Sub topic 12
Testing more than two variants
This chapter assumes you can run a two-proportion z-test and compute a per-variant sample size, as covered earlier. It builds on the p-value and sample size functions from those chapters. Adding variants looks cheap, because you only write more subject lines. The statistics get harder, though, and the chance of crowning a false winner goes up with every variant you add.
Why extra variants inflate false winners
A significance level of 0.05 means that when a variant is truly no different from the control, you still see a "significant" result 5% of the time. That risk applies to each comparison. If you compare several variants against the control, the risks add up. The chance of at least one false positive across k independent comparisons is 1 − 0.95^k.
| Comparisons (k) | Chance of at least one false winner |
|---|---|
| 1 | 5.0% |
| 3 | 14.3% |
| 5 | 22.6% |
| 10 | 40.1% |
This is the family-wise error rate. A test with ten subject lines, each compared to the control, produces a "winner" about 40% of the time even when every line performs identically. The problem is worse when people test many subject lines "to see what sticks" and only report the best one.
Decide the family of comparisons first
Before you send, write down which comparisons you will make. This list is the "family", and every correction below depends on its size.
- Each variant against the control. This gives k = (number of variants) − 1 comparisons. It is the usual design when the control is your current subject line.
- All pairs. With n variants this gives n(n − 1)/2 comparisons. Four variants give 6 pairs, and ten give 45. Use it only when you really need a full ranking.
- One planned comparison. If your hypothesis says that variant C will beat the control, and the others are exploratory, you can designate C as the single primary comparison. Treat the rest as hints for a follow-up test.
Choosing the family after you see the data is a form of peeking. It brings back the inflation you were trying to remove.
Correcting p-values
A correction makes each comparison harder to pass so that the family as a whole keeps its 5% error budget.
Bonferroni
Divide alpha by the number of comparisons, or equivalently multiply each p-value by k (capping at 1). With 3 comparisons, a variant needs p < 0.0167. It is simple and always valid, but conservative. The more comparisons you make, the more real winners it misses.
Holm
Holm's method is a step-down version of Bonferroni and is never less powerful. Sort the p-values from smallest to largest. Multiply the smallest by k, the next by k − 1, and so on down to 1. Then make sure the adjusted values never decrease as you go up the sorted list. Holm controls the same family-wise error rate, so use it as the default.
Benjamini–Hochberg
When you screen many ideas and can tolerate a few false leads, you can control the false discovery rate instead: the expected share of "winners" that are false. It is more permissive than Holm. It suits an exploratory program with dozens of variants, but not a single high-stakes send.
Worked example
Four subject lines, 20,000 recipients each. The control gets 400 clicks. Variants B, C and D get 430, 480 and 445 clicks. This script reuses the z-test from the significance chapter and adds both corrections.
from math import sqrt
from statistics import NormalDist
def two_proportion_z_test(success_a, sent_a, success_b, sent_b):
p_a = success_a / sent_a
p_b = success_b / sent_b
pooled = (success_a + success_b) / (sent_a + sent_b)
se = sqrt(pooled * (1 - pooled) * (1 / sent_a + 1 / sent_b))
z = (p_b - p_a) / se
p_value = 2 * (1 - NormalDist().cdf(abs(z)))
return p_b - p_a, z, p_value
def bonferroni(p_values):
k = len(p_values)
return [min(1.0, p * k) for p in p_values]
def holm(p_values):
k = len(p_values)
order = sorted(range(k), key=lambda i: p_values[i])
adjusted = [0.0] * k
running_max = 0.0
for rank, i in enumerate(order):
value = min(1.0, (k - rank) * p_values[i])
running_max = max(running_max, value)
adjusted[i] = running_max
return adjusted
control_clicks, sent = 400, 20000
variants = {"B": 430, "C": 480, "D": 445}
raw = []
for name, clicks in variants.items():
diff, z, p = two_proportion_z_test(control_clicks, sent, clicks, sent)
raw.append(p)
bonf = bonferroni(raw)
holm_p = holm(raw)
for (name, clicks), p, b, h in zip(variants.items(), raw, bonf, holm_p):
print(f"{name}: clicks={clicks} raw p={p:.4f} bonferroni={b:.4f} holm={h:.4f}")The raw p-values come out near 0.29 for B, 0.0064 for C and 0.082 for D. After Bonferroni they are about 0.88, 0.019 and 0.25. After Holm they are about 0.29, 0.019 and 0.16. Only C survives either correction, and it does so with room to spare. D looked promising on its own (p ≈ 0.08), but that is not enough evidence once three comparisons are in play.
Planning sample size for several variants
Corrections raise the bar, so you need more recipients to keep the same power. Plan with the adjusted alpha. The sample size function below is the one from the earlier chapter.
from math import ceil
from statistics import NormalDist
def sample_size_per_variant(p_base, p_target, alpha=0.05, power=0.8):
z_alpha = NormalDist().inv_cdf(1 - alpha / 2)
z_beta = NormalDist().inv_cdf(power)
variance = p_base * (1 - p_base) + p_target * (1 - p_target)
return ceil((z_alpha + z_beta) ** 2 * variance / (p_target - p_base) ** 2)
k = 3
print(sample_size_per_variant(0.02, 0.025)) # one comparison
print(sample_size_per_variant(0.02, 0.025, alpha=0.05 / k)) # Bonferroni, 3 comparisonsFor a move from a 2% to a 2.5% click rate, one comparison needs about 13,800 recipients per variant. With the Bonferroni alpha for three comparisons, each variant needs about 18,400, roughly a third more. There are also four groups instead of two, so the total is around 73,700 recipients instead of about 27,600. Many lists cannot support that. If yours cannot, run fewer variants, aim for a larger effect, or accept less power.
Common errors
- Picking the best of many. The top variant of several is biased upward. Its observed lift is usually larger than its true lift (the "winner's curse"). Expect the rollout to show a smaller gain than the test did.
- Uneven groups. Keep all variants the same size unless you have a reason. If the control must be larger because you compare all others to it, that is fine, but recompute power.
- Mixing factors. Testing three subject lines at three send times creates nine cells. If you only want to know which subject line is best, do not vary send time. If you want both, run a factorial design and check for interaction, which needs much more volume.
- Skipping the correction because the test "looked clean". The error comes from the number of comparisons, not from how convincing one result looks.
- Correcting but still peeking. Corrections do not fix repeated looks at the data over time. Fix the sample size and analyze once.
Rollout with several variants
If one variant survives correction, send it to the remainder of the list. If none do, you have not shown that any variant beats the control. Keep the control, and log the result as inconclusive instead of choosing the nominal leader. A variant that fails correction but has a plausible hypothesis can be the single planned comparison in a follow-up test.
Exercise
You test a control and 4 variant subject lines, comparing each variant to the control. The raw p-values are 0.012, 0.030, 0.200 and 0.450. Using Holm's method, which variants are significant at the 0.05 level for the family?
Show answer
There are 4 comparisons. Sorted p-values are 0.012, 0.030, 0.200 and 0.450. Holm multiplies them by 4, 3, 2 and 1, giving 0.048, 0.090, 0.400 and 0.450. Adjusted values never decrease, so they stay as listed. Only the variant with raw p = 0.012 (adjusted 0.048) is significant. The variant with raw p = 0.030 is not (adjusted 0.090), even though it passed the uncorrected 0.05 threshold.
Exercise
A colleague runs ten subject lines against a control, finds one with p = 0.04, and wants to roll it out. About how likely is it that at least one of ten comparisons would reach p < 0.05 if no variant had any real effect, and what should you do?
Show answer
About 40% (1 − 0.95^10 ≈ 0.40). A single p = 0.04 among ten comparisons is weak evidence. With Bonferroni it becomes 0.40, which is not significant. Treat it as a hypothesis, and retest that subject line against the control in a new two-variant test sized in advance.