Skip to main content

experimentation-toolkit

CI PyPI Python 3.12 Last commit License: MIT Ruff mypy codecov

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
  • 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.

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.1 supports independent, two-arm, fixed-horizon analyses only. It does not implement paired or clustered designs, exact unconditional proportion tests, covariate adjustment, CUPED, sequential monitoring, alpha spending, 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.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for experimentation-toolkit 0.1.0
File Size Uploaded Provenance Actions
experimentation_toolkit-0.1.0.tar.gz 19.6 kB With provenance Details for experimentation_toolkit-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for experimentation-toolkit 0.1.0
File Interpreter ABI Platform Actions
experimentation_toolkit-0.1.0-py3-none-any.whl Python 3 none any Details for experimentation_toolkit-0.1.0-py3-none-any.whl

Total release size: 43.8 kB

Release files / experimentation_toolkit-0.1.0.tar.gz

Download URL experimentation_toolkit-0.1.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6a6093ce82509893a94cdb12d095338c5039a5542bb2317d3ed59f97d5496c85
BLAKE2b-256 checksum
How to use checksums
be5a66b8670bf2aba0bd3259c9075d5ec3bb7c6ab80980a37f9e5c46fdec2b15
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 15, 2026.

Transparency log

Release files / experimentation_toolkit-0.1.0-py3-none-any.whl

Download URL experimentation_toolkit-0.1.0-py3-none-any.whl
Size 24.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60c3865100d3ec2c2a0cb5f0778f0ecb9fe3fbaae7d2b9a3eb656bf8e635e5fc
BLAKE2b-256 checksum
How to use checksums
3cff5991dd29c6a986390f75f433c957b19a5d85bbb2a4061fd0b8683924ad2e
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 15, 2026.

Transparency log

Security for experimentation-toolkit 0.1.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.

Select from 2 files

Attestation for experimentation_toolkit-0.1.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 15, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page