Statistics · medium · Asked at Meta
Asked in Data Scientist interviews, in the Statistics round.
Use power analysis: baseline rate, MDE, alpha, power (0.8) to compute n per arm.
Four inputs and one formula. Name the inputs before touching the formula.
from statsmodels.stats.power import NormalIndPower
from statsmodels.stats.proportion import proportion_effectsize
effect = proportion_effectsize(0.033, 0.030) # Cohen's h
n_per_arm = NormalIndPower().solve_power(effect_size=effect, alpha=0.05, power=0.8, ratio=1)
# ~ 27,000 per arm for these numbers
Then turn the number into a duration: per-arm n divided by daily eligible traffic per arm, rounded up to whole weeks so weekday and weekend behaviour are both covered. If that is 9 weeks and the team wanted 1, the honest conversation is about a larger MDE or a more sensitive metric, not a shorter test.
The follow-ups worth pre-empting: the MDE drives everything (halving it roughly quadruples n); fixing n in advance is what makes the p-value valid, so no peeking and stopping early; and for a continuous metric the same calculation uses the metric's standard deviation instead of a rate.