Kolton Ndoj

A/B testing: how apps decide with statistics

When two friends see a slightly different YouTube thumbnail or app button. You're probably in dozens of experiments right now.

What problem does it solve?

If version B gets more clicks than version A, is it really better, or just lucky?

The big idea

Randomly split users into two groups, show each a different version, and compare. Randomness is the hero: it makes the groups alike in every other way on average, so a difference in results must come from the change, or from chance. Statistics measures how big a gap chance alone usually produces; only gaps much bigger than that count. A p-value of 0.05 means 'if there were truly no difference, a gap at least this big would show up only 5% of the time', not 'there's a 95% chance B is better'.

How it works, step by step

  1. 1. Decide in advance what you'll measure and how many users you need.
  2. 2. Randomly assign each user to A or B.
  3. 3. Measure each group's rate, e.g. the fraction who clicked.
  4. 4. Compute z: the gap divided by the size of gap that chance usually produces.
  5. 5. Only if |z| is large (about 2 or more for p < 0.05) declare a winner, and don't keep peeking and stopping early.

The key formula

z=p^B−p^Ap^(1−p^)(1nA+1nB)z=\frac{\hat p_B-\hat p_A}{\sqrt{\hat p(1-\hat p)\left(\frac{1}{n_A}+\frac{1}{n_B}\right)}}
p^A,p^B\hat p_A,\hat p_B
the measured click rates in each group
p^\hat p
the click rate of both groups pooled together
nA,nBn_A,n_B
how many users were in each group
⋯\sqrt{\cdots}
the 'standard error': the typical gap from luck alone, which shrinks as groups grow

How fast is it?

The arithmetic is trivial; the cost is users and time. To detect a gap half as big you need about 4 times as many users, because the noise shrinks like 1/√n. The biggest dangers aren't maths but habits: peeking every day and stopping as soon as it looks good inflates false wins.

Graph for A/B testing: how apps decide with statistics 100200000.060
The typical gap that pure luck produces between two groups of t users each. To trust a 1-percentage-point difference you need roughly 2 × this to be below 0.01, which means thousands of users per group. (drawn with the default slider values — move the sliders live)

Try it yourself

Fun fact

Google famously tested 41 shades of blue for its links to see which got the most clicks, a story told by Marissa Mayer and criticised by designer Doug Bowman as decision-by-data gone too far.

Related

Open it in the Math Lab →

Theory · Intermediate