synaptome.questions¶
synaptome.questions
¶
Questions: what is compared on which data. A question resolves its design and analysis table from the study; tests, estimates and plots all read from it (DESIGN.md section 5).
Create questions from a study: study.compare(...), study.compare_along(...),
study.distribution(...); rebuild a recorded one with study.question(spec).
Question
¶
A question asked of a study. Create one with study.compare, study.compare_along or
study.distribution, not directly.
A question is read-only. Its design, data and data_key are resolved from the study on first
access and then kept: if the study changes afterwards, ask the question again
(study.question(q.to_dict())).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study
|
Study
|
|
required |
outcome
|
str
|
The variable compared. |
required |
subset
|
Mapping[str, Any] | None
|
Filters applied first. Keys: a dimension of the outcome (coordinates), a level at or above the
outcome's (unit ids), or a scalar variable at or above it (units whose value is among these). Values:
one value, a list, or |
None
|
reduce
|
Mapping[str, Any] | None
|
Reductions of dimensions and levels the question doesn't use, e.g. |
None
|
unit
|
str | None
|
The unit of independence: a level (default: the outcome's level, or the level its reductions lead to), or an ordered dimension of the outcome to pair on its coordinates within one unit. |
None
|
title
|
str | None
|
Short label; default built from the roles. |
None
|
description
|
str
|
The interpretation, in words. |
''
|
status
|
str
|
|
'exploratory'
|
specified_at
|
datetime | str | None
|
When the question was asked (default: now, UTC). |
None
|
design
property
¶
What is compared: paired or independent, groups, pairs, unit, n (see Design).
data
property
¶
The analysis table: unit id columns, the factor by, the along coordinate (if any) and the
outcome; one row per observed value, after subset and reduce. A copy: changing it changes
nothing.
data_key
property
¶
Fingerprint of data and of the definitions it was read from (see fingerprint.data_key).
pair_data(a, b)
¶
The complete cases of the pair a - b. Paired designs: one row per unit with both values, in
columns a and b (with along: one row per unit and coordinate, keeping units observed in both
groups at every coordinate). Independent designs: the rows of the two groups, in long form (with
along, of the units observed at every coordinate).
estimate(name, ci='analytic', confidence=0.95, n_boot=2000, seed=0, interval='bca', replicates=None, assume_independent=False)
¶
How large? Computes estimator name (see synaptome.estimates.ESTIMATORS) per group or per pair,
with a confidence interval. Refuses an estimator the design doesn't suit, naming those that do.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Per group: |
required |
ci
|
str | None
|
|
'analytic'
|
confidence
|
float
|
Coverage of the interval (default 0.95). |
0.95
|
n_boot
|
int
|
Bootstrap resamples (default 2000). |
2000
|
seed
|
int | None
|
Bootstrap seed (default 0, so the same call gives the same interval); recorded in the result. |
0
|
interval
|
str
|
Bootstrap interval: |
'bca'
|
replicates
|
str | bool | None
|
Upstream bootstrap draws to read instead of resampling: default, the outcome's replicate variable if it has exactly one; a name picks one; False resamples. |
None
|
assume_independent
|
bool
|
Only with an ordered unit ( |
False
|
Returns:
| Type | Description |
|---|---|
EstimateResult
|
|
test(name, alternative='two-sided', offset=None, effect_sizes=None, correction=None, alpha=0.05, assume_independent=False, **params)
¶
Is there a difference? Runs test name (see synaptome.hypotheses.TESTS) with effect sizes and
corrected p values. Refuses a test the design doesn't suit, naming those that do.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Two groups, once per pair of the question on its own complete cases: paired |
required |
alternative
|
str
|
|
'two-sided'
|
offset
|
float | None
|
The difference tested against (default 0; for |
None
|
effect_sizes
|
str | tuple[str, ...] | list[str] | None
|
Pair (or, for omnibus tests, omnibus) estimators to report, each with its analytic interval when
it has one (coverage |
None
|
correction
|
str | None
|
Across the result's rows: |
None
|
alpha
|
float
|
Threshold of |
0.05
|
assume_independent
|
bool
|
Only with an ordered unit ( |
False
|
**params
|
Any
|
Test parameters: |
{}
|
Returns:
| Type | Description |
|---|---|
PairwiseResult | OmnibusResult | ClusterResult | NormalityResult
|
|
describe()
¶
Summary statistics of the outcome, per group (and per along coordinate), from q.data: n,
missing, mean, sd, median, q1, q3, min, max for interval or ratio values; no mean
or SD for ordinal ones; proportion for binary ones.
Returns:
| Type | Description |
|---|---|
DescribeResult
|
|
to_dict()
¶
The question as JSON-safe data (no values), to record it. Rebuild with study.question(spec).
from_dict(spec, study)
classmethod
¶
Rebuilds a question from to_dict output on study.
Compare
¶
Bases: Question
An outcome compared across the levels of a factor: study.compare(outcome, by=...).
Whether the comparison is paired or independent is read from where by lives: a dimension of the
outcome, or a variable at a level crossed with the unit, varies within each unit (paired); a variable
at the unit's level is constant within it (independent).
Its roles, besides those of every Question (outcome, subset, reduce, unit, title, ...):
by(str): the factor, a dimension of the outcome or a categorical variable.reference(optional): a level ofbythat every other level is compared with; pairs are then(reference, other).pairs(list of(a, b), optional): the pairs to compare, each asa - b. Default: every pair. Givereferenceorpairs, not both.higher_is_better(bool, optional): orients answers (results say "positive = reference better"). Default True.
CompareAlong
¶
Bases: Compare
Curves compared across the levels of a factor along an ordered dimension kept unreduced:
study.compare_along(outcome, by=..., along=...). Answered by cluster permutation and by estimates per
coordinate.
Its roles are those of Compare (by, reference, pairs, higher_is_better) and:
along(str): an ordered dimension of the outcome (ordinal, interval or ratio scale), kept unreduced.
Design
dataclass
¶
What a question compares, once resolved on a study. Built by the question (q.design); read-only.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
|
outcome |
str
|
The variable compared. |
by |
str | None
|
The factor compared across (None for a distribution without groups). |
factor_role |
str | None
|
Where |
by_level |
str | None
|
The level of |
paired |
bool | None
|
True when |
groups |
tuple
|
The levels of |
reference |
Any
|
The reference group, if any. |
pairs |
tuple[tuple[Any, Any], ...]
|
The pairs compared; |
higher_is_better |
bool | None
|
|
unit |
str
|
The unit of independence: a level, or a dimension of the outcome ( |
unit_is_dimension |
bool
|
|
ordered_unit |
bool
|
True when the observations are positions along an ordered dimension (serially correlated). |
n_units |
int
|
Units with at least one observed value. |
n_per_group |
dict
|
Units with an observed value, per group. |
n_per_pair |
dict
|
Units in the pair's complete cases: paired, units with both values; independent, units in either
group. With |
along |
str | None
|
The ordered dimension kept unreduced ( |
along_coordinates |
tuple
|
|
scale |
str
|
The scale of the analysed values: the outcome's, or the one its reductions give (a count or a
proportion of booleans is ratio, a slope interval). |
scale_assumed |
bool
|
|
binary |
bool
|
True when the analysed values are binary: a bool outcome (not reduced to proportions), or a category with two categories. |
replicates |
tuple[str, ...]
|
Replicate variables of the outcome (upstream bootstrap or jackknife draws). |
Distribution
¶
Bases: Question
How an outcome is distributed, overall or per level of a factor: study.distribution(outcome, by=None).
Answered by descriptive statistics and normality tests.
Its role, besides those of every Question:
by(str, optional): a factor (a dimension of the outcome or a categorical variable) to describe each level separately.
question_from_dict(spec, study)
¶
Rebuilds a question of any kind from Question.to_dict output, on study.
data_key(table, definitions)
¶
A hash of an analysis table and of the definitions it was read from.
The table is sorted on all its columns first, so row order never matters. Definitions contribute
only their meaning-bearing fields (definition_fingerprint): editing a description leaves the key
unchanged; changing a range, a scale or a category does not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
DataFrame
|
|
required |
definitions
|
Iterable[Variable]
|
|
required |
Returns:
| Type | Description |
|---|---|
str
|
|