Skip to content

synaptome.results

synaptome.results

Results: answers to questions, as plain values that carry their question, settings and data fingerprint (DESIGN.md section 9). Never stored in the study; saved on their own as .synr files if wanted.

Result

An answer to a question: a value, never stored in the study.

Results are made by questions (q.estimate(...), q.test(...)), not directly.

Attributes:

Name Type Description
question Question

The question answered. A result loaded without its study only has question_spec.

question_spec dict

The question as recorded (Question.to_dict).

method dict

The method and every setting used (seed included).

table DataFrame

One row per group / pair (and coordinate). A copy.

data_key str

The question's data fingerprint when the result was computed.

computed_at datetime
versions dict

Software versions.

elapsed float

Compute time, in seconds.

timing dict | None

Whether the question was registered in the protocol before its data arrived ("before data", "after data", "not pre-specified", "unknown"), with the times compared; see results.timing.timing. None for results saved before it was recorded.

question property

The question answered, rebuilt on its study (refused for a result loaded without one).

question_spec property

The question as recorded (Question.to_dict).

title property

The question's title.

method property

The method and every setting used, seed and correction included (a copy).

table property

The answer, one row per group, pair or cluster (a copy).

data_key property

The fingerprint of the data the question read when the result was computed.

computed_at property

When the result was computed (UTC).

versions property

Versions of synaptome and of the libraries that computed it.

elapsed property

Compute time, in seconds.

timing property

Whether the question was registered before its data (see results.timing), or None.

plot(**kwargs)

The usual figure of this result, drawn on its question's study: a comparison for a test, curves with clusters for a cluster test, a forest or points for an estimate, densities for a normality test, the groups for an omnibus test. Keywords go to that view (study.plot.comparison, ...). A result whose data changed since it was computed is refused.

Returns:

Type Description
Plot

to_frame(pretty=False, digits=2, vs=False)

The table, as data (pretty=False, a copy of table) or ready to show (pretty=True): numbers rounded to digits, p values in APA style (.032, < .001), each estimate with its interval in one cell (0.42 [0.12, 0.71]), and the counts per row.

Parameters:

Name Type Description Default
pretty bool

Format for reading (default False: the raw table).

False
digits int

Decimals of statistics and estimates (default 2). p values always have 3.

2
vs bool

Pair results only: one row per competitor of the question's reference, oriented so that positive means the reference is better (see vs()).

False

Returns:

Type Description
DataFrame

Pretty: every cell a string.

to_markdown(digits=2, vs=False)

The formatted table (to_frame(pretty=True)) as a Markdown table, followed by a note on the method (test, alternative, correction...), e.g. for a Quarto or Jupyter document.

Parameters:

Name Type Description Default
digits int

Decimals of statistics and estimates (default 2).

2
vs bool

Oriented on the question's reference (see to_frame).

False

Returns:

Type Description
str

to_dict()

Everything but the tables, as JSON-safe data.

save(path, overwrite=False)

