Plan sample size¶
Question¶
How many independent units are needed for the chosen effect?
See every package-generated example · Read the complete analysis pipeline
When to use¶
Use this before data collection to estimate power at a chosen independent-unit count or the count needed for a scientifically meaningful effect.
Example figure¶
This deterministic example is calculated by the sample_size action and drawn by render_sample_size_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("sample_size", question="phase_difference", difference=2, resultant_length=0.85)
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("sample_size", question='phase_difference', difference, resultant_length=None, n_per_group=None, target_power=None, config=None)
Arguments and parameters¶
| Name | Type | Required | Default | Units | Meaning |
|---|---|---|---|---|---|
question |
string | no | "phase_difference" |
- | Which power question to answer: 'phase_difference' for two groups of phases compared on the circle, or 'mesor', 'amplitude' or 'rhythm_phase' for a cosinor parameter compared between two cohorts. 'observed' asks for post-hoc observed power and is refused with the reason, because it is a restatement of the p-value you already have. |
difference |
float | yes | — | hours or recording units | The smallest difference worth detecting, in the parameter's own units: hours for a phase, recording units for a mesor or an amplitude. Not the difference you observed -- the one that would change your mind. |
resultant_length |
float | no | null |
- | Within-group phase concentration for the phase-difference question; omitted uses the shared resultant-length default. |
n_per_group |
integer | no | null |
units per group | Give it to ask 'what power do I have at this n'. Leave it out to ask 'how many do I need', which searches over n instead. |
target_power |
float | no | null |
- | Prospective target power; omitted follows config.power_target. Ignored when a fixed sample size is evaluated. |
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. |
Every nested config key, default, allowed value, and purpose is listed in the complete configuration reference.
How it works¶
The package simulates the same circular-phase or differential-cosinor test used in analysis. Power is the rejection fraction and Wilson intervals carry Monte Carlo uncertainty; sample-size search uses the interval rather than the point estimate.
$$ \widehat{\mathrm{power}}=\frac{\text{rejected simulations}}{S} $$
Implementation: power.py::phase_difference_power / rhythm_parameter_power.
Outputs and interpretation¶
The result returns the question, assumptions, candidate sample sizes, power estimates and Wilson intervals, target, recommended size or achieved power, simulations, runtime, and warnings.
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¶
The answer is conditional on the supplied meaningful effect and dispersion. Post-hoc observed power is refused because it only restates the observed p value.
Example¶
The figure above is a real package result from a seeded, redistributable synthetic dataset. Its editable SVG embeds the exact plotted data and provenance and is included with a rendered preview in the installed help. The separate authoring bundle retains figure_data_sample-size.csv, a standalone plot_sample-size.py and source hashes; these companion files are not installed application files.
Methods text¶
Prospective power was estimated by simulating the package's target inferential test under the declared minimum meaningful effect; Wilson intervals described simulation uncertainty and determined the recommended sample size.
See also¶
Predict the entrainment range · Predict re-entrainment · Fit the two-process sleep model · Analysis index · Gallery