Skip to content

synaptome.datasets

synaptome.datasets

Toy studies with planted effects, one generator per study type (DESIGN.md section 13).

Each function returns a new, seeded Study; its planted effects (real and null) are listed in its docstring and in study.info.extra["planted"].

>>> import synaptome as syn
>>> study = syn.datasets.crossover(n_subjects=24, seed=1)
>>> study.info.extra["planted"][0]["value"]
5.0

case_control(n_per_group=30, effect=10.0, seed=0)

Case-control study: patients and controls, one score each. compare("score", by="group") is an independent-samples comparison.

Units: subject (2 * n_per_group). Variables at subject: group (control / patient), age (years), sex (F / M), score (points, SD 10 within each group).

Planted:

  • score, patient - control: mean difference effect (default 10 points, Cohen's d = 1);
  • age, patient - control: 0 (null).

Parameters:

Name Type Description Default
n_per_group int

Subjects per group (at least 2).

30
effect float

Patients' mean score minus controls'.

10.0
seed int
0

Returns:

Type Description
Study

crossed(n_subjects=20, n_stimuli=16, n_repeats=2, effect=30.0, seed=0)

Crossed subjects x stimuli: every subject sees every stimulus n_repeats times; half the stimuli are incongruent. A trial belongs to one subject and one stimulus (trial < subject * stimulus), and the condition lives on the stimulus. compare("rt", by="condition", reduce={"trial": "mean"}, unit="subject") is paired across subjects.

Units: subject, stimulus, trial < subject * stimulus. Variables: condition (congruent / incongruent) at stimulus; rt (ms) and correct (bool) at trial. Response times: 500 ms, SD 50 across subjects, SD 20 across stimuli, SD 80 across trials. Stimuli are a sample too: with 16 of them, the observed effect varies around effect with the stimuli drawn (SD about 10 ms), a variance that a by-subject comparison does not see.

Planted (trials averaged per subject and condition):

  • rt, incongruent - congruent: mean difference effect (default 30 ms);
  • correct, incongruent - congruent: 0 (null; 95% correct in both).

Parameters:

Name Type Description Default
n_subjects int

At least 2.

20
n_stimuli int

Even, at least 2 (half per condition).

16
n_repeats int

Presentations of each stimulus to each subject (at least 1).

2
effect float

Slowing on incongruent stimuli (ms).

30.0
seed int
0

Returns:

Type Description
Study

crossover(n_subjects=24, effect=5.0, seed=0)

Crossover trial: every subject is measured under placebo and drug. condition is a dimension, so compare("score", by="condition") is paired. Subjects differ much more from each other (SD 15) than their two measurements do (SD 3 each), so pairing matters: an independent comparison would miss the effect.

Units: subject. Variables: sequence (AB / BA, balanced) at subject; score (points) and heart_rate (bpm), both with dimension condition (placebo, drug).

Planted:

  • score, drug - placebo: mean difference effect (default 5 points; d_z about 1.2);
  • heart_rate, drug - placebo: 0 (null).

Parameters:

Name Type Description Default
n_subjects int

At least 2.

24
effect float
5.0
seed int
0

Returns:

Type Description
Study

longitudinal(n_per_group=15, n_visits=7, slope=-1.0, onset=4.0, missing=0.1, seed=0)

Longitudinal study, two groups: body weight at visits every 2 weeks. Treated subjects start losing weight after week onset; controls stay stable. Some visits are missing, so subjects have different weeks (ragged). Curves: compare_along("weight", by="group", along="week"); slopes: compare("weight", by="group", reduce={"week": "slope"}). Both are independent comparisons.

Units: subject. Variables: group (control / treated) at subject; weight (kg) with dimension week (0, 2, ..., 2 * (n_visits - 1)). Baseline weight SD 5 kg, visit noise SD 1 kg.

Planted:

  • weight, treated - control, along week: slope * max(week - onset, 0) (default: 0 until week 4, then -2 kg per visit);
  • weight reduced to its slope over weeks, treated - control: the least-squares slope of that curve over the full visit schedule (default -0.857 kg/week);
  • weight at week 0, treated - control: 0 (null).

Parameters:

Name Type Description Default
n_per_group int

At least 2.

15
n_visits int

Visits per subject, every 2 weeks from week 0 (at least 2).

7
slope float

Weekly weight change of the treated group after onset (kg/week).

-1.0
onset float

Week the treatment effect starts.

4.0
missing float

Probability that a visit after week 0 is missing.

0.1
seed int
0

Returns:

Type Description
Study

method_comparison(n_subjects=16, n_sources=200, n_missing=5, n_depth_bins=5, effect=0.05, seed=0)

Method comparison against a reference, per source: three methods (proposed, alternative, baseline) are scored by their error at every source of every subject, for three sensor types. Every factor is a dimension, so every comparison is paired; sources differ in number and identity between subjects (ragged); alternative failed in n_missing subjects and has no values there. Lower error is better. Shaped like the mindmap-bem manuscript (TODO.md).

compare("error", by="method", reference="proposed", subset={"sensors": "eeg"}, reduce={"source": "median"}, higher_is_better=False) compares per-subject median errors, each pair on its complete cases.

Units: subject. Variables at subject:

  • error (dims method, sensors, source): error per source, positive, rising with depth;
  • bias (same dims): a signed per-source error, centred on 0 for every method;
  • depth (dim source, mm): each source's distance to the inner skull;
  • error_depth (dims method, sensors, depth_bin): median error per depth bin (bin centres in mm), as a pipeline would store it;
  • accepted (dim method, bool): False where alternative failed.

Planted (on per-subject medians over sources; the differences hold in every depth bin too):

  • error, proposed - baseline: -effect for eeg and mag (default -0.05), 0 for grad (null);
  • error, alternative - proposed: 2 * effect, on n_subjects - n_missing subjects;
  • bias, proposed - baseline: 0 for every sensor type (null).

Parameters:

Name Type Description Default
n_subjects int

At least 3.

16
n_sources int

Typical sources per subject (each subject has ±10%, drawn from its own set of ids); at least 10.

200
n_missing int

Subjects where alternative failed (0 to n_subjects - 2).

5
n_depth_bins int

Bins of error_depth (at least 1).

5
effect float

How much lower proposed's error is than baseline's, for EEG and magnetometers.

0.05
seed int
0

Returns:

Type Description
Study

repeated_trials(n_per_group=12, n_trials=30, effect=3.0, seed=0)

Repeated trials (an ERP study): two groups, many trials per subject, a voltage curve per trial. Trials are repetitions (a unit level) to average: compare_along("erp", by="group", along="time", reduce={"trial": "mean"}) compares the evoked responses of independent groups.

Units: subject > trial. Variables: group (control / patient) at subject; erp (µV) at trial with dimension time (ms, -100 to 500 every 10 ms). Every subject shows a component peaking at 300 ms (amplitude 5 µV, SD 1 µV across subjects); single trials add white noise (SD 5 µV).

Planted:

  • erp, patient - control, along time: effect * exp(-(time - 300)² / (2 * 50²)) µV (default peak 3 µV; above half of it between 241 and 359 ms);
  • erp averaged over the pre-stimulus window (time < 0), patient - control: 0 (null).

Parameters:

Name Type Description Default
n_per_group int

Subjects per group (at least 2).

12
n_trials int

Trials per subject (at least 1).

30
effect float

Extra component amplitude of patients (µV).

3.0
seed int
0

Returns:

Type Description
Study

simulation_benchmark(n_regions=12, n_runs=5, snrs=(0, 5, 10, 20), n_boot=100, effect=0.03, seed=0)

Simulation benchmark: three methods (wcset, a, b) recover sources in several brain regions, with repeated simulation runs per region, at several noise levels. Runs are repetitions (a unit level), so compare("accuracy", by="method", reduce={"run": "mean"}, subset={"snr": 10}) is paired across regions. Each run's accuracy also comes with upstream bootstrap draws (accuracy_boot).

Units: region > run. Variables at run: accuracy (proportion correct) with dimensions method and snr (dB); accuracy_boot, its bootstrap draws (replicates_of="accuracy", extra dimension draw of kind "replicate"), as if each run's 200 test items were resampled.

Planted (after averaging runs, at every SNR):

  • accuracy, wcset - a: mean difference effect (default 0.03);
  • accuracy, wcset - b: 0 (null).

Parameters:

Name Type Description Default
n_regions int

At least 2.

12
n_runs int

Runs per region (at least 1).

5
snrs Sequence[float]

Signal-to-noise ratios (dB), at least one. Accuracy rises with SNR, from 0.5 to 0.8 for a.

(0, 5, 10, 20)
n_boot int

Bootstrap draws per run, method and SNR (at least 2).

100
effect float

How much more accurate wcset is than a.

0.03
seed int
0

Returns:

Type Description
Study

timepoint_pairing(n_subjects=3, n_times=500, effect=0.05, rho=0.9, seed=0)

Timepoint pairing within one recording: two methods track a signal over time, scored by their correlation with the truth at every time sample. Within one subject, the time samples are the paired observations (compare("correlation", by="method", subset={"subject": "s01"}, unit="time")). The noise is autocorrelated (AR(1), coefficient rho), so consecutive samples are not independent and the effective sample size is far below n_times.

Units: subject. Variable: correlation with dimensions method (standard, improved, matched) and time (s, sampled at 100 Hz).

Planted, in every subject:

  • correlation, improved - standard, paired on time: mean difference effect (default 0.05);
  • correlation, matched - standard, paired on time: 0 (null);
  • serial correlation rho of each method's noise (noted in the entries);
  • correlation, improved - standard, over subjects after averaging time: effect (few subjects).

Parameters:

Name Type Description Default
n_subjects int

At least 1.

3
n_times int

Time samples (at least 10).

500
effect float
0.05
rho float

AR(1) coefficient of the noise, in [0, 0.99].

0.9
seed int
0

Returns:

Type Description
Study