Skip to content

Compare before and after

Question

How did the same subjects change between two visits?

See every package-generated example · Read the complete analysis pipeline

When to use

Use this when the same subjects have measurements before and after an intervention.

Example figure

Compare before and after output generated by Circadian Workbench

This deterministic example is calculated by the paired_measures action and drawn by render_paired_measures_workbench_svg, the same renderer used for publication export. Empty or withheld elements are therefore visible exactly as they are in a real result.

import circadian_workbench as cw

cw.call("paired_measures", epochs=visits)

Required inputs and controls

The public function is the registered action below. settings= is accepted as a friendlier alias for config= by cw.call; the calculation stores the complete normalized config in provenance.

Function reference

cw.call("paired_measures", epochs, config=None, circular_measures=None)

Arguments and parameters

Name Type Required Default Units Meaning
epochs object yes — - The epochs of one study, each a list of subject entries: {"baseline": [{"subject_id": "m01", "measures": {"period_hours": 23.8}}, ...], "treatment": [...]}. Pairing is by subject_id, so a subject missing from any epoch is dropped and named. paired_measures takes exactly two and longitudinal_measures three or more; each refuses the other's shape by name.
config object no null - Partial scientific settings. Omitted or None values use the shared installed defaults; invalid fresh values are rejected. Run describe_config for names, meanings, units, bounds and choices. Explicitly load old saved mappings with load_saved_settings to report compatibility conversions.
circular_measures array no null - Which measure names are clock times rather than plain numbers, e.g. ["acrophase_hours"]. Those are differenced round the circle -- 23.5 h to 00.5 h is +1 h, not -23 h -- and tested with a Rayleigh test. Nothing is inferred from a name.

Every nested config key, default, allowed value, and purpose is listed in the complete configuration reference.

How it works

Subjects are matched by identifier before within-subject differences and tests are calculated.

$$ d_i=y_{i,\mathrm{after}}-y_{i,\mathrm{before}} $$

Implementation: repeated.py::paired_measures.

Outputs and interpretation

The result reports paired means, differences, intervals, tests and dropped subjects.

cw.call returns a Result: use .data for calculated values, .warnings for scientific qualifications, .provenance for version and input identity, .script for an equivalent replay script, and .files for saved outputs.

Limitations

Unmatched subjects are dropped; circular measures must be declared before comparison.

Example

The figure above is a real package result from a seeded, redistributable synthetic dataset. The flat gallery bundle retains figure_data_paired-measures.csv, a standalone plot_paired-measures.py, source hashes, an editable SVG, and a rendered preview.

Methods text

Before and after values were paired by subject identifier and tested within subjects.

See also

Track repeated visits · Analysis index · Gallery