Fair Race
Robo built a new game-recommending model, B. Is it really better than the old one, A? The only fair way to know: send real players to each and count how many click Play. But luck plays tricks, and stopping too early lets luck fool you.
Press Play and players start arriving. Each one is sent to A or B. Watch the two click rates, their wobbly "could be anywhere in here" bars, and the p-value line.
Players: 0
Dot = click rate so far. Bar = 95% confidence interval: the real rate is probably somewhere inside. Bars shrink as more players arrive.
p-value: "if A and B were really the same, how often would luck make a gap this big?" Below the red line (0.05) people call it a winner. Watch how it wiggles!
The peeking problem: 200 races where nobody is better
Each square is a whole A/A race (A and B are identical, so any "winner" is fake). Every race runs up to 1,000 players per group. Peeking checks the p-value every 25 players and stops at the first p < 0.05. Planned only checks once, at the end.
Peeking: stop at first p < 0.05
Fake winners: -
Planned: check once at the end
Fake winners: -
The promise of "p < 0.05" is: only about 5 races in 100 (10 of these 200) show a fake winner. That promise only holds if you look once.
Challenges
What just happened?
- An A/B test is a fair race: players are sent to A or B at random, so the only difference between the groups is the model.
- Click rates wobble by luck. The confidence interval bars show how much. Early on they are huge and overlap.
- The p-value asks: if A and B were the same, how surprising is this gap? It wiggles up and down a lot, even in an A/A test.
- If you keep checking and stop the moment p dips below 0.05, luck will hand you a fake winner far more often than 5% of the time. That is peeking.
- The fix: decide how many players you need before you start, then look once. Small wins need lots of players.
- A bandit sends more players to whoever is doing better as it goes. It misses fewer clicks, but it is not a clean race, so its p-values are not trustworthy.
How it works
- Each player flips a coin (weighted by the split slider) to see A or B.
- The player clicks Play with the model's secret true chance. We only see clicks, never the chance.
- Click rate = clicks ÷ players for each model, with a 95% interval around it.
- The z-test turns the gap between the rates into a p-value: big gap and lots of players = small p.
- The bandit keeps a belief about each model's rate, makes a lucky guess from each belief, and sends the player to the bigger guess.
For grown-ups: what's really going on
Users are Bernoulli trials with hidden rates pA, pB (8–14%, B differs by −2 to +4 points, or equals A in A/A mode). The two-proportion z-test uses the pooled estimate: z = (p̂B − p̂A) / √(p̂(1 − p̂)(1/nA + 1/nB)), two-sided p = 2(1 − Φ(|z|)). Intervals are 95% Wilson score intervals, which behave better than ±1.96·SE for small n and rates near 0.
- Sample size per group for α = 0.05 (two-sided), power 1 − β = 0.8:
n = (z1−α/2√(2p̄(1−p̄)) + z1−β√(p1(1−p1) + p2(1−p2)))² / (p2 − p1)². 10% → 12% needs 3,841 per group; halving the effect roughly quadruples n. - Optional stopping ("peeking"): with 40 looks the chance that a random walk of z ever crosses ±1.96 is far above 5% (about 25–30% here). Valid alternatives: fix the horizon; group-sequential designs with alpha-spending boundaries (Pocock, O'Brien–Fleming); or always-valid sequential tests (mSPRT, e-values) built to be checked continuously.
- Under H₀ p-values are uniform on [0, 1], so a single fixed-horizon test has exactly α false positives; the 200-race grid estimates that rate with about ±3 points of noise.
- Thompson sampling: Beta(1 + clicks, 1 + misses) posteriors; each user goes to the arm with the larger posterior draw. It minimises regret
Σt (max(pA, pB) − parm(t)), but adaptive allocation biases the naive z-test and starves the losing arm of data, so bandits optimise reward rather than give a clean estimate. - Both strategies share common random numbers: each user has one uniform draw u and converts on arm k iff u < pk, so their regrets are directly comparable.
Further reading: Kohavi, Tang and Xu (2020), Trustworthy Online Controlled Experiments; Johari et al. (2017), Peeking at A/B Tests; Russo et al. (2018), A Tutorial on Thompson Sampling.