Calculating A/B Test Sample Size and Duration for Conversion CTR
Statistics & ExperimentsModel answerLast updated
Perform a statistical power analysis to derive required sample size and experiment duration for an A/B test, analyzing the impact of changing MDE and real-world practical constraints.
Scenario
You are an analytics lead designing an experiment to evaluate a redesigned visual element on a online reservation platform. The core metric is the Click-Through Rate (CTR) of the main call-to-action button.
Baseline Metrics & Parameters
- Baseline CTR ($p_1$): 5.0%
- Minimum Detectable Effect (MDE): A relative lift of 10% (i.e., detecting an absolute change from 5.0% to 5.5%).
- Significance Level ($\alpha$): 0.05 (two-tailed)
- Statistical Power ($1 - \beta$): 0.80
- Daily Eligible Users: 20,000 active unique users per day.
- Traffic Allocation: 50/50 split between Control and Treatment.
Tasks
- Compute the required sample size per group using the two-sided two-proportion $z$-test formula.
- Calculate the theoretical minimum runtime (in days) to gather sufficient sample size.
- Explain the mathematical relationship between the MDE and required sample size, including the trade-offs of targeting a smaller MDE.
- Address practical considerations that could influence runtime beyond the mathematical minimum.
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Standard Solution & Analytical Walkthrough
Part 1: Sample Size Calculation
To compare two independent proportions ($p_1$ and $p_2$), the sample size required per group ($n$) for a two-sided test is given by:
$$n = \frac{(Z_{\alpha/2} + Z_\beta)^2 \cdot [p_1(1-p_1) + p_2(1-p_2)]}{(p_2 - p_1)^2}$$
Step-by-Step Numerical Substitution:
-
Inputs:
- $p_1 = 0.050$
- Relative lift = $10% \implies p_2 = 0.050 \times 1.10 = 0.055$
- Absolute difference $\delta = p_2 - p_1 = 0.005$
- $Z_{\alpha/2} = 1.960$ (for $\alpha = 0.05$, two-tailed)
- $Z_\beta = 0.8416$ (for power $1 - \beta = 0.80$)
- Critical value sum: $Z_{\alpha/2} + Z_\beta \approx 1.960 + 0.842 = 2.802$
- Squared critical value sum: $(2.802)^2 \approx 7.851$
-
Variance Calculation:
- Control variance: $p_1(1-p_1) = 0.05 \times 0.95 = 0.0475$
- Treatment variance: $p_2(1-p_2) = 0.055 \times 0.945 = 0.051975$
- Total variance sum: $0.0475 + 0.051975 = 0.099475$
-
Denominator:
- $\delta^2 = (0.005)^2 = 0.000025$
-
Result: $$n = \frac{7.851 \times 0.099475}{0.000025} \approx 31,231$$
(Note: Using the pooled probability variance approximation $2 \cdot \bar{p}(1-\bar{p})$ yields $\approx 31,200$. Both approximations round to approximately 31,200 users per group.)
- Total Required Sample Size: $\approx 62,400$ total users across both variants.
Part 2: Experiment Duration
-
Daily Accrual per Variant:
- Total daily traffic = 20,000 unique users.
- With a 50/50 allocation, Control and Treatment each receive 10,000 users per day.
-
Minimum Mathematical Duration: $$\text{Days} = \frac{31,231 \text{ users/group}}{10,000 \text{ users/group/day}} = 3.123 \text{ days}$$
Rounding up to complete full days gives a mathematical minimum of 4 days.
Part 3: Impact of Reducing the MDE
The sample size $n$ is inversely proportional to the square of the absolute effect size ($\delta$):
$$n \propto \frac{1}{\delta^2}$$
Key Implications:
- Inverse-Square Scaling: If you cut the MDE in half (e.g., from a 10% relative lift / 0.5 percentage point change down to a 5% relative lift / 0.25 percentage point change), the required sample size increases by roughly a factor of 4 ($1 / 0.5^2 = 4$).
- Numerical Example:
- For a 5% relative MDE ($\delta = 0.0025$), $n \approx 122,000$ per group.
- Runtime increases from 4 days to 13 days.
- Business Trade-off: Targeting a smaller MDE enables detection of minor improvements but significantly extends experiment runtime, consuming traffic capacity and delaying product decisions.
Part 4: Practical Considerations & Business Logic
While the statistical math indicates a runtime of ~4 days, stopping an experiment at day 4 in a real-world environment is generally bad practice due to several operational factors:
- Day-of-Week Seasonality (Cyclical Variation): User intent on reservation platforms varies significantly across days (e.g., Friday/Saturday vs. Monday/Tuesday). An experiment must run for at least 7 full days (or 14 days) to capture a complete weekly cycle and prevent day-of-week bias.
- Novelty vs. Primacy Effects: Returning users might click a newly colored button out of curiosity (novelty effect) or avoid it briefly due to unfamiliarity (primacy effect). Running the test longer allows user behavior to reach steady-state equilibrium.
- Unit of Randomization & Independence: The formula assumes each observation is an independent Bernoulli trial. If metric calculations occur at the session or impression level rather than the unique user level, intra-user correlation violates variance assumptions, requiring cluster-robust standard errors or the Delta method.
- Sample Ratio Mismatch (SRM): Ensure continuous monitoring for assignment imbalances (e.g., using a Chi-Square goodness-of-fit test). An unexpected assignment ratio indicates engineering issues (such as redirection latency or broken tracking).
Common Pitfalls to Avoid
- Confusing Relative and Absolute MDE: Using $10%$ ($\delta = 0.10$) instead of $0.5%$ ($\delta = 0.005$) in the denominator produces an underpowered experiment by several orders of magnitude.
- Incorrect Traffic Allocation Division: Dividing total sample size by total platform traffic (20,000) rather than traffic per group (10,000).
- Ignoring Minimum Runtime Rules: Concluding an experiment as soon as $n$ is reached without running full weekly cycles.