A/B Testing — Sequential Monitoring and Power

Python · NumPy · SciPy  ·  R · gsDesign

The Peeking Problem

An online A/B test is a randomized experiment, so identification is settled before it starts. What the online setting adds is a problem of a completely different kind: results arrive continuously, and everyone wants to look at them. A classical p-value is only valid at a sample size fixed in advance, and checking repeatedly turns each look into another opportunity to cross the threshold by luck. This is the most common inferential mistake in industry experimentation, and it is not a subtle one.

The way to measure it is an A/A test — both arms identical, true effect exactly zero, so every rejection is a false positive by construction. Testing once gives the nominal 4.8%. Checking after each batch and stopping the first time z>1.96|z| > 1.96 gives this:

looks taken on a true null (A/A)Type-I error rate
1 (the honest fixed-sample test)0.048
20.077
50.138
100.191
200.242
500.302

At twenty looks the false-positive rate is 24%. Roughly one A/A test in four declares a winner where nothing whatsoever is happening. And the curve is still climbing at fifty looks — there is no sample size at which peeking becomes safe, because the running z-statistic is a random walk that will eventually wander across any fixed boundary. Stopping at the first crossing is guaranteed to find one if you wait long enough.

The Classical Answer — Fix n in Advance

The classical discipline is to fix the sample size in advance from a power calculation and look exactly once. For a two-sample difference in means the requirement per arm follows from the effect worth detecting, and inverting it gives the minimum detectable effect at a sample size you already have.

n=2σ2(z1α/2+z1β)2δ2n = \frac{2\sigma^2\left(z_{1-\alpha/2} + z_{1-\beta}\right)^2}{\delta^2}
effect to detect, δusers needed per arm (80% power)
0.056,279
0.101,570
0.20392
0.5063
inverted: at n = 1,000 per arm the minimum detectable effect is 0.125

Two consequences govern all experiment planning, and both are visible in the table. Sample size scales with 1/δ21/\delta^2, so halving the effect you want to catch quadruples the users needed — 1,570 per arm at δ=0.1\delta = 0.1 becomes 6,279 at 0.05. And the MDE improves only as 1/n1/\sqrt{n}, so traffic buys sensitivity at a punishing rate. The design is honest, and it is also rigid enough that teams peek anyway, which is what makes the third approach necessary rather than merely elegant.

Always-Valid Inference — the Mixture SPRT

Always-valid inference resolves the tension instead of policing it. The mixture sequential probability ratio test (Johari, Pekelis & Walsh 2017 — the engine behind Optimizely's Stats Engine) places a mixing prior over the unknown effect and tracks the likelihood ratio of "some effect" against "none". Under the null that ratio is a non-negative martingale with mean 1, so Ville's inequality bounds the probability that it ever exceeds 1/α1/\alpha — not at one sample size, but across all of them simultaneously.

Λn=VnVn+τ2  exp ⁣(δ^n2τ22Vn(Vn+τ2)),Pr ⁣(n:Λn1/α)α\Lambda_n = \sqrt{\frac{V_n}{V_n+\tau^2}}\;\exp\!\left(\frac{\hat\delta_n^{\,2}\,\tau^2}{2\,V_n\,(V_n+\tau^2)}\right), \qquad \Pr\!\big(\exists\, n : \Lambda_n \ge 1/\alpha\big) \le \alpha

That is the whole trick, and it is worth being clear about why it works. The fixed-sample test controls error at one pre-committed moment, so looking at other moments spends error it never budgeted for. The martingale bound is a statement about the entire path, so no amount of looking can exhaust it. The reciprocal pn=1/Λnp_n = 1/\Lambda_n is an always-valid p-value and inverting the statistic gives a confidence sequence valid at all times.

The measured payoff is both halves at once. Under continuous peeking — checking after every single observation — the mSPRT holds Type-I error at 3.6%, against roughly 25% for naive peeking at the same cadence. And under a real effect of 0.1 it reaches 93% power with a median stop at 1,454 per arm, which is earlier than the fixed-horizon design's 1,570. Monitoring continuously is not merely permitted, it is faster.

under continuous monitoring, checking every observationresult
mSPRT Type-I error on a true null0.036 controlled at 0.05
naive peeking at the same cadence~0.25 and rising
mSPRT power at δ = 0.10.93
median stopping point1,454 per arm against a fixed horizon of 1,570

The Pharmaceutical Answer — Group-Sequential Boundaries

The R companion supplies the pharmaceutical counterpart, which solved the same problem thirty years earlier under stricter regulatory constraints. Group-sequential designs pre-specify a small number of interim looks and spend the error budget across them with a boundary that starts stringent and relaxes. O'Brien–Fleming runs 4.56, 3.23, 2.63, 2.28, 2.04 across five looks — nearly impossible to cross early, essentially the nominal threshold at the end — while Pocock uses a flat 2.41 throughout. The cost is the interesting part: O'Brien–Fleming inflates the maximum sample size by only 2.8%, Pocock by 22.9%. Simulated on an A/A test at five looks, the O'Brien–Fleming boundary holds Type-I at 4.3% where naive five-look testing gives 14.1%.

five interim looksz-boundariesmax sample-size inflation
O’Brien–Fleming4.56   3.23   2.63   2.28   2.041.028×
Pocock2.41   2.41   2.41   2.41   2.411.229×
simulated A/A Type-I at five looks: O’Brien–Fleming 0.043 against naive five-look testing at 0.141

Where this sits

This builds directly on the RCT foundations — the design is unchanged, only the monitoring is new — and pairs naturally with covariate adjustment, since CUPED cuts the variance and therefore reaches any given boundary sooner; the two compound rather than compete. The test-inversion logic behind a confidence sequence is the same move that produces conformal prediction's intervals in the ML arc, and the martingale argument is the same object that underpins the sequential methods there. The remaining notebooks in this group take up the other ways an online experiment fails without any identification problem at all: ratio metrics, correlated dashboards, and interference between users.

Notebooks

References