Learn · Part E · Chapter 17

Power and sample size

How many do I need before I start? Plan the sample for the smallest effect worth acting on.

The power curve: how many customers Helion's next experiment needs

Target rate: 37 %

Target power: 80 %

The two worlds at the planned sample size, and the power curve At a sample size of 3,993, the test statistic's cut-offs are −1.96 and 1.96; if the effect is real, 0.800 of its distribution lies beyond them, which is the power. The power curve rises with the sample size and reaches 0.800 at 3,993. The test statistic at n = 3,993: if H₀ holds, and if the effect is real −1.96 1.96 H₀ true: no effect The effect is real α = 0.05 power = 0.800 Power against the sample size 0.0 0.2 0.4 0.6 0.8 1.002,5005,0007,50010,000Sample size per group (per arm) n = 3,993, power 0.800

From 34 % to 37 %, α = 0.05, target power 80 %: 3,993 customers per arm (Cohen's h = 0.063); the power at that size is 0.800.

A curve rises from left to right: the power of the two-sided two-proportion z test at α = 0.05 against the number of customers per arm, for a lift from 34 % to 37 %. A dashed line marks the target power of 80 %; where the curve crosses it, a marker reads off the sample size: 3,993 customers per arm. Above it, two worlds show the test statistic's distribution at that sample size if there is no lift and if the lift is real, with the cut-offs of the test; the second curve's area beyond them is the power. Sliders change the lift, the target power and α.

What you just saw

Helion is planning its next experiment on paperless billing. The baseline is 34 %, and finance will not fund a change that lifts it by less than 3 points. How many customers per arm does the test need to catch a 3-point lift 80 % of the time? The curve answers: power rises with every customer added, slowly at first, and crosses 80 % at 3,993 customers per arm.

The two worlds above the curve show why. They are the test statistic's distribution if there is no lift and if the lift is real. Every extra customer moves the second world further from the first, so more of it lands beyond the test's cut-offs. Move the lift slider: a smaller lift pushes the curve to the right and the sample size up, fast; halving the lift roughly quadruples the sample.

The two questions to ask about power

  • Before the study: how many observations do I need for an 80 % chance of detecting the smallest effect I would actually act on? That is a sample size calculation, and skipping it is how underpowered studies happen.
  • After a non-significant result: what is the smallest effect this design could reliably have detected, the minimum detectable effect? Without that number, "we found no difference" cannot be interpreted. With it, you can say the useful thing: "we found no difference, and we would have caught anything larger than this".

Both questions are asked about the effect worth acting on, which comes from the decision, not from the data. That is the whole difference between planning power and misusing it.

How many customers would we need?

For two proportions, the calculation runs on Cohen's h (chapter 16), and the sample size per arm comes from turning the power formula round:

In words: \(z_{1-\alpha/2}\) is the test's cut-off (1.96 for α = 0.05, two-sided), \(z_{1-\beta}\) the extra distance needed for the power you want (0.8416 for 80 %), and \(h\) the lift you want to catch on Cohen's scale. For Helion, \(h = 2\arcsin\sqrt{0.37} - 2\arcsin\sqrt{0.34} = 0.063\), so \(n = 2 \times ((1.96 + 0.8416) / 0.0627)^2\), just over 3,992; always round up, to 3,993 per arm.

Sample size for the primary metric (the tutorial's table 24)
InputValue
Baseline adoption34.0 %
Target lift (the finance threshold)3.0 percentage points
Cohen's h for that lift0.063
Customers needed per arm (α = 0.05, power 80 %)3,993
Customers per arm in the Portal v2 test5,969: adequately powered

Smaller effects cost more than people expect. A lift from 10 % to 12 % conversion, a common target for a sign-up page, has h = 0.064 and needs about 3,835 customers per group; a 1-point lift from 10 % needs about four times as many.

What is the smallest effect we could have detected?

For days to payment at 5,969 customers per arm, the minimum detectable effect at 80 % power is a Cohen's d of 0.051, or 0.18 days in real units (d times the standard deviation of days to payment, 3.48 days). The observed effect of 1.09 days sits comfortably above it.

This second number is what makes a null result interpretable. "We found no difference" is uninterpretable on its own. "We found no difference, and this design would have detected anything larger than 0.18 days" is a finding. Report the MDE alongside every non-significant result and the file drawer stops being a black hole.

Planning, not observed power: the bottles

The tutorial's bottles (chapter 6) did not reject H₀: μ = 500 with 25 bottles, t = 2.00 and p = 0.057. The worked example then asks how much power the study had. Done right, this is planning: the drift worth catching on the filling line is 4 ml, so with σ about 10 ml the effect is d = 0.40, and the one-sample t test with 25 bottles had power 0.484 against it. To reach 80 %, the solver gives 51.009 bottles, which rounds up to 52 (at 51 the power is 0.7999, just under the target).

Done wrong, the same arithmetic is observed power: power computed at the effect the sample happened to show, after the test. It adds no evidence, because it is a restatement of the p-value: a result exactly on the 5 % line always has an observed power of about 0.50, whatever the study. The 0.484 above is legitimate only because 4 ml is the drift the plant cares about, chosen before looking; it would be meaningless as a verdict on this sample.

Why this is true: Why observed power is the p-value in disguise

For a two-sided z test, power at an effect that gives an expected statistic of \(\delta\) is \(\Phi(\delta - z_{1-\alpha/2}) + \Phi(-\delta - z_{1-\alpha/2})\).

Observed power plugs in the observed \(|z|\) as \(\delta\). But \(|z|\) is a fixed function of the p-value, so observed power is too: p = 0.05 means \(|z| = 1.96\) and a power of 0.50; a smaller p gives a larger observed power. A non-significant result always has observed power under about a half. It cannot tell you anything the p-value did not.

Power for the other tests: ANOVA and chi-square

Every test has a power calculation; only the effect size changes. For ANOVA it is Cohen's f, for a chi-square test Cohen's w (the square root of the summed squared differences between the true and the hypothesised shares, each divided by the hypothesised share). Helion's channel-mix test compares 1,600 contacts with the forecast shares over 4 channels; against a small shift in the mix (w = 0.1) it has power 0.93, comfortably above 80 %. It would need 1,091 contacts for exactly 80 %.

Why it matters

An experiment sized by whatever traffic showed up is a coin flip dressed as evidence. Sizing it first, for the smallest effect worth acting on, tells you whether to run it at all, how long it must run, and what a null result will mean. It is the cheapest decision in the whole readout.

When this goes wrong

A power calculation is only as good as its inputs: the baseline rate, the spread and the effect are all guesses before the data, and a wrong baseline moves the answer. Plan for the smallest effect worth acting on, not the effect you hope for; the hoped-for effect is always bigger and gives a sample that is too small. Allow for customers who drop out, and remember that testing several metrics or peeking at the data (chapter 18) changes the error rates the calculation assumed.

In code

What it computes Python (scipy, statsmodels) Excel
Customers per arm for a 3-point lift from 34 % NormalIndPower().solve_power(proportion_effectsize(0.37, 0.34), alpha=0.05, power=0.8, ratio=1) =2*((NORM.S.INV(0.975)+NORM.S.INV(0.8))/(2*ASIN(SQRT(0.37))-2*ASIN(SQRT(0.34))))^2
The minimum detectable d at 5,969 per arm TTestIndPower().solve_power(nobs1=5969, alpha=0.05, power=0.8, ratio=1) =(NORM.S.INV(0.975)+NORM.S.INV(0.8))*SQRT(2/5969)
Bottles needed for 80 % power against a 4 ml drift TTestPower().solve_power(effect_size=0.4, alpha=0.05, power=0.8) =((NORM.S.INV(0.975)+NORM.S.INV(0.8))/0.4)^2
Power of the channel-mix test against w = 0.1 GofChisquarePower().power(effect_size=0.1, nobs=1600, alpha=0.05, n_bins=4) =1-NORM.S.DIST(NORM.S.INV(0.95)-0.1*SQRT(1600), TRUE)

The power classes are in statsmodels.stats.power, proportion_effectsize in statsmodels.stats.proportion. Excel has no non-central t, F or χ², so its lines are the normal approximation: close for large samples (the bottles need 49.06 by it, against 51.009 with the t test's exact power), rougher for χ².

Try this Plan the pilot of chapter 16 properly: how many customers per arm to catch a real lift from 11 % to 13.8 % 80 % of the time?
Try this Turn the question round: with 5,969 customers per arm, what is the smallest d this design catches?
Try this The bottles: power of the one-sample t test with 25 bottles against d = 0.4.
Remember: Plan power before the data, for the smallest effect worth acting on: it tells you how many observations you need, and after a null result, the smallest effect you could have caught. Round the sample size up. Never compute power at the effect you observed: that is the p-value in disguise.

Practise

5 exercises

Quiz

Three questions on the chapter. Your best score is kept in this browser.

1. Why plan power before the experiment instead of computing it afterwards from the observed effect?
2. A 3-point lift from 34 % needs 3,993 customers per arm at 80 % power. Roughly how many does a 1.5-point lift need?
3. A test with 5,969 customers per arm finds no significant change in days to payment; its MDE was 0.18 days. What can you say?
Answer every question first.
An unhandled error has occurred. Reload 🗙

Reconnecting…

Your connection to Hypothesis Testing Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.