Check an A/B test daily and over a fifth of duds look like winners
A short NumPy script shows clients why the number of looks must be fixed before the experiment goes live.
In brief
- In a 20-day simulation with no real effect, looking every day raised the false positive rate from 5.34% to 22.68%.
- If the client needs interim looks, fix the number in advance and tighten the cutoff: 0.0158 per look for five looks under Pocock.
- A corrected test protects only the decision to stop; a lift figure read early remains uncertain.
David Robinson once simulated a 20-day A/B test, with about 10,000 impressions a day, of a new feature that did nothing at all. Judged on day 20 alone, 5.34% of runs had a p-value below 0.05. Checked every day, 22.68% of runs dipped below that threshold at some point.
The feature was the same and so was the number of days. What changed was how often someone opened the dashboard and was allowed to believe whatever it showed. Evan Miller gives a figure of similar size: in the worst case, testing after every observation, the false positive rate reaches 26.1%.
This exercise takes a familiar situation: the client checks results every morning, sees green and wants to ship at once. Rather than urging patience, you will build a script that runs on their traffic, so they can see for themselves what stopping early costs.
Build a machine that makes fake winners
You need Python 3.8 or later, NumPy and a file called peeking.py. The exercise has three parts: generate thousands of A/A tests, read them on different schedules, then try two valid stopping rules. A/A here means both groups share the same true rate, so every “significant” result is wrong.
The setup is borrowed from Robinson: 20 days and a CTR of 0.1%. The simplifications are an even split of exactly 5,000 impressions per group per day and a two-sided z-test using the normal approximation. On day one each group expects only 5 conversions, so the approximation is still rough.
Step 1: Generate 10,000 tests with nothing to find
import math
from statistics import NormalDist
import numpy as np
SEED, RUNS, DAYS, N = 20, 10_000, 20, 5_000
print("NumPy", np.__version__, "seed", SEED)
def simulate(seed, p_a, p_b):
rng = np.random.default_rng(seed)
a = rng.binomial(N, p_a, size=(RUNS, DAYS)).cumsum(axis=1)
b = rng.binomial(N, p_b, size=(RUNS, DAYS)).cumsum(axis=1)
n = N * np.arange(1, DAYS + 1)
diff = (b - a) / n
pooled = (a + b) / (2 * n)
se = np.sqrt(pooled * (1 - pooled) * 2 / n)
z = np.divide(diff, se, out=np.zeros_like(diff), where=se > 0)
return diff, z
diff, z = simulate(SEED, 0.001, 0.001)
print(z.shape, diff[:, -1].mean())
Each row is one test and each column one day. cumsum accumulates the data from the first day to the day in question: if a test starts on Monday, Wednesday’s result includes Monday and Tuesday.
Check: the shape must be (10000, 20), and the mean difference on the last day must be close to 0. Save the line that prints the version. NumPy’s documentation warns that Generator does not guarantee compatibility across versions, so the same seed may yield a different sequence on the client’s machine.
Step 2: Read the same data on three schedules
def cutoff(alpha):
return NormalDist().inv_cdf(1 - alpha / 2)
def false_positive(z, looks, alpha):
cols = np.array(looks) - 1
return (np.abs(z[:, cols]) > cutoff(alpha)).any(axis=1).mean()
last = [20]
five = [4, 8, 12, 16, 20]
daily = list(range(1, 21))
for name, looks in [("last", last), ("five", five), ("daily", daily)]:
print(name, false_positive(z, looks, 0.05))
The word that matters most is any. It stands in for someone who stops the first time a result crosses the threshold, even if it would have vanished the next day. Because of abs, the count covers both directions: B looking better and B looking worse.
Check: last must be around 5% and daily must exceed 20%. For five, SAS documentation cites Armitage, McPherson and Rowe for a benchmark of 0.14169 when a test at the 0.05 level is repeated over five stages. Your figure will differ slightly because of the normal approximation and the finite number of runs.
How big a gap should worry you? With 10,000 runs, the standard error of a 5% rate is √(0.05 × 0.95 / 10,000), or about 0.22 percentage points. If last comes out at 8%, look for a bug in the code before looking for a statistical explanation.
Step 3: Let the client look, but tighten the cutoff
If the client still wants interim looks, the Pocock boundary offers a way out: use the same p-value cutoff at every analysis, with the number of analyses set in advance. To hold overall alpha at 0.05, the cutoff is 0.0294 for two looks, 0.0221 for three, 0.0182 for four and 0.0158 for five.
print("Pocock, 5 looks", false_positive(z, five, 0.0158))
print("same cutoff, 20 looks", false_positive(z, daily, 0.0158))
Check: the first line must return to around 5%. The second, estimated with the normal approximation, lands at roughly 8–10%, nearly double. It cannot be lower than the first, because those five checkpoints all fall within the 20 days.
That is the number to show when the client asks to “watch it a few more days” at the old cutoff: a cutoff built for five looks keeps its promise only for five looks.
Before the test goes live, you can tell the client: “We decide on days 4, 8, 12, 16 and 20, and stop only if p is below 0.0158. On all other mornings, the dashboard is only for checking errors and sample counts.”
Spotify’s engineers recommend group sequential tests, the family of checkpoint-based tests that includes Pocock, when you can estimate the sample size accurately and do not need to run past it. So the first question for the client is whether their traffic is predictable.
Step 4: Why does the lift at an early stop look so good?
Now make B genuinely better: CTR rises from 0.1% to 0.12%, an absolute difference of 0.0002. Unlike Step 2, the code below deliberately drops abs: the client ships only when B wins, so only the positive direction counts, still at the two-sided test’s z cutoff of about 1.96.
real = 0.0002
diff2, z2 = simulate(SEED + 1, 0.001, 0.001 + real)
cross = z2 > cutoff(0.05)
rows = np.where(cross.any(axis=1))[0]
first = cross.argmax(axis=1)[rows]
early = diff2[rows, first]
print("stopped:", len(rows) / RUNS)
print("overstated:", early.mean() / real)
You can work this out by hand before running it. On day 20 each group has 100,000 impressions and the standard error is about 0.000148, so to cross the cutoff the observed difference must be around 0.00029, nearly 1.5 times the true effect. Day 5 has only a quarter of the data, so the standard error doubles and the minimum climbs to nearly 3 times.
Check: by the hand estimate, overstated is around 3 and stopped is about 0.35–0.45. If your machine gives a ratio below 1.4, the code is probably taking the difference from the wrong day. A client who stops the moment the cutoff is crossed will believe in a lift several times the real one, even though the feature does work.
A tighter cutoff does not remove this effect. Statsig’s documentation notes that early decisions often give underpowered lift estimates with high uncertainty, even with sequential testing. Keep the lift from the stopping day out of the client’s revenue forecast.
Step 5: Try a stopping rule that only needs counting
Evan Miller proposes a procedure for tests split 50/50. Choose N in advance, then count conversions in the treatment group (T) and the control group (C). When T−C reaches 2√N, stop and declare the treatment the winner; when T+C reaches N, stop with no winner.
When the two groups are identical, each conversion is like a coin toss, so the rule can be simulated directly. With N at 400, the winning line is 40.
N_CONV = 400
rng = np.random.default_rng(SEED)
steps = rng.choice([-1, 1], size=(RUNS, N_CONV))
wins = (steps.cumsum(axis=1) >= 2 * math.sqrt(N_CONV)).any(axis=1)
print("simple sequential", wins.mean())
Check: the result must be about 4.5%, because the reflection principle for random walks gives an approximation of 2 × P(Z greater than 2). Here you look after every conversion and still hold the error rate. Miller says the method works best when conversion rates are low, and this version can only conclude that the treatment wins.
Where it most often goes wrong
The first mistake is forgetting to accumulate, which turns each day into a separate test and inflates the error rate for a different reason. The second is harder to spot: choosing the schedule after the run, then picking the Pocock cutoff that matches the number of looks taken. A schedule chosen after seeing the data is no longer protected by that cutoff.
The third is pitching sequential testing to a client while hiding the trade-off. GrowthBook’s documentation states plainly that confidence intervals will be wider than in a fixed-sample test. Clients need to know they are trading precision for the right to stop early.
What to bring to tomorrow’s meeting
Bring the raw output from your machine, with the NumPy version and the seed. The four lines below are enough for one conversation; if your numbers stray far from the benchmarks, fix the code before showing it to the client.
| Printed line | Benchmark | What to tell the client |
|---|---|---|
last |
Around 5% | Wait until day 20 and the false alarm risk is what we agreed |
daily |
Above 20% | With the right to stop every morning, that risk far exceeds what we agreed |
Pocock, 5 looks |
Around 5% | You can look early, provided we stick to the five checkpoints |
overstated |
Around 3 (hand estimate) | Don’t forecast with the lift from the stopping day |
Miller advises people who build A/B testing software not to show significance levels until an experiment is over. If you control the dashboard, hide the p-value column between checkpoints and keep sample counts, system errors and the split ratio. The client still has something to look at every morning, and the right to declare a win belongs to the agreed checkpoints.
Johari, Pekelis and Walsh write that continuous monitoring can easily increase Type I error fivefold, in the context of sample sizes of 10,000, which are common in online A/B testing. If the client dismisses that as theory, replace N, the CTR and the number of days with their own figures and run it in the meeting.
When an FDE job posting asks you to “measure impact,” ask the employer who has the right to stop an experiment and under what rule. On your résumé, write the measured result: “Simulated 10,000 A/A tests, compared three viewing schedules, proposed a five-checkpoint protocol at a 0.0158 cutoff,” with the before-and-after false alarm rates from your machine and a link to the repo.
Then prepare for the interviewer’s hardest question: if the client still wants to stop today, which number do you show them first?
Was this article useful?
Thanks for the feedback!
10 sources
- How Not To Run an A/B Test · 2010-04-18
- Always Valid Inference: Bringing Sequential Analysis to A/B Testing · 2015-12-15
- Is Bayesian A/B Testing Immune to Peeking? Not Exactly · 2015-08-20
- Group Sequential Methods, SAS/STAT 12.1 User's Guide: The SEQDESIGN Procedure
- Pocock boundary
- Choosing a Sequential Testing Framework — Comparisons and Discussions · 2023-03-21
- Sequential Testing (GrowthBook Docs)
- Simple Sequential A/B Testing · 2015-10-13
- Random Generator — NumPy Manual
- Sequential Testing (Statsig Docs)