Sample Size for Comparing Two Means

medium
Unit 16 · A/B Testing0/2 to milestone

To detect a difference δ\delta between two means with common standard deviation σ\sigma, the per-group sample size for a two-sided test is

n=2 (z1−α/2+z1−β)2 σ2δ2n = \frac{2\,(z_{1-\alpha/2} + z_{1-\beta})^2\,\sigma^2}{\delta^2}

rounded up. Implement n_per_group(delta, sigma, alpha=0.05, power=0.8), computing normal quantiles yourself by bisection on Φ\Phi (via math.erf).

Also implement mde(n, sigma, alpha=0.05, power=0.8): the minimum detectable effect for a given n per group (the same formula solved for δ\delta).

#ab-testing#power-analysis2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Sample Size for Comparing Two Means · TechGradify