How many do you need? Power for proportions and tables
Sample size for a proportion depends on the baseline as well as the gap. Solve for n, for power or for the smallest detectable difference, and do it before you collect data.
What runs in CodeSplash
- Power analysis — proportions Verified in Python and R
- Power analysis — χ² tests Verified in Python and R
You will be able to
- Solve for the sample size that detects a chosen gap between two proportions
- Explain why the baseline proportion changes the answer
- Plan a chi-square test using Cohen's w
Four numbers
ReadPowerStatistical powerThe chance a test detects an effect of a given size, if that effect is real. is the chance of detecting a real difference of the size you chose. It ties together the two proportions, the sample size, and the power itself. Fix three and solve for the fourth.
For two equal groups, the usual normal approximation is:
The gap sits squared in the denominator, so halving the gap roughly quadruples .
Guess the size
PredictPredict first
You expect 50% against 65%, and you want 80% power at a two-sided of 0.05. How many people do you need in each group?
Make your guess between 10 and 500 per group, then reveal.
Reveal
170 per group, 340 in total. The formula gives 169.3, which rounds up, and that size delivers 80.2% power.
Pull the levers
ExploreThis explorable plans a t test using Cohen's , and the trade-offs are the same. Change the effect size and see where the rejection region sits. Then look at the power curve, and find how much extra each extra point of power costs.
BExplorable · Power explorer
How likely is my study to detect an effect that is really there?
Guess the power: the chance this study rejects H0 if the effect is real.
Standardized difference between the group means.
α
Alternative
Each outcome is tested at α ÷ this number.
Solid: t under H₀. Dashed: t if the effect is real. Shaded orange: power, the alternative's area inside the hatched rejection region.
Commit your prediction above to see the result
Make your prediction to see the result.
The baseline matters
ReadThe variance is largest at ½, so the same gap costs most near 50%. Lehr's quick rule for 80% power shows it:
That's near the formula's answer. On the arcsine scale, Cohen's hCohen's hThe gap between two proportions on the arcsine scale, so equal values of h are about equally hard to detect. compares gaps fairly across baselines.
Rare events can still be expensive. With 10% against 5%, = −0.19, and a three-to-one allocation needs 283 and 849 people: 1,132 in all.
Uneven groups
ReflectFor a given total, equal groups give the most power. With an allocation ratio , you need about times the total of an equal design. At , that's : a third more people.
You might still accept that if one arm is much cheaper, or if you want more people on a treatment you expect to help.
In your setting, what would justify paying for uneven groups?
When n is fixed
ReadOften the sample is already set, so solve for something else.
With 250 per group, a baseline of 20% and 90% power, the smallest detectableMinimum detectable effectThe smallest true effect a test of this size would detect with the planned power. second proportion is 32.7%, a gap of 0.127.
Or solve for power. Testing 80 people against a reference of 50%, when you expect 62%, a one-sided test has 70% power.
If a gap that large is the smallest you could detect, is the study still worth running?
Tables and Cohen's w
ReadFor chi-square tests, Cohen's wCohen's wEffect size for chi-square tests. It measures how far the true cell shares sit from the null's. plays the role of the gap. For an observed table, , and power comes from a noncentral with .
| Solve for | Given | Answer |
|---|---|---|
| Sample size | = 0.30, 1 df, 80% power | 88 people |
| Power | = 0.25, 6 df, 150 people | 61% |
| Detectable effect | 3 df, 400 people, 90% power | = 0.19 |
More degrees of freedom spread the same effect across more cells, so they need more people.
Check your understanding
CheckpointCheck yourself
Use Lehr's rule, , for and a gap of . How many people per group?
Show the answer
Answer: 400
16 × 0.25 / 0.01 = 400.
Check yourself
You halve the gap you want to detect. Roughly what happens to the sample size?
Show the answer
Answer: b
The gap is squared in the denominator, so a gap half as big needs about four times the people.
Check yourself
A chi-square test on 500 people gives = 20. What is Cohen's ?
Show the answer
Answer: 0.2
√(20 / 500) = √0.04 = 0.2.
Check yourself
You plan for = 0.3 with 100 people. What is the noncentrality parameter ?
Show the answer
Answer: 9
100 × 0.09 = 9.
Check yourself
Keep and fixed and move from a 2 × 2 table to a 4 × 4 table. What happens to power?
Show the answer
Answer: a
The noncentrality is the same, but the test now has 9 degrees of freedom rather than 1, so it needs a larger statistic to reject.
Check yourself
A study gives p = 0.20, and a colleague computes "observed power" from its own effect size to explain the result. What does that add?
Show the answer
Answer: b
Observed power restates the p-value. To judge the study, report the confidence interval, or the smallest effect it could have detected.
Do it in CodeSplash
In the appThese planners need no dataset. In the proportions planner, set Solve for, Design, Proportion 1 and Proportion 2, then Allocation ratio, Target power and Significance level. Test chooses one- or two-sided, and Approximation chooses normal or arcsine. The chi-square planner takes Effect size (Cohen's w) and Degrees of freedom.
import numpy as np
from scipy import stats
from statsmodels.stats.power import GofChisquarePower, NormalIndPower
from statsmodels.stats.proportion import proportion_effectsize
# Normal approximation, as in R's power.prop.test
za, zb = stats.norm.ppf(0.975), stats.norm.ppf(0.8)
p1, p2 = 0.5, 0.65
pbar = (p1 + p2) / 2
top = za * np.sqrt(2 * pbar * (1 - pbar)) + zb * np.sqrt(p1 * (1 - p1) + p2 * (1 - p2))
print((top / (p1 - p2)) ** 2)
# Arcsine approximation with three controls per treated
h = proportion_effectsize(0.05, 0.1)
print(NormalIndPower().solve_power(effect_size=h, ratio=3, alpha=0.05, power=0.8))
# Chi-square: n_bins = df + 1
print(GofChisquarePower().solve_power(effect_size=0.3, n_bins=2, alpha=0.05, power=0.8))power.prop.test(p1 = 0.5, p2 = 0.65, power = 0.8)
# Power of a chi-square test, from the noncentral distribution
pchisq(qchisq(0.95, df = 1), df = 1, ncp = 88 * 0.3^2, lower.tail = FALSE)Recap
Recap- Power links the two proportions, , and power: fix three and solve for the fourth.
- The same gap costs most near 50%, and halving the gap quadruples .
- Plan before you collect. After a result, report its interval rather than its "observed power".
Concepts in this lesson