Saves the result on its own, as one .synr file (an uncompressed zip of manifest.json, result.json, table.parquet and one <name>.parquet per further table, e.g. the bootstrap test's draws). Reload with synaptome.load_result.

Parameters:

Name Type Description Default
path str | Path

Must end with .synr.

required
overwrite bool

Replace an existing result file (default False). Other files are never replaced.

False

Returns:

Type Description
Path

ClusterResult

Bases: TestResult

The answer of compare_along(...).test("cluster_permutation"): one row per cluster of each pair (a, b: curves of a - b), with the coordinates it spans (start, stop, both included, n_coordinates), its mass (sum of t, signed: positive where a is higher), p, p_corrected, significant and the counts. A pair without any cluster has no row: verdict() lists every pair.

Extra tables: curve() (t at each coordinate), null() (largest cluster mass of each permutation), and the pairs tested (verdict()).

family property

The correction family: "cluster" or "pair".

correct(method='holm', alpha=None, family='cluster')

Corrects the cluster p values for testing several pairs, giving a new result.

Technical details

The permutation test already controls the family-wise error along the axis within a pair. Two families for the pairs: "cluster" (default) pools every cluster of every pair; "pair" corrects one p per pair (its smallest cluster p, 1 without a cluster) across every pair tested, and each cluster's corrected p is the larger of its pair's corrected p and its own.

Parameters:

Name Type Description Default
method str

"holm" (default), "bonferroni", "fdr_bh", "fdr_by" or "none".

'holm'
alpha float | None

Default: this result's.

None
family str

"cluster" (default) or "pair".

'cluster'

Returns:

Type Description
ClusterResult

verdict()

One row per pair tested: a, b, n_clusters, p_min (smallest cluster p, 1 without a cluster), p_corrected (smallest corrected p of its clusters; with family="pair" and no cluster, 1), significant (any significant cluster) and where (the significant clusters' spans).

curve(a=None, b=None)

The t statistic at each coordinate, for the pair a - b (default: every pair).

null(a=None, b=None)

The largest cluster mass of each permutation (0 without a cluster), per pair.

vs(reference=None)

The clusters of the pairs with reference, oriented so that a positive mass means the reference is better (using the question's higher_is_better); alternative turns with it.

Returns:

Type Description
DataFrame

Columns reference, competitor, alternative, then the cluster columns.

DescribeResult

Bases: Result

The answer of q.describe(): one row per group (by; one row without groups) and per along coordinate. Columns depend on the scale of the analysed values: interval or ratio: n, missing, mean, sd, median, q1, q3, min, max; ordinal: no mean / sd (their distances mean nothing); binary: n, missing, proportion (of True). n counts observed values, missing the NaN ones; sd uses ddof=1; quartiles are linear interpolations.

EstimateResult

Bases: Result

The answer of q.estimate(...): one row per group (by, estimate, ci_low, ci_high, n) or per pair (a, b: the estimate is of a - b), and per along coordinate. Bootstrap intervals add the diagnostics bias, se, bias_se_ratio, z0; an ordered unit adds n_eff.

estimator property

The estimator's name (e.g. "hodges_lehmann").

vs(reference=None)

One row per competitor of reference, oriented so that a positive value (above 0.5 for CLES, above 1 for an odds ratio) means the reference is better, using the question's higher_is_better.

Parameters:

Name Type Description Default
reference Any

A level of the question's factor; default: the question's reference.

None

Returns:

Type Description
DataFrame

Columns reference, competitor, [along], estimate, ci_low, ci_high and the counts. Bootstrap diagnostics are left out (they don't transform like the estimate).

NormalityResult

Bases: RowsResult

The answer of q.test("shapiro" | "normaltest"): one row per group (by; a single row without groups) or, for a paired comparison, per pair (a, b: the differences a - b, what a paired t-test assumes normal), with statistic, p, p_corrected, significant and n. The null hypothesis is normality: a small p is evidence against it. Not corrected by default (a diagnostic, not a claim).

OmnibusResult

Bases: RowsResult

The answer of q.test("friedman" | "rm_anova" | "kruskal" | "anova"): one row with statistic, df (or df1, df2 for an F test), p, p_corrected, significant, n (paired: units observed in every group; independent: values), k (groups) and the effect sizes. Pairwise follow-ups are separate calls (q.test("wilcoxon")).

PairwiseResult

Bases: RowsResult

The answer of q.test(...): one row per pair (a, b: the test is of a - b against offset), with statistic (and df, n_eff where they apply), p, p_corrected, significant, the counts (n paired, n_a / n_b independent), and per effect size its estimate (column named after it) and interval (<name>_ci_low, <name>_ci_high). The bootstrap test adds its estimator, its interval and the bias diagnostics.

vs(reference=None)

One row per competitor of reference, oriented so that a positive effect (above 0.5 for CLES, above 1 for an odds ratio) means the reference is better, using the question's higher_is_better. The hypothesis is reoriented to match: alternative (greater <-> less) and offset are flipped with the effect, so p values are unchanged.

Parameters:

Name Type Description Default
reference Any

A level of the question's factor; default: the question's reference.

None

Returns:

Type Description
DataFrame

Columns reference, competitor, alternative, offset, the p values, the counts and the effect sizes. The test statistic and the bootstrap diagnostics are left out (they don't transform like the effect).

differences(a=None, b=None)

Paired tests: the per-unit differences behind the test of the pair a - b (default: the only pair), read from the question's data.

Returns:

Type Description
DataFrame

The unit columns, a, b (values) and difference (a - b, before any offset).

draws(a=None, b=None)

Bootstrap test: the draws of its estimator behind the p value and the interval, for the pair a - b (default: every pair).

Returns:

Type Description
DataFrame

Columns a, b, draw, value.

load_result(path, study=None)

Loads a result saved with Result.save.

Parameters:

Name Type Description Default
path str | Path
required
study Study | None

Rebuilds the result's question on this study (result.question). Without it, only result.question_spec is available. Loading doesn't check the data: use study.verify(result).

None

Returns:

Type Description
Result

Of the kind saved (e.g. EstimateResult).