experimentation-toolkitGitHub

Decision-first experimentation

Is your A/B test telling you the truth?

Eleven worked modules on real data: a 64,000-customer email test and California's 1988 tobacco tax. Every method is checked on the data before it is trusted, and every result ends in a decision.

Checking every day turns a 5% false alarm rate into 21%

What most A/B tests get wrong

Measured on real customers, not assumed from a formula.

Check results every day and stop at the first win

21% false alarms instead of the promised 5%

Switch to the bootstrap because revenue is skewed

9% false alarms with 1,000 customers per group

Size the test with the textbook formula

Too optimistic on revenue: 161K per group vs 173K by simulation

Read "not significant" as "no effect"

This test would have missed a worthwhile lift 5 times out of 6

Expect CUPED to shrink the noise

A year of purchase history removed under 0.1% of revenue variance

Build an uplift model to target who gets the email

Two uplift models ranked customers no better than random, and emailing everyone beat every targeting policy

Trust difference-in-differences without checking the trends

A fake 1980 "policy" showed a 12-pack effect, and DiD overstated Prop 99's real impact by about 40%

The modules

Each one is a question a team actually asks.

How I approach experiments

  1. Decide before you look. The decision rule, guardrails and the smallest lift worth acting on are written down before any result is seen. The plan is a file the analysis reads, not a slide.
  2. Calibrate every method on the data you have. Before trusting a test, I run thousands of fake A/A experiments on real control-group data and check that it gets false positives and intervals right. Textbook formulas often break on real metrics like revenue.
  3. Answer in money and risk, not p-values. Incremental revenue per 1,000 emails, the expected loss of each option, and the chance each option is best.
  4. People respond differently, so decisions should too. Find who the treatment actually changes, and decide who to treat after counting the cost.
  5. Say what the data can't tell you. Some questions have no reliable answer at this sample size, and saying so is part of the result.

Use it on your own tests

pip install git+https://github.com/ai-with-md/experimentation-toolkit
from exptoolkit.checks import sample_ratio_check
from exptoolkit.estimators import welch_t
from exptoolkit.calibration import aa_test
from exptoolkit.power import simulate_power
from exptoolkit.sequential import obf_boundaries

# df: one row per customer, with an "arm" column and your metric
control = df.loc[df["arm"] == "control", "revenue"]

# 1. Were the groups split the way you planned?
sample_ratio_check(df)["p_value"]

# 2. Does the t-test behave on *your* metric at *your* size? (A/A test on real data)
aa_test(control, welch_t, n_per_arm=5_000).false_positive_rate

# 3. How likely is a test of this size to catch a 10 cent lift?
simulate_power(control, revenue_lift=0.10, n_per_arm=20_000)

# 4. Checking daily for two weeks? Use these thresholds instead of 1.96.
obf_boundaries(n_looks=14)

# 5. A policy you could not randomize? Build a synthetic comparison group.
from exptoolkit.causal import synthetic_control
result = synthetic_control(panel, treated="California", start=1989)   # panel: years x units
result.weights, result.average_effect