Sample size and power
Where each input to a sample size calculation pushes the answer, why a rare outcome demands an unreasonably large trial, and one thing demonstrated here with a few thousand simulations — post hoc power is a completely determined function of the p value, so computing it is just restating the p value on another scale.
Four inputs determine one number
A sample size calculation needs four things, and none of them is optional:
| Input | What it is | Who decides it |
|---|---|---|
| α (type I error) | The chance of claiming an effect when there is none | Conventionally 0.05; interim analyses consume part of it |
| Power (1 − β) | The chance of detecting an effect that is really there | Conventionally 0.80 or 0.90 |
| The effect to be detected | The size below which you are content not to detect it | A clinical judgement, not a statistical question |
| Variance or baseline risk | How spread out the outcome is | Pilot studies, the literature, registry data |
The smaller the effect, the faster the cost explodes
Hold the control arm risk at 10%, α at 0.05 and power at 80%, and watch the sample size as the effect to be detected shrinks:
| Control risk | Treated risk | Absolute reduction | Per arm | Total |
|---|---|---|---|---|
| 10% | 5.0% | 5.0 percentage points | 435 | 870 |
| 10% | 6.0% | 4.0 percentage points | 721 | 1,442 |
| 10% | 7.0% | 3.0 percentage points | 1,356 | 2,712 |
| 10% | 8.0% | 2.0 percentage points | 3,213 | 6,426 |
| 10% | 8.5% | 1.5 percentage points | 5,856 | 11,712 |
| 10% | 9.0% | 1.0 percentage points | 13,495 | 26,990 |
Going from detecting a 5.0 percentage point reduction to detecting a 1.0 percentage point one takes the per-arm number from 435 to 13,495 — roughly 31 times as many people.
Sample size is roughly inversely proportional to the square of the effect size. Halve the effect and you need four times the sample.
Rare outcomes demand unreasonable samples
Look at it from the other direction: fix the effect at “halve the relative risk” and vary the baseline risk.
| Control risk | Treated risk | Total |
|---|---|---|
| 30% | 15.0% | 242 |
| 20% | 10.0% | 398 |
| 10% | 5.0% | 870 |
| 5% | 2.5% | 1,812 |
| 2% | 1.0% | 4,638 |
| 1% | 0.5% | 9,346 |
For an effect that sounds equally impressive throughout — “halving the risk” — a baseline risk of 30% needs 242 people, and a baseline of 1% needs 9,346.
Post hoc power: a number carrying no information
Discussion sections are full of sentences like this: “our study did not reach statistical significance; the post hoc power was only 20%, indicating an insufficient sample size.”
That sentence is circular. Here it is drawn out over 4,000 simulated trials — each with 40 patients per arm and a true effect fixed at 0.35 standard deviations (an underpowered design, so most simulations land on the non-significant side):
figures/scripts/B8-02-sample-size.RTheir Spearman correlation is -1.0000 — not “strongly correlated” but a perfectly determined monotone relationship. Post hoc power is a function of the p value, and the p value is a function of it.
Across the 2,609 simulated trials that did not reach significance, the median post hoc power is 0.195, and the maximum is only 0.503. The median of 0.195 is a product of this particular setting (40 per arm, true effect 0.35 SD) and would be a different number under other parameters; the maximum of 0.503 is the general fact — when p lands exactly on 0.05, observed power is necessarily around 0.5, whatever the sample size and the true effect.
What to report instead: the width of the confidence interval
“Did not detect a difference” means very different things at different sample sizes. Simulate studies whose true effect is zero and look at the upper limit of the 95% confidence interval, in standard deviation units:
| Per arm | Upper confidence limit (median) | Effects that can be ruled out |
|---|---|---|
| 40 | 0.451 SD | Anything larger than 0.45 standard deviations |
| 100 | 0.278 SD | Anything larger than 0.28 standard deviations |
| 400 | 0.138 SD | Anything larger than 0.14 standard deviations |
A study with a true effect of zero and 40 patients per arm can only rule out effects larger than 0.45 standard deviations — by Cohen’s convention (0.2 small, 0.5 medium, 0.8 large) that is roughly a medium effect, so this null has ruled out almost nothing of clinical importance. A study with the same true effect of zero but 400 per arm rules out a far smaller range, and is correspondingly more informative.
(All three rows are simulations in which the true effect is zero, not a subset of “studies that did not reach significance” — when the true effect is zero about 95% of simulations are non-significant anyway, so the two medians are close, but they are two different quantities.)
This is the right way to ask how much a null result is worth.
Doing the calculation yourself
# Sample size per arm for two proportions
n_per_arm <- function(p1, p2, alpha = 0.05, power = 0.80) {
z_a <- qnorm(1 - alpha / 2)
z_b <- qnorm(power)
pbar <- (p1 + p2) / 2
num <- (z_a * sqrt(2 * pbar * (1 - pbar)) +
z_b * sqrt(p1 * (1 - p1) + p2 * (1 - p2)))^2
ceiling(num / (p1 - p2)^2)
}
n_per_arm(0.10, 0.05) # control 10%, treated 5%
# In practice use a package; they cover far more designs
# install.packages("pwr")
# pwr::pwr.2p.test(h = pwr::ES.h(0.10, 0.05), power = 0.80)Verified with R 4.6.0. Every number on this page comes from simulation, with the seed fixed at 20260822.
import numpy as np
from scipy.stats import norm
def n_per_arm(p1, p2, alpha=0.05, power=0.80):
z_a, z_b = norm.ppf(1 - alpha / 2), norm.ppf(power)
pbar = (p1 + p2) / 2
num = (z_a * np.sqrt(2 * pbar * (1 - pbar)) +
z_b * np.sqrt(p1 * (1 - p1) + p2 * (1 - p2))) ** 2
return int(np.ceil(num / (p1 - p2) ** 2))
print(n_per_arm(0.10, 0.05))
# statsmodels has this ready-made too
# from statsmodels.stats.power import NormalIndPowerstatsmodels' power module covers the common designs; for anything more involved (survival, cluster, non-inferiority) reach for R's pwr or powerSurvEpi.
Extra considerations for particular designs
| Design | What else has to be handled |
|---|---|
| Non-inferiority trial | The margin has to be fixed in advance, and the sample is usually larger than for a superiority trial; report both ITT and per-protocol |
| Cluster randomised | Multiply by the design effect 1 + (m − 1) × ICC, where m is the cluster size |
| Survival analysis | Power is driven by the number of events, not the number of people; longer follow-up and more patients are interchangeable |
| Diagnostic accuracy | The denominators are the number of cases and the number of controls; the total is not the quantity that matters |
| Prediction model | EPV ≥ 10 has been superseded; use Riley’s sample size calculation |
| Interim analyses | α has to be allocated across the looks, so the final threshold is below 0.05 |
Common misuses
| Misuse | Why it is wrong |
|---|---|
| Computing post hoc power after a null result as evidence of an insufficient sample | It is a function of the p value and adds nothing; report the confidence interval instead |
| Using a pilot study’s point estimate as the effect to detect | The winner’s curse; pilot effect estimates are inflated and unstable |
| Setting “the effect to detect” equal to “the effect we expect” | What belongs there is the minimal clinically important difference |
| Not adjusting the calculated sample for attrition | Divide the number to enrol by (1 − expected attrition) |
| Powering a survival analysis on people rather than events | Power is determined by the number of events |
| Omitting the design effect in a cluster randomised trial | Intracluster correlation makes the effective sample far smaller than the nominal one |
| Reusing a superiority sample size for a non-inferiority trial | The margin is usually smaller than the expected difference, so a larger sample is needed |
| Using 0.05 as the final threshold when interim analyses were done | Repeated looks inflate the type I error; an alpha spending function is required |
Reproducing every number on this page
/opt/homebrew/bin/Rscript figures/scripts/B8-02-sample-size.RRead the figure
The answer comes from the same statistical output that produced this page's figures, not from a number typed in beside them.
A protocol was written to detect a control risk of 10% falling to 5%, which gave 435 per arm. The clinicians then say that a fall to 7% would already be worth having, so the effect to be detected is made smaller. Which number is the new per-arm figure, and what does that show?
Show the answer and why
Correct answer: 1356. The effect shrinks to three fifths of what it was and the sample size more than triples - sample size scales roughly with the inverse square of the effect
Sample size scales roughly with the inverse square of the effect. Going from five percentage points down to three is a factor of three fifths, whose inverse square is close to three, and 435 scaled up a little over threefold is 1356. Under a linear rule the answer would be 721 - which happens to be the row for detecting four percentage points, so it looks like a reasonable number, and that is exactly why linear intuition is so hard to catch. 2712 is the total for the same row, and reading a total as a per-arm figure halves the apparent size of the trial. What to take away: setting the minimal clinically important difference lower does not cost proportionally more, it costs quadratically more, and that value is a clinical judgement rather than a statistical one.
For the same effect - halving the risk - a trial with a control risk of 30% needs 242 in total. What does it need when the control risk falls to 1%, and why?
Show the answer and why
Correct answer: 9346. The relative effect is the same, but events have become rare, so accumulating enough of them to tell the arms apart takes far more recruitment
What drives sample size is the number of events, not the number of people. At a control risk of 30%, 242 accumulate enough events; at 1% the same relative effect needs 9346, because each participant now contributes a thirtieth of the event probability. 1812 is the row for a control risk of 5%, and one more row sits between it and 9346, so modest rise does not survive contact with this table. 4673 is the per-arm figure for the same row: the total column is not double-counting, it is the two arms added, and reading it as double-counting halves the apparent size of the trial. This is why rare adverse events almost never reach a conclusion inside an ordinary efficacy trial, and why safety signals usually come from post-marketing database studies.
A paper writes: this study did not reach statistical significance, and post-hoc power was only 20%, indicating an insufficient sample size. This page used four thousand simulations to check how post-hoc power relates to the p value. Which statement is right?
Show the answer and why
Correct answer: The Spearman correlation between the two is -1.000, a completely determined monotone relationship - post-hoc power carries no information the p value does not
A correlation of -1.000 is not high correlation but a function: given the sample size and the design, post-hoc power can be computed from the p value and the p value from it. Low power and a large p value are therefore the same sentence on two scales, and neither can stand as independent evidence about sample size. 0.195 is a product of this particular simulation setup; another set of parameters gives another number, so quoting it as a general fact says something false. 0.503 is the largest post-hoc power among the non-significant runs, and why it lands there is handled by another question on this page. What has to be refused here is the one thing more: how far the data were from detecting an effect is fixed by the p value, and converting one into the other and back adds nothing. What a non-significant study should report is the confidence interval, because it answers directly how large an effect the data rule out.
Two studies both report no statistically significant difference. One had 40 per arm and the other 400. What decides which null is more informative?
Show the answer and why
Correct answer: The upper confidence limit. With 40 per arm the median upper limit is 0.451 standard deviations, already a medium effect by Cohen's convention, so this null rules out nothing of clinical importance
Both studies say no difference was detected, but what they exclude differs by more than threefold: 40 per arm rules out only effects larger than 0.451 standard deviations, while 400 per arm reaches 0.138. The first is already at the scale Cohen's convention calls a medium effect, so nothing of clinical importance has been excluded; the second actually says something. Claiming both converge near 0.138 takes a property of the large-sample row and gives it to both, when the monotone shrinking of the upper limit down the three rows is exactly what this section exists to show. The post-hoc power route simply loops back on itself: power is a function of the p value, a non-significant study cannot have high post-hoc power by definition, and so it cannot separate these two studies at all.
Two protocols both say they will detect a halving of risk. The first has a control risk of 20% and the second 5%. Will they need the same sample size?
Show the answer and why
Correct answer: No. When the relative effect is the same, the absolute difference is what drives sample size; the protocol with 20% control risk needs 398 in total, far fewer than the other
Halving is a relative quantity, and sample size feeds on the absolute one. Halving a control risk of 20% is a ten point absolute fall and costs 398 in total; halving a control risk of 5% is a quarter of that fall and costs 1812. Saying both need 1812 takes the second protocol's figure and applies it to both, which is the relative effect misread as independent of baseline risk. 199 is the first protocol's per-arm figure, and the total is twice that - reading a per-arm figure as a total is what produces a difference of only a few dozen, when the real gap is several fold. Whenever a protocol says halving the risk, the first question is what the baseline risk is.
Among the 2609 runs that did not reach significance, with 40 per arm and a true effect of 0.35 standard deviations, post-hoc power has a maximum. What is special about it?
Show the answer and why
Correct answer: It is 0.503, and it depends on neither the sample size nor the true effect - when p lands exactly on the significance threshold, observed power must sit near a half
0.503 is the only universal number in this section: post-hoc power is a function of the p value, and when p equals the significance threshold exactly, observed power has to sit near a half regardless of sample size or true effect. Not significant and post-hoc power is low are therefore the same fact twice, and the first guarantees the second. 0.195 is the median of the same batch of simulations, a product of the 40 per arm and 0.35 standard deviation setup, so it changes with the parameters and quoting it as a general fact says something false. 0.278 is not even in the same column: it is a median upper confidence limit at a larger per-arm size, measured in standard deviations rather than in probability. To say how informative a null is, read the confidence interval, not post-hoc power.
Chapters that use this method
Sources and licences
This page is original writing