PUBH-311 · Lesson 6 of 12 · 26 min

Hypothesis tests for proportions

▶ Video coming soon A video version of this lesson is on the way.

Kestrel Valley’s smoking cessation service had run a small randomized trial. Two hundred smokers received standard counseling plus text-message support and 200 received standard counseling alone. After six months, 60 in the text-message group and 40 in the control group had verified abstinence. The program manager wanted to roll out text messaging region-wide and asked Jonah to confirm that the result was “significant.” Jonah found that it was, with a p-value of 0.021. But Dr. Osei asked him to go further: how big was the effect, how precisely was it estimated, and how should it be expressed so that decision makers could understand it? Proportions, she said, deserve more than a p-value.

Binary outcomes, such as quit or not, vaccinated or not, infected or not, are the most common outcomes in public health. This lesson covers tests and confidence intervals for one proportion and for comparing two proportions, the effect measures used to express differences (risk difference, risk ratio, odds ratio and number needed to treat), paired binary data, multiple comparisons and sample size for studies with binary outcomes.

Testing a single proportion

The one-sample z-test for a proportion compares an observed proportion \(\hat{p}\) with a hypothesized value \(p_0\), such as a coverage target or a historical rate. Under the null hypothesis, the standard error uses \(p_0\):

\[z = \frac{\hat{p} - p_0}{\sqrt{p_0 (1 - p_0) / n}}\]

The normal approximation is reasonable when \(np_0\) and \(n(1 - p_0)\) are both at least about 10; otherwise an exact binomial test is used.

Worked problem

Is measles vaccine coverage below target?

A school-entry record review samples 400 children and finds 344 have two documented doses of measles-containing vaccine. Is coverage different from the 0.90 target used in the regional plan?

Show solution
  1. Hypotheses: \(H_0: p = 0.90\); \(H_1: p \ne 0.90\).
  2. Observed proportion: \(\hat{p} = 344/400 = 0.86\).
  3. Standard error under the null: \(\sqrt{0.90 \times 0.10 / 400} = \sqrt{0.000225} = 0.015\).
  4. Test statistic: \(z = (0.86 - 0.90)/0.015 = -2.67\).
  5. Two-sided p-value: twice the area below −2.67 in the standard normal, about 0.008.
  6. 95 percent CI for coverage (using the observed proportion in the SE): \(0.86 \pm 1.96 \sqrt{0.86 \times 0.14/400} = 0.826\) to \(0.894\).

Answer: Coverage is estimated at 86 percent (95 percent CI 82.6 to 89.4 percent), significantly below the 90 percent target (z = −2.67, p = 0.008). The interval shows coverage is probably between about 1 and 7 points short.

Note that the test uses \(p_0\) in the standard error because it asks how surprising the data are if the null were true, while the confidence interval uses \(\hat{p}\) because it describes the uncertainty of the estimate itself. The two can occasionally disagree near the boundary.

Coverage targets for measles are set high because the disease is so contagious; elimination is generally thought to require two-dose coverage of about 95 percent. The 0.90 value here is the example region’s interim target.

Comparing two proportions

To compare proportions in two independent groups, the two-sample z-test uses the pooled proportion \(\bar{p}\), the overall proportion with the outcome in both groups combined, to estimate the standard error under the null hypothesis that the two population proportions are equal:

\[z = \frac{\hat{p}_1 - \hat{p}_2}{\sqrt{\bar{p}(1-\bar{p}) \left( \dfrac{1}{n_1} + \dfrac{1}{n_2} \right)}}\]

Worked problem

The text-message cessation trial

In the trial, 60 of 200 in the text-message group and 40 of 200 controls quit. Test whether the quit proportions differ.

Show solution
  1. Proportions: \(\hat{p}_1 = 60/200 = 0.30\); \(\hat{p}_2 = 40/200 = 0.20\). Difference = 0.10.
  2. Pooled proportion: \(\bar{p} = (60 + 40)/400 = 0.25\).
  3. Standard error under the null: \(\sqrt{0.25 \times 0.75 \times (1/200 + 1/200)} = \sqrt{0.001875} = 0.0433\).
  4. Test statistic: \(z = 0.10/0.0433 = 2.31\).
  5. Two-sided p-value: about 0.021.

Answer: The quit proportion was significantly higher with text messaging (30 versus 20 percent; z = 2.31, p = 0.021). The next step is to estimate the size of the effect with confidence intervals.

