experimentation-toolkit
experimentation-toolkit is a typed Python library for classical frequentist analysis of
independent, two-arm controlled experiments. It connects assignment diagnostics, metric-level
inference, multiplicity correction, power planning, and a serializable report without making a
DataFrame the core abstraction.
The package reports estimates, uncertainty, and statistical evidence. It deliberately does not turn a small p-value into a claim that an effect is important, beneficial, or worth shipping.
Quick example
from experimentation_toolkit import (
Experiment,
ExperimentReport,
analyze_proportion,
check_sample_ratio_mismatch,
)
experiment = Experiment(control="control", treatment="treatment")
srm = check_sample_ratio_mismatch(
observed_counts={"control": 10_000, "treatment": 10_050},
expected_proportions={"control": 0.5, "treatment": 0.5},
)
conversion = analyze_proportion(
control_successes=1_200,
control_total=10_000,
treatment_successes=1_280,
treatment_total=10_050,
confidence_level=0.95,
alternative="two-sided",
metric_name="conversion",
)
report = ExperimentReport(
experiment=experiment,
analyses=(conversion,),
diagnostics=(srm,),
)
print(report.model_dump_json(indent=2))
The absolute effect is a risk difference. A move from 10% to 11% is 0.01, or one
percentage point. Its relative lift is 0.10, or 10% relative. Results expose these as
separate fields with an explicit relative-effect definition.
Supported analyses
- Independent binary outcomes from success counts and totals
- Independent continuous outcomes from numeric array-like samples
- Two-sided, treatment-greater, and treatment-less alternatives
- Sample-ratio-mismatch checks for two or more assignment groups
- Proportion sample-size planning and achieved-power approximation
- Bonferroni, Holm, and Benjamini-Hochberg p-value adjustment
- One-sided group-sequential monitoring with Lan-DeMets alpha spending
- Immutable Pydantic models and standards-compliant JSON reports
Statistical methods
Proportion inference uses a pooled two-sample score z-test for the point null
p_treatment - p_control = 0. The risk-difference confidence interval is Newcombe's hybrid
score interval formed from Wilson limits without continuity correction. It remains useful at
zero and one, while an explicit warning flags sparse expected cells where the test's normal
approximation may be inaccurate.
Continuous inference uses Welch's unequal-variance two-sample t-test and the
Welch-Satterthwaite degrees of freedom. It does not assume equal group variances. Both analyses
define effects as treatment minus control and align one-sided confidence bounds with the chosen
alternative. An unbounded endpoint is serialized as null, never infinity.
See docs/statistical-methods.md for formulas, assumptions, and references.
Assumptions
Inference assumes randomized or otherwise exchangeable groups, independent experimental units, a metric definition fixed independently of observed treatment results, and no interference between units. Binary observations must be Bernoulli outcomes at the analysis unit. Welch inference assumes finite variance and is exact under normal sampling; with larger samples it uses the sampling distribution of the mean. The library cannot establish that these assumptions hold from arrays or counts alone.
Sample ratio mismatch
check_sample_ratio_mismatch applies Pearson's chi-square goodness-of-fit test to observed arm
counts and configured allocation probabilities. FAIL means the allocation is statistically
inconsistent with the plan at the selected threshold. It indicates a potential randomization,
eligibility, logging, or instrumentation problem; it does not identify the cause. Inspect SRM
before interpreting treatment effects.
Power and sample size
from experimentation_toolkit import proportion_sample_size
plan = proportion_sample_size(
baseline_rate=0.10,
minimum_detectable_effect=0.01,
mde_type="absolute", # +1 percentage point
alpha=0.05,
power=0.80,
allocation_ratio=1.0, # treatment / control
)
Set mde_type="relative" to express the MDE as a fraction of baseline: 0.10 at a 10%
baseline targets an 11% treatment rate. The calculation is a fixed-horizon normal approximation,
and the returned achieved power reflects the integer group sizes. Planning inputs are assumptions,
not estimates guaranteed to hold after launch.
Multiple testing
adjust_p_values preserves original hypothesis order and optionally carries labels. Bonferroni
and Holm control the family-wise error rate. Benjamini-Hochberg controls the false discovery rate
under independence or positive dependence and must not be interpreted as FWER control. The caller
defines the hypothesis family before looking at results.
Sequential testing
from experimentation_toolkit import analyze_sequential_continuous
monitoring = analyze_sequential_continuous(
control=control_hours, # 72 observations before the change
treatment=treatment_hours, # ordered observations after it, one per hour so far
control_looks=[72] * (len(treatment_hours) - 1),
treatment_looks=list(range(2, len(treatment_hours) + 1)),
maximum_control_size=72,
maximum_treatment_size=72,
alpha=0.05,
alternative="less", # monitor for harm
spending="obrien-fleming",
)
monitoring.crossed, monitoring.crossed_at_look
group_sequential_boundaries returns exact one-sided z boundaries for any strictly increasing
information fractions, and alpha_spent evaluates the O'Brien-Fleming-type or Pocock-type
Lan-DeMets spending functions. Every look may be analyzed without inflating the one-sided error
rate beyond alpha, provided the maximum sizes and spending function are fixed before monitoring
starts. analyze_sequential_continuous maps each look's Welch statistic to z by tail probability,
stops at the first crossing, and reports the looks it analyzed. Monitoring is one-sided; a
crossing is evidence of an effect in the monitored direction, not an estimate of its size.
Interpretation
Statistical significance quantifies incompatibility with a null model under its assumptions. Practical significance requires domain context, costs, guardrails, and a pre-specified decision rule. Read the absolute effect and its confidence interval first. Relative effects are omitted when the control denominator is zero or when continuous means do not support a conservative, non-negative and numerically resolved ratio-scale interpretation.
Installation
Python 3.12 is required.
python -m pip install experimentation-toolkit
For a source checkout:
python -m pip install -e '.[dev]'
To execute the visual notebook, install the separate example dependencies:
python -m pip install -e '.[dev,examples]'
Testing and development
ruff check .
ruff format --check .
mypy
pytest
pytest --cov=experimentation_toolkit --cov-report=term-missing
The deterministic game onboarding notebook demonstrates assignment counts, SRM, a primary completion metric, retention and session-duration metrics, Holm correction, Plotly-generated uncertainty plots rendered as GitHub-compatible PNGs, and report serialization. It is self-contained, uses a fixed seed, and labels all generated observations as synthetic.
Limitations
Version 0.2 supports independent, two-arm analyses, fixed-horizon or monitored one-sided with alpha spending. It does not implement paired or clustered designs, exact unconditional proportion tests, covariate adjustment, CUPED, two-sided or futility boundaries, bias-adjusted estimates after early stopping, Bayesian analysis, causal identification, heterogeneous effects, feature flags, or platform infrastructure. The proportion test and power methods use large-sample approximations; warnings do not convert them into exact procedures.
Roadmap
Statistically useful next steps include stratified analyses with explicit estimands, cluster-aware standard errors and design effects, robust or transformed continuous outcomes, exact methods for sparse binary data, and simulation-based validation of planning assumptions. Each belongs behind a distinct API that states its sampling unit and assumptions.
License
MIT
Metadata
Release files for experimentation-toolkit 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| experimentation_toolkit-0.2.0.tar.gz | 24.9 kB | With provenance | Details for experimentation_toolkit-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| experimentation_toolkit-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for experimentation_toolkit-0.2.0-py3-none-any.whl |
Total release size: 55.8 kB
Release files / experimentation_toolkit-0.2.0.tar.gz
| Download URL | experimentation_toolkit-0.2.0.tar.gz |
|---|---|
| Size | 24.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63af25acc041d24613f988a2cb70feca397e21294a3e0f00a3ee21f786d1ab13
|
|
BLAKE2b-256 checksum How to use checksums |
c0d410afb0d349468b76230384e94c06f80712ab0bd8f22e52490184be077c51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logRelease files / experimentation_toolkit-0.2.0-py3-none-any.whl
| Download URL | experimentation_toolkit-0.2.0-py3-none-any.whl |
|---|---|
| Size | 30.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b831471d5b69196e81cb852d544e9a6ccb0238d548b9d4c3480e05f31c8dd48
|
|
BLAKE2b-256 checksum How to use checksums |
8673d772f096ce733545f0dc09430204c4ef649103074ad4296ef0a6f8b61ca2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logSecurity for experimentation-toolkit 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for experimentation_toolkit-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.