A/B Testing
A controlled experiment that randomly splits subjects into a control and a variant, then tests whether the measured difference is real or just noise. The disciplined way to decide "did this change actually help?"
Prerequisites: Hypothesis Testing, Confidence Intervals
An A/B test is the cleanest way to answer "did my change help?" You take one population, split it at random into two groups, show group A the old thing and group B the new thing, and measure some outcome, a click-through, a conversion, a fill rate, an execution cost. Randomization is the whole trick: because people land in A or B by coin flip, the two groups are on average identical in every other respect, so any difference in the outcome can be pinned on the change rather than on who happened to be in which group. In trading the same discipline shows up in transaction-cost analysis, routing order flow to two execution algorithms and comparing slippage.
The core test
For a yes/no outcome like conversion, each group gives a proportion. Call them and with sample sizes and . The null hypothesis is that the true rates are equal; the difference is just sampling noise. To test it, pool the two groups for the shared rate (where is the count of successes), compute the standard error, and form a z-statistic:
The numerator is the observed lift; the denominator is how big a lift you would expect from noise alone. If is large (past about for a two-sided test), the difference is bigger than noise can comfortably explain and you call it real.
Randomize first, then test. The z-statistic is observed lift divided by the noise you would expect anyway. Randomization is what turns a difference into evidence about your change rather than about the two groups differing to begin with.
Worked example
You test a new checkout page. Over a week:
| Group | Visitors | Conversions | Rate |
|---|---|---|---|
| A (control) | 1000 | 100 | 10.0% |
| B (variant) | 1000 | 130 | 13.0% |
The variant looks percentage points better, but is that real? Pool the rate: . The standard error is
So
which gives a two-sided p-value of about , under . The lift clears the bar: you would see a gap this large by chance only about time in if the pages were truly equal. Report it with a confidence interval on the difference too, roughly , so you know the effect could be as small as a fraction of a point.
Plan the sample size before you start
The most common failure is running a test that never had a chance of detecting the effect you cared about. The number of subjects per group needed to detect a difference scales like
where and come from your chosen significance and power. The key lesson is the in the denominator: halving the effect you want to catch quadruples the sample you need. Decide the minimum lift worth caring about, then compute , before collecting a single data point.
Fix the sample size and the metric in advance. Deciding to catch a lift versus a lift changes the required sample by , so this choice, not the analysis, is what usually determines whether your test can succeed.
Where A/B tests go wrong
- Peeking. Checking the result repeatedly and stopping the moment it hits significance dramatically inflates false positives, every peek is another chance for noise to cross the line. If you genuinely need to monitor as data arrives, use sequential testing, which is built for exactly that.
- Many metrics, many chances. Test one change against twenty metrics at each and you will "find" something. This is a multiple-testing problem; pre-register one primary metric.
- Sample ratio mismatch. If your 50/50 split arrives as 52/48, something is broken in the randomization or logging, and the whole result is suspect.
- Statistical vs practical significance. With enough traffic a trivial lift becomes "significant." Ask whether the effect is large enough to matter, not merely whether .
Do not watch the p-value and stop as soon as it dips below . This "peeking" can push the true false-positive rate several times past your nominal . Commit to a sample size up front, or switch to a sequential method designed to be checked continuously.
An A/B test is just Hypothesis Testing with randomization bolted on, and its two great enemies, peeking and running many comparisons, lead straight into Sequential Hypothesis Testing and false-discovery-rate control.
Related concepts
Practice in interviews
Further reading
- Kohavi, Tang & Xu, Trustworthy Online Controlled Experiments
- Wasserman, All of Statistics (Ch. 10)
- Gelman & Hill, Data Analysis Using Regression and Multilevel Models