As Lesson 7 shows, this z-test is mathematically identical to a chi-square test on the two-by-two table: \(z^2 = 2.31^2 = 5.33\), which is the chi-square statistic for these data.

Measures of effect for binary outcomes

A p-value tells us whether a difference is likely to be due to chance, not how large it is. Three effect measures, introduced in Principles of Epidemiology, express the size of a difference between two proportions. Here we add their confidence intervals.

Table 1. Results of the cessation trial (invented data) in the standard two-by-two layout.
QuitDid not quitTotal
Text messagesa = 60b = 140200
Controlc = 40d = 160200
Total100300400

Risk difference

The risk difference (RD), also called the absolute risk difference, is \(\hat{p}_1 - \hat{p}_2\). Its standard error for a confidence interval uses the separate (unpooled) proportions:

\[SE(RD) = \sqrt{\frac{\hat{p}_1(1-\hat{p}_1)}{n_1} + \frac{\hat{p}_2(1-\hat{p}_2)}{n_2}}\]

For the trial, \(SE = \sqrt{0.30 \times 0.70/200 + 0.20 \times 0.80/200} = \sqrt{0.00105 + 0.0008} = 0.0430\), so the 95 percent CI is \(0.10 \pm 1.96 \times 0.0430\), or 0.016 to 0.184. Text messaging increased the quit proportion by 10 percentage points (95 percent CI 1.6 to 18.4 points).

The number needed to treat (NNT) is the reciprocal of the risk difference: 1/0.10 = 10. On average, 10 smokers need to receive text-message support for one additional person to quit. The NNT is intuitive for decision makers, and its confidence interval is found by inverting the limits of the RD interval (here, about 5 to 64). When an intervention prevents a harmful outcome the same idea is called the number needed to treat to benefit; when it causes harm, the number needed to harm.

Risk ratio

The risk ratio (RR), or relative risk, is \(\hat{p}_1 / \hat{p}_2 = 0.30/0.20 = 1.5\): quitting was 1.5 times as likely with text messages. Ratios have skewed sampling distributions, so confidence intervals are calculated on the natural logarithm scale and then transformed back:

\[SE(\ln RR) = \sqrt{\frac{1}{a} - \frac{1}{a+b} + \frac{1}{c} - \frac{1}{c+d}}\]

Here \(SE = \sqrt{1/60 - 1/200 + 1/40 - 1/200} = \sqrt{0.0317} = 0.178\). The interval on the log scale is \(\ln 1.5 \pm 1.96 \times 0.178 = 0.405 \pm 0.349\), or 0.056 to 0.754. Exponentiating gives a 95 percent CI for the RR of 1.06 to 2.13. Because the interval is on the ratio scale, it is not symmetric around 1.5.

Odds ratio

The odds of an outcome are the probability it happens divided by the probability it does not. The odds ratio (OR) compares the odds in two groups: \(OR = (a \times d)/(b \times c) = (60 \times 160)/(140 \times 40) = 1.71\). Its log-scale standard error is

\[SE(\ln OR) = \sqrt{\frac{1}{a} + \frac{1}{b} + \frac{1}{c} + \frac{1}{d}}\]

which here is \(\sqrt{1/60 + 1/140 + 1/40 + 1/160} = 0.235\), giving a 95 percent CI of \(1.71 \times e^{\pm 1.96 \times 0.235}\), or 1.08 to 2.72.

The OR is further from 1 than the RR (1.71 versus 1.5) because the outcome is common. When the outcome is rare, below about 10 percent, the OR and RR are close. The OR is the natural measure in case-control studies, where risks cannot be calculated, and it is the measure produced by logistic regression (Lesson 10). Reporting an OR as if it were a risk ratio when outcomes are common exaggerates the effect.

Table 2. Effect measures for the cessation trial.
MeasureEstimate95 percent CINull valuePlain-language meaning
Risk difference0.100.016 to 0.184010 more quitters per 100 smokers
Number needed to treat10about 5 to 64infiniteTreat 10 to gain one extra quitter
Risk ratio1.501.06 to 2.131Quitting 1.5 times as likely
Odds ratio1.711.08 to 2.721Odds of quitting 1.7 times as high

Absolute and relative measures tell different stories. A risk ratio of 2 sounds impressive whether risk rises from 1 to 2 in 1,000 or from 10 to 20 in 100, but the public health impact differs tenfold. Good practice, endorsed by reporting guidelines such as CONSORT for trials, is to report both an absolute and a relative measure for binary outcomes.

