Calculate the required sample size for a checkout A/B test
Statistics & ExperimentsModel answerLast updated
Derive the minimum per-group sample size for a two-sample proportion test given baseline conversion, MDE, and standard error and power requirements.
Scenario
You are a data scientist at an e-commerce company. The product team wants to test a redesigned checkout button (treatment) against the current button (control). They ask you to tell them how many users each group needs before they can read out results.
Given information
| Parameter | Value |
|---|---|
| Baseline conversion rate (control) | 10% |
| Minimum Detectable Effect (MDE) | +2 percentage points (i.e., 12% treatment) |
| Significance level α | 0.05 (two-tailed) |
| Desired statistical power 1 − β | 0.80 |
What is expected
- Write down the formula for the per-group sample size for a two-proportion z-test.
- Identify the critical z-values needed and explain where they come from.
- Plug in the numbers and compute the required sample size per group (you may leave your arithmetic transparent — show each intermediate value).
- State the total number of users needed across both groups.
- Explain intuitively what would happen to the sample size if the MDE were halved to +1 percentage point.
Hints
Hint 1
The two z-values you need correspond to α/2 (two-tailed critical value) and β (power). For α=0.05 two-tailed and 80% power, recall z_{0.025} ≈ 1.96 and z_{0.20} ≈ 0.84.
Hint 2
The pooled variance term uses both p_c and p_t. Under the null you pool the two rates; under the alternative you sum the individual variances. A common approximation pools at the average of the two proportions.
Hint 3
After computing n, always round up to the nearest whole number. Also mention the real-world factors that could inflate this number further (e.g., novelty effect, traffic seasonality).
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Step 1 — Formula
For a two-sided, two-proportion z-test the standard per-group sample size formula is:
$$ n = \frac{(z_{\alpha/2} + z_{\beta})^2 \cdot [p_c(1-p_c) + p_t(1-p_t)]}{(p_t - p_c)^2} $$
Where:
p_c= baseline (control) conversion ratep_t= expected treatment conversion ratez_{α/2}= critical value for significance (two-tailed)z_β= critical value for power
This formula comes directly from setting the Type I error of the null-distribution sampling distribution equal to α and the Type II error of the alternative-distribution equal to β, then solving for n.
Step 2 — Identify the z-values
| Symbol | Meaning | Value |
|---|---|---|
| z_{α/2} = z_{0.025} | Upper 2.5% of standard normal | 1.96 |
| z_{β} = z_{0.20} | 80th percentile of standard normal | 0.84 |
- 1.96 comes from the fact that P(Z > 1.96) = 0.025 for a standard normal, covering both tails at α = 0.05.
- 0.84 comes from P(Z < 0.84) ≈ 0.80, ensuring 80% power.
Their sum: (1.96 + 0.84)² = (2.80)² = 7.84
Step 3 — Compute intermediate values
Given:
- p_c = 0.10, so p_c(1 − p_c) = 0.10 × 0.90 = 0.090
- p_t = 0.12, so p_t(1 − p_t) = 0.12 × 0.88 = 0.1056
- Effect size: (p_t − p_c)² = (0.02)² = 0.0004
Numerator:
7.84 × (0.090 + 0.1056) = 7.84 × 0.1956 = 1.533
Denominator:
0.0004
n per group:
n = 1.533 / 0.0004 = 3,832.5 → round up to 3,833
Step 4 — Total sample size
Total = 2 × 3,833 = 7,666 users
Both groups must reach 3,833 users before the experiment is called. Reading out early inflates the false-positive rate (the "peeking problem").
Step 5 — What happens if MDE is halved?
If MDE drops from 2 pp to 1 pp (i.e., p_t = 0.11), the denominator becomes (0.01)² = 0.0001, which is 4× smaller. Because n is inversely proportional to (Δp)², the required sample size scales by roughly 4×, to approximately ~15,300 per group.
This is the single most important intuition: sample size grows with the square of the inverse effect size. Chasing very small effects is expensive.
Common mistakes to avoid
- Forgetting to round up. Always use ceil(n), not floor. Rounding down leaves the experiment underpowered.
- One-sided vs. two-sided confusion. Using z_{0.05} = 1.645 instead of z_{0.025} = 1.96 is appropriate only if you have a strong directional hypothesis stated before the experiment. Default to two-sided.
- Ignoring the variance of both groups. Some candidates only use p_c(1-p_c). The correct formula sums the variance of both groups.
- Conflating sample size with runtime. The question asks for users, not days. You still need to divide by daily traffic to get runtime, and adjust for seasonality or ramp-up periods.
- Not mentioning practical constraints. Even if the math says 7,666 users, real experiments need guardrail metrics monitored, novelty effects dissipated (usually 1–2 weeks minimum), and allocation checks (e.g., SRM — Sample Ratio Mismatch tests).
Quick reference for common z-value pairs
| α (two-tailed) | Power | z_{α/2} | z_β | (z_{α/2}+z_β)² |
|---|---|---|---|---|
| 0.05 | 80% | 1.96 | 0.84 | 7.84 |
| 0.05 | 90% | 1.96 | 1.28 | 10.50 |
| 0.01 | 80% | 2.58 | 0.84 | 11.56 |