ML0070 A/B Test Design

How would you design an A/B test, including sample size and duration?

Answer

An A/B test is a randomized controlled trial: randomly assign users to control (A) and treatment (B), measure a pre-registered primary metric, and compare the two arms with a hypothesis test. The design happens before any traffic flows: pick one primary metric and a minimum detectable effect (MDE), fix \alpha and power (0.05 and 0.8 are common defaults), and compute the required sample size per arm from the metric’s variance. Duration follows from daily traffic, rounded up to whole business cycles (at least one to two weeks) so day-of-week effects average out, and the decision is made once at the pre-committed end rather than by peeking at daily p-values.

(1) Hypothesis and MDE First: state the expected effect and the smallest effect worth shipping for. The MDE, \alpha, power, and metric variance together pin down the sample size.
(2) Duration by Cycles, Not by Peeking: run whole weeks to cover weekly seasonality and never stop early on a crossing p-value. Booking.com simulated null experiments and found that daily peeking lets over half of them touch 95% significance at some point, versus the promised 5%.
(3) Sensitivity Is the Bottleneck: variance reduction beats longer runs. CUPED (developed at Microsoft) uses pre-experiment covariates to cut metric variance by about 50%, halving the required users or duration, and Booking.com warns that tracking users the change cannot reach dilutes the measured effect and inflates the required sample size by the dilution factor squared.

Flow diagram: hypothesis with MDE leads to random assignment into arms A and B, then a run of full weekly cycles, then one test at the pre-committed end, then a ship or iterate decision

Figure 1: The design pipeline: fix the hypothesis, MDE, \alpha, and power up front; randomize; run whole business cycles; test exactly once at the pre-committed sample size; then ship, iterate, or abandon.

Mathematical Formulation:
n = \frac{2 \, (z_{1-\alpha/2} + z_{1-\beta})^2 \, \sigma^2}{\delta^2}
\sigma^2 = p \, (1 - p) \ \text{for a binary metric}

Where:

  • n is the required sample size per arm; \delta is the MDE; \sigma^2 is the per-user metric variance.
  • z_{1-\alpha/2} and z_{1-\beta} are normal quantiles for the significance level and power (1.96 and 0.84 at the usual settings).
  • p is the baseline rate for a binary metric such as conversion, whose variance is set by p(1 - p).
Sample size per arm on a log scale falling with the square of the minimum detectable effect, with a marked point at 1 percentage point MDE on a 10 percent baseline needing about 14400 users per arm

Figure 2: Sample size per arm falls with the square of the MDE: halving the detectable effect quadruples the traffic needed. On a 10% conversion baseline, a 1-point MDE needs about 14,400 users per arm; a 0.25-point MDE needs about 230,000.

Decision RuleWhen You LookFalse Positive ControlCost
Fixed horizon (pre-committed n)Once, at the endExact \alphaRequires patience
Naive peekingDaily, stop on significanceInflated: Booking’s nulls hit 95% over half the timeShips noise
Sequential test (mSPRT, group-sequential)Any timeControlled by constructionWider confidence sequences
Two histograms of the estimated treatment minus control difference: a wide raw distribution and a narrow CUPED-adjusted distribution centered on the same effect

Figure 3: CUPED regresses out the part of the metric explained by pre-experiment behavior, leaving the same estimated effect with roughly half the variance. That is equivalent to doubling the sample size without adding a single user.


Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *