← Back to portfolio A/B Testing Methodology Toolkit preview
Stack
PythonNumPy / SciPypytestuv
Impact
  • 15 modules, each calibrated by simulation: Type I error ≈ α, power curves
  • CUPED: SE shrinks by ~corr(X,Y)²
  • Naive peeking inflates Type I error — Pocock/OBF and mSPRT keep it under control
  • Delta method gives the correct SE for ratio metrics (CTR, RPC) — the naive per-unit t-test is biased
  • End-to-end pipeline: SRM → CUPED → delta-method CTR → per-segment ATE + BH → novelty check

A/B Testing Methodology Toolkit

Business Context

An A/B testing method is only as good as its Type I error under the null and its power under a real effect. Rather than trusting asymptotic promises, each module simulates the pipeline end-to-end and reports the empirical rates.

Modules

ModuleMethodWhat the demo shows
srm_test.pySample Ratio Mismatch (χ²)catches bucketing/traffic bugs before any downstream test
sample_size.pyFixed-horizon sizingn/arm for proportions and means
delta_method_ratio.pyRatio metrics (CTR, RPC)correct SE for ΣY/ΣX; the naive per-unit t-test is biased
cuped.pyVariance reductionSE shrinks by ~corr(X,Y)² using pre-period data
group_sequential.pyAlpha-spending boundariesPocock/OBF control Type I while naive peeking inflates it
msprt_always_valid.pyAlways-valid p-valuesmSPRT lets you peek and stop any time, validly
sequential_ratio.pySequential ratio metricsdelta-method + mSPRT for CTR under continuous monitoring
sequential_ab_testing.pyEvan Miller’s sequential rulereproduces the size table, validates Type I/power, sample savings
bayesian_ab_test.pyAnalytic Bayesian A/BBeta-Binomial / Normal-Normal, P(B>A), expected loss, ROPE
bootstrap_ci.pyBootstrap CIspercentile & BCa for skewed metrics
heterogeneous_treatment_effects.pyHTE by segmentinteraction model reveals Simpson-paradox-like cancellation
multiple_comparisons.pyMultiple-testing correctionBonferroni (FWER) vs Benjamini-Hochberg (FDR)
novelty_primacy.pyTime-varying effectstreat×day interaction detects novelty decay / primacy growth
switchback.pyCluster & switchback designscluster-robust SE; naive over-/under-rejects; carryover bias
test_simulator.pyGeneric test calibrationplug any DGP + test → empirical Type I and power curve

End-to-end pipeline

scripts/run_full_pipeline.py ties the modules into one realistic flow on synthetic data: SRM check → CUPED → delta-method CTR test → per-segment ATE with BH correction → novelty check → a markdown report in outputs/report.md.

Testing Philosophy

The tests/ suite re-runs every calibration with assertions:

  • Type I error ≈ α (± tolerance) for each method under its null;
  • CI coverage ≈ 95% for the bootstrap;
  • naive peeking inflates Type I, always-valid / alpha-spending control it;
  • the naive per-unit ratio SE is inaccurate, the delta-method SE is accurate;
  • correctness on known-answer fixtures (SRM splits, segment uplifts, etc.).

Run

uv sync --all-groups
uv run pytest                 # calibration test suite
uv run python scripts/run_full_pipeline.py   # end-to-end demo → outputs/report.md

Impact

  • 15 calibrated modules — from SRM to switchback, each with an A/A null check.
  • Checked numbers — Type I ≈ α, coverage ≈ 95%, peeking controlled.
  • Unbiased ratio metrics — delta method instead of the naive per-unit t-test.
  • Cohesive pipeline — from SRM check to per-segment ATEs and a novelty check.

Documentation

Case study

Problem

A/B testing methods are sold on asymptotic promises, but nobody checks the Type I error under the null or the power under a real effect. Naive peeking, wrong SEs for ratio metrics, and multiple testing silently break decisions.

Approach

Each module is implemented from the primary literature and calibrated by simulation: an A/A null check for Type I error ≈ α and a power curve under a real effect. 15 topics are covered — SRM, sizing, CUPED, delta method, alpha spending (Pocock/OBF), mSPRT, sequential ratio, Bayesian A/B, bootstrap BCa, HTE, Bonferroni/BH, novelty/primacy, switchback. All wired into an end-to-end pipeline: SRM → CUPED → CTR test → per-segment ATE with BH → novelty check → report.

Result

The numbers are checked, not assumed: the test suite asserts Type I error ≈ α for every method, ≈95% CI coverage for bootstrap, peeking control for always-valid/alpha-spending, delta-method accuracy for ratio metrics, and correctness on known-answer fixtures.

15 Modules
A/A per method Type I error checks
~corr(X,Y)² SE reduction (CUPED)
Pocock/OBF, mSPRT Peeking control