PROBABILITY & STATISTICS · INTERVIEW QUESTION
How do you determine sample size for an A/B test?
🟡 intermediate · Experimental Design
Hint: Think about significance level, power, minimum detectable effect, and baseline rate.
Answer
Sample size determines how long an A/B test must run to detect a meaningful difference with statistical confidence.
Key Inputs
| Parameter | Typical Value | Description |
|---|---|---|
| 0.05 | Significance level (Type I error rate) | |
| 0.80 | Statistical power | |
| MDE () | Varies | Minimum detectable effect |
| From data | Metric variance |
Formula
python
from math import ceil
from statsmodels.stats.power import NormalIndPower
analysis = NormalIndPower()
n = analysis.solve_power(
effect_size=0.05, # standardized mean difference delta / sigma
alpha=0.05,
power=0.80,
alternative='two-sided'
)
print(f'Required sample size per group: {ceil(n)}')This normal-approximation formula gives the required sample size per arm, with equal allocation, common variance, absolute mean difference delta, and standard-normal quantiles. For conversion rates, specify baseline and alternative rates and use a two-proportion power calculation; a relative MDE is not the standardized effect above.
Practical Considerations
- Use a prespecified sequential testing procedure if monitoring for early stopping
- Account for multiple comparisons (Bonferroni correction)
- Consider CUPED for variance reduction
- Ensure the test runs for at least one full business cycle
Related questions
- Explain Bayes' theorem and give an ML application.
- What is the difference between Type I and Type II errors? How do they relate to precision and recall?
- Explain the difference between MAP and MLE estimation. When would you prefer one over the other?
- What is the Law of Large Numbers? How does it relate to ML?
- Explain the Central Limit Theorem and its assumptions. Why is it important in data science?