Sub topic 9
Calculating sample size before you send
This chapter assumes you know what a click rate is, can read a short Python function, and have a basic idea of probability. Here you will decide how many recipients each variant needs before you launch.
Why size the test first
A test with too few recipients cannot tell a real difference from noise. Small lists produce big random swings in click rate, so you either miss real improvements or crown a false winner. Sizing the test before sending also stops you from ending it whenever the numbers happen to look good.
The four inputs
The required sample size depends on four choices.
| Input | Meaning | Typical value |
|---|---|---|
| Baseline rate | The current rate of your primary metric | 2% click rate |
| Minimum detectable effect (MDE) | The smallest lift worth detecting | +0.5 points (2% to 2.5%) |
| Significance level (alpha) | Accepted chance of a false positive | 0.05 |
| Power | Chance of detecting a real effect of the MDE size | 0.8 |
Power is the probability that the test finds a true effect of at least the MDE. At 0.8, you still miss real effects of that size one time in five.
The calculation
The standard normal-approximation formula for comparing two proportions is:
n = (zalpha + zbeta)² × (p1(1 − p1) + p2(1 − p2)) / (p2 − p1)²
Here zalpha is the critical value for a two-sided test and zbeta matches the power. The result is per variant.
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)
print(sample_size_per_variant(0.02, 0.025))This prints roughly 13,800. A two-variant test therefore needs about 27,600 recipients in total. Those recipients must be randomly assigned, as covered in the earlier randomization chapter.
What moves the number
- Smaller MDE: Sample size grows with the inverse square of the difference. Halving the MDE roughly quadruples the recipients you need.
- Lower baseline rate: Rare events such as clicks need more recipients than common ones.
- Higher power or lower alpha: Both raise the requirement.
Try several MDE values before you commit. If the list cannot support the answer, you have three options. You can accept a larger MDE, test a more frequent metric, or skip the test. Do not run an underpowered test and treat its result as meaningful.
Common errors
- Using open rate as the baseline. Open rates are inflated by Mail Privacy Protection, so the baseline and the effect are both unreliable. Size the test on clicks or another metric you trust.
- Treating the number as a total. The formula returns recipients per variant. Multiply by the number of variants.
- Ignoring more than two variants. Extra variants need extra recipients, and corrections for multiple comparisons raise the requirement further.
- Stopping when the sample is "close enough." Fix the sample size in advance and send to all of it. Checking early invites false winners.
- Counting sends instead of delivered emails. Bounces reduce your effective sample. Add a margin for them.
Exercise
A colleague says the planned test is too small, so they propose detecting a lift half as large as the current MDE. Roughly how does the required sample size per variant change, and why?
Show answer
It rises to about four times the original. The difference between the rates appears squared in the denominator of the formula, so halving it multiplies the required sample size by roughly four.