McNemar's test

Statistics
Introduced by
Quinn McNemar
Year
1947
Type
Nonparametric test for paired binary data

What does it do?

McNemar's test is a nonparametric hypothesis test for two paired binary measurements, such as a yes/no response recorded on the same subjects before and after an intervention.

Quinn McNemar introduced it in 1947, and it works on the 2×2 table of matched outcomes, using only the pairs whose classification changed.

The intuition behind the method

When the same people are measured twice — for example a symptom recorded as present or absent before and after treatment — the two measurements are not independent, so an ordinary chi-square test of association is wrong. McNemar's test ignores the people who did not change and looks only at the discordant pairs: those who switched from no to yes versus those who switched from yes to no. If a real change occurred, these two switch counts should be markedly unequal.

History

Quinn McNemar published the test in 1947 in Psychometrika, in a note on the sampling error of the difference between correlated proportions or percentages. The note presents two formulas and points out the chi-square equivalent of one of them. For three or more repeated binary measurements on the same subjects, the approach is generalized by Cochran's Q test.

When to use it

Choose it when each subject contributes two related yes/no observations, for example a response recorded before and after an intervention, or a matched pair in a case-control design, and the question is whether the proportion of positive responses changed between the two conditions. Do not use it for independent samples, where an ordinary chi-square test of association applies. Do not use it for three or more repeated conditions, where Cochran's Q test is the relevant extension. When the discordant total b + c is small, use the exact binomial version rather than the chi-square approximation.

Limitations and considerations

  • Applies only to two conditions and a dichotomous outcome in a single 2×2 table.
  • The chi-square version is unreliable when b + c is small, so the exact form is needed in that case.
  • Concordant pairs (a and d) do not enter the statistic, so subjects whose response did not change contribute nothing to the test, although they still count toward the sample.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Respects the paired structure: it tests change within subjects, which an ordinary chi-square test of association would wrongly treat as independent samples.
  • Needs only the two discordant cell counts b and c to compute the statistic.
  • Has an exact binomial form, so the test remains usable when few pairs switch.

Applications

  • Comparing a binary symptom or response before and after a treatment in the same patients.
  • Matched case-control studies where each case is paired with a control on a yes/no exposure.
  • Measuring whether an intervention changes a pass/fail or agree/disagree response in the same respondents.
  • Assessing whether two diagnostic tests applied to the same subjects differ in their positive/negative classifications.

How it works

How it works

1

The null hypothesis states that the two discordant cell probabilities are equal, p_b = p_c, where p_b and p_c are the probabilities of the two off-diagonal cells b and c in the 2×2 table of matched outcomes. Under this null, the proportion responding positively is unchanged across the two conditions. The alternative, p_b ≠ p_c, indicates a genuine shift.

Formula
H_0:\ p_b = p_c \quad H_1:\ p_b \neq p_c
2

The 2×2 table has concordant cells a and d, where the two measurements agree, and discordant cells b and c, where they disagree. Only b and c enter the statistic, because they alone carry information about change. The statistic squares the difference between the two discordant counts and divides by their sum; under the null hypothesis it is referred to a chi-square distribution with one degree of freedom. The formula shown is the uncorrected form. Conditional on the discordant total b + c, the null hypothesis implies that b follows a Binomial(b + c, 0.5) distribution, so the exact version of the test is a two-sided binomial test of b against that distribution. This exact form does not rely on the large-sample chi-square approximation. It is advisable when the discordant total is small, because the chi-square approximation is then less reliable.

Formula
\chi^2 = \dfrac{(b - c)^2}{b + c} \sim \chi^2_{1}
3

If the p-value falls below 0.05, the null hypothesis is rejected, indicating a change between the two conditions. The 0.05 level is a conventional significance threshold, and the user should choose the level appropriate to the study. As written, the test is two-sided, since the alternative is p_b ≠ p_c. The ratio b/c can be read as an odds ratio describing the direction and size of the shift.

Formula
\text{reject } H_0 \text{ if } p < 0.05

Common pitfalls

  • Applying a standard chi-square test of association to paired observations, which assumes an independence the design does not have.
  • Relying on the asymptotic chi-square form when the discordant total is small, instead of using the exact binomial version.
  • Reading a non-significant result as evidence of no change when very few pairs switched, since the test has little information in that situation.
  • Trying to use it for three or more conditions; Cochran's Q test is the correct extension.

Frequently asked questions

How is this different from a regular chi-square test?

The ordinary chi-square test assumes the two samples are independent. McNemar's test is built for paired data, where the same subjects are measured twice, and it focuses only on the discordant pairs, so it accounts for the correlation that the standard test would wrongly ignore.

What if I have very few discordant pairs?

When b + c is small, the chi-square approximation is unreliable. Use the exact binomial version of the test instead, which conditions on the discordant total and does not rely on the large-sample approximation.

What about three or more conditions?

McNemar's test handles exactly two paired conditions. For three or more repeated binary measurements on the same subjects, use Cochran's Q test, which is the direct multi-condition extension.

Can I report an effect size?

Yes. The odds ratio b/c summarizes the direction and magnitude of the shift between the two discordant cells. The test itself does not produce a confidence interval; if one is needed, it should be computed with a method suited to matched pairs and named explicitly in the report.

Related methods

Sources

  1. McNemar, Q. (1947). Note on the sampling error of the difference between correlated proportions or percentages. Psychometrika, 12(2), 153–157.

    Open DOI reference