Comparing rates rather than proportions

Surveillance data and cohort studies with unequal follow-up often produce rates, events per unit of person-time, rather than simple proportions. The comparison is then a rate ratio, and its confidence interval is again calculated on the log scale. If \(a\) events occur over person-time \(T_1\) and \(c\) events over \(T_2\), the rate ratio is \((a/T_1)/(c/T_2)\) and the standard error of its logarithm is approximately \(\sqrt{1/a + 1/c}\). Note that only the numbers of events appear in the standard error: the precision of a rate ratio depends on how many events were observed, not on how many people were followed.

Worked problem

Injury rates in two school districts

District A recorded 30 sports injuries requiring medical care over 12,000 student-years of participation; District B recorded 18 over 15,000 student-years. Compare the rates.

Show solution
  1. Rates: 30/12,000 = 2.5 per 1,000 student-years; 18/15,000 = 1.2 per 1,000 student-years.
  2. Rate ratio: 2.5/1.2 = 2.08.
  3. SE of ln rate ratio: \(\sqrt{1/30 + 1/18} = \sqrt{0.0889} = 0.298\).
  4. 95 percent CI: \(2.08 \times e^{\pm 1.96 \times 0.298}\), which is 1.16 to 3.74.

Answer: District A’s injury rate was about twice District B’s (rate ratio 2.08, 95 percent CI 1.16 to 3.74). The wide interval reflects the small number of injuries; before acting, investigators would check whether the districts record injuries in the same way.

Paired binary data: McNemar’s test

When binary outcomes are measured twice on the same people, or in matched pairs, the observations are not independent. McNemar’s test uses only the discordant pairs, those whose outcome changed. If \(b\) people changed from yes to no and \(c\) from no to yes, the test statistic is

\[\chi^2 = \frac{(b - c)^2}{b + c}\]

with 1 degree of freedom. For example, 300 adults were asked before and after a media campaign whether they knew the signs of stroke. Twenty who knew before did not know after, and 52 who did not know before knew after. The statistic is \((20 - 52)^2/(20 + 52) = 1024/72 = 14.2\), far above the critical value of 3.84, so knowledge changed significantly. People whose answers did not change contribute nothing to the test, because they carry no information about the direction of change.

Multiple comparisons

Each test at \(\alpha = 0.05\) carries a 5 percent chance of a false positive when the null is true. Run 20 independent tests on data with no real effects and you expect about one significant result by chance; the probability of at least one is \(1 - 0.95^{20} = 0.64\). This multiple comparisons problem arises when studies examine many outcomes, many subgroups or many time points.

The simplest correction is the Bonferroni method: divide \(\alpha\) by the number of tests. With 10 tests, each is judged against 0.005. Bonferroni is easy but conservative, reducing power. Alternatives include the Holm method and, when many tests are run (as in genetic studies), control of the false discovery rate by the Benjamini-Hochberg procedure. The most important defense, however, is a pre-specified analysis plan that names the primary outcome before the data are seen, so that secondary and subgroup findings are clearly labeled as exploratory.

Sample size for comparing two proportions

Planning a study with a binary outcome requires the expected proportions in each group, the significance level and the desired power. A standard approximation for the number per group is

\[n = \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}\]

where \(\bar{p}\) is the average of \(p_1\) and \(p_2\).

Worked problem

Was the cessation trial big enough?

Suppose investigators had planned to detect an increase in quitting from 0.20 to 0.30 with 80 percent power at α = 0.05 (two-sided). How many smokers per group would they have needed?

Show solution
  1. Average proportion: \(\bar{p} = 0.25\). First term: \(1.96 \times \sqrt{2 \times 0.25 \times 0.75} = 1.96 \times 0.612 = 1.200\).
  2. Second term: \(0.84 \times \sqrt{0.30 \times 0.70 + 0.20 \times 0.80} = 0.84 \times \sqrt{0.37} = 0.84 \times 0.608 = 0.511\).
  3. Numerator: \((1.200 + 0.511)^2 = 1.711^2 = 2.93\).
  4. Denominator: \((0.10)^2 = 0.01\). So \(n = 293\), rounded up to 294 per group.

Answer: About 294 per group. With 200 per group, the trial had only about 64 percent power to detect this difference (Figure 1). It was somewhat fortunate to obtain a significant result, and its effect estimate may be on the high side.

Power plotted against participants per group for two scenarios. For quit proportions of 30 versus 20 in 100, power reaches 0.64 at 200 per group and 0.80 at 294 per group. For a larger difference, 30 versus 15 in 100, power rises much faster and passes 0.80 at about 120 per group.
Figure 1. Power curves for a two-group comparison of proportions. Larger true differences need far fewer participants.

Sample size grows rapidly as the difference to be detected shrinks, roughly in proportion to one over the difference squared. Detecting a change from 0.20 to 0.25 would need about 1,100 per group. This is why trials of preventive interventions with small absolute effects, such as screening programs, often enrol tens of thousands of participants.

Back to the cessation service

Dr. Osei’s brief to the program manager reported that text-message support increased verified quitting by 10 percentage points (95 percent CI 1.6 to 18.4), with about 10 smokers needing support for each additional quitter. She noted that the trial was smaller than ideal and that the true benefit could be modest, but that the intervention was cheap and consistent with larger published trials. The service decided to expand text messaging while continuing to track quit rates, with a plan to compare results against the trial estimate after one year.

Common mistakes

  • MistakeReporting only that a difference in proportions was significant.

    InsteadReport the proportions, an absolute effect (RD or NNT), a relative effect (RR or OR) and their confidence intervals.

  • MistakeInterpreting an odds ratio as a risk ratio when the outcome is common.

    InsteadWith common outcomes the OR overstates the RR; describe it as a ratio of odds or convert it.

  • MistakeCalculating a CI for a ratio as estimate ± 1.96 × SE on the original scale.

    InsteadCalculate on the log scale and exponentiate the limits; ratio CIs are asymmetric.

  • MistakeAnalyzing before-and-after yes/no answers from the same people with a two-sample test.

    InsteadUse McNemar’s test, which uses the discordant pairs.

  • MistakeTesting dozens of subgroups and highlighting the significant ones.

    InsteadPre-specify primary analyses, adjust for multiple comparisons and label subgroup findings as exploratory.

Summary and key terms

  • The one-sample z-test compares an observed proportion with a target; use an exact binomial test for small samples.
  • The two-sample z-test compares proportions using a pooled standard error; it is equivalent to the 2 × 2 chi-square test.
  • The risk difference and number needed to treat express absolute effects; the risk ratio and odds ratio express relative effects.
  • CIs for ratios are calculated on the log scale and are asymmetric; the OR approximates the RR only for rare outcomes.
  • McNemar’s test analyses paired binary data using discordant pairs.
  • Multiple testing inflates false positives; use pre-specified primary outcomes and corrections such as Bonferroni or false discovery rate control.
  • Sample size for comparing proportions grows roughly with the inverse square of the difference to be detected.
Pooled proportion
The overall proportion with the outcome in both groups combined, used in the standard error under the null hypothesis.
Risk difference
The difference between two risks or proportions; an absolute measure of effect.
Number needed to treat
The reciprocal of the risk difference; how many people must receive an intervention for one extra person to benefit.
Risk ratio
The ratio of two risks; a relative measure of effect.
Odds
The probability an event occurs divided by the probability it does not.
Odds ratio
The ratio of the odds of an outcome in two groups.
McNemar’s test
A test for change in paired binary data based on discordant pairs.
Bonferroni correction
Dividing the significance level by the number of tests to control the overall Type I error rate.
False discovery rate
The expected proportion of significant results that are false positives.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. In a sample of 250 adults, 95 had a flu shot. Test whether coverage differs from 0.45 (two-sided).

    Show answer

    p̂ = 0.38; SE = √(0.45 × 0.55/250) = 0.0315; z = −0.07/0.0315 = −2.22; p ≈ 0.026. Coverage is significantly below 0.45.

  2. Influenza-like illness occurred in 30 of 500 vaccinated and 60 of 500 unvaccinated staff. Calculate the RD, RR and NNT.

    Show answer

    Risks 0.06 and 0.12. RD = −0.06 (6 fewer cases per 100); RR = 0.5; NNT (to prevent one case) = 1/0.06 ≈ 17.

  3. For the data in the previous question, calculate the OR and explain why it is close to the RR.

    Show answer

    OR = (30 × 440)/(470 × 60) = 13,200/28,200 = 0.47. It is close to the RR of 0.5 because the outcome is fairly uncommon.

  4. A study tests 15 outcomes at α = 0.05. What Bonferroni-adjusted threshold should each test use?

    Show answer

    0.05/15 = 0.0033.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz