Skip to content

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.

Applied ~12 min10 steps

What runs in CodeSplash

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

Read first

01

Four numbers

Read

PowerStatistical 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, α\alpha and the power itself. Fix three and solve for the fourth.

For two equal groups, the usual normal approximation is:

n=(z1−α/22pˉ(1−pˉ)+z1−βp1(1−p1)+p2(1−p2))2(p1−p2)2n = \frac{\left(z_{1-\alpha/2}\sqrt{2\bar p (1 - \bar p)} + z_{1-\beta}\sqrt{p_1(1 - p_1) + p_2(1 - p_2)}\right)^2}{(p_1 - p_2)^2}

The gap sits squared in the denominator, so halving the gap roughly quadruples nn.

02

Guess the size

Predict

Predict first

You expect 50% against 65%, and you want 80% power at a two-sided α\alpha 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.

03

Pull the levers

Explore

This explorable plans a t test using Cohen's dd, 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 nn 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.

0.50
How sure?
0.50

Standardized difference between the group means.

30

α

Alternative

1

Each outcome is tested at α ÷ this number.

E[t] = 1.94H₁

Solid: t under H₀. Dashed: t if the effect is real. Shaded orange: power, the alternative's area inside the hatched rejection region.

80%

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

04

The baseline matters

Read

The variance p(1−p)p(1 - p) is largest at ½, so the same gap costs most near 50%. Lehr's quick rule for 80% power shows it:

n≈16 pˉ(1−pˉ)δ2=16×0.575×0.4250.152≈174n \approx \frac{16\, \bar p (1 - \bar p)}{\delta^2} = \frac{16 \times 0.575 \times 0.425}{0.15^2} \approx 174

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%, hh = −0.19, and a three-to-one allocation needs 283 and 849 people: 1,132 in all.

05

Uneven groups

Reflect

For a given total, equal groups give the most power. With an allocation ratio rr, you need about (1+r)2/(4r)(1 + r)^2 / (4r) times the total of an equal design. At r=3r = 3, that's 16/1216 / 12: 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?

06

When n is fixed

Read

Often 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?

07

Tables and Cohen's w

Read

For 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, w=X2/nw = \sqrt{X^2 / n}, and power comes from a noncentral χ2\chi^2 with λ=nw2\lambda = n w^2.

Solve forGivenAnswer
Sample sizeww = 0.30, 1 df, 80% power88 people
Powerww = 0.25, 6 df, 150 people61%
Detectable effect3 df, 400 people, 90% powerww = 0.19

More degrees of freedom spread the same effect across more cells, so they need more people.

08

Check your understanding

Checkpoint

Check yourself

Use Lehr's rule, 16pˉ(1−pˉ)/δ216\bar p(1 - \bar p)/\delta^2, for pˉ=0.5\bar p = 0.5 and a gap of δ=0.1\delta = 0.1. 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 X2X^2 = 20. What is Cohen's ww?

Show the answer

Answer: 0.2

√(20 / 500) = √0.04 = 0.2.

Check yourself

You plan for ww = 0.3 with 100 people. What is the noncentrality parameter λ=nw2\lambda = n w^2?

Show the answer

Answer: 9

100 × 0.09 = 9.

Check yourself

Keep ww and nn 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.

09

Do it in CodeSplash

In the app

These 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.

Python
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))
R
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)
10

Recap

Recap
  • Power links the two proportions, nn, α\alpha and power: fix three and solve for the fourth.
  • The same gap costs most near 50%, and halving the gap quadruples nn.
  • Plan before you collect. After a result, report its interval rather than its "observed power".

Concepts in this lesson