Test whether a yes/no outcome changed for the same people measured twice, such as before and after treatment, with exact and chi-square p-values.
χ² = (b − c)² ÷ (b + c)
| After: yes | After: no | |
|---|---|---|
| Before: yes | ||
| Before: no |
Count each person once, in the box for their before-and-after pair. Only the two "changed" boxes, b and c, drive the test.
McNemar's test checks whether a yes/no outcome changed when the same people are measured twice. It's the paired-data counterpart of the chi-square test, just as the paired t-test is for averages.
People who answered the same both times tell you nothing about change, so the test ignores them. It focuses on the two kinds of switchers: yes-to-no and no-to-yes. With no real change those should be about equal.
It suits before-and-after studies, comparing two diagnostic tests on the same patients, and matched case–control pairs.
As given by McNemar (1947) and Agresti, Categorical Data Analysis, section 11.1. See Sources.
Under no change, each switcher is equally likely to go either way, like a coin flip.
The symptom rate fell from 55% to 45%, and three times as many patients lost it as gained it: a significant improvement at the 5% level.
For different numbers of switchers split 3 to 1, showing how the versions converge as counts grow.
| b, c | Exact | Corrected χ² | Plain χ² |
|---|---|---|---|
| 6, 2 | 0.2891 | 0.2888 | 0.1573 |
| 15, 5 | 0.0414 | 0.0442 | 0.0253 |
| 30, 10 | 0.0022 | 0.0027 | 0.0016 |
| 75, 25 | 5.64e-7 | 9.58e-7 | 5.73e-7 |
The exact one is always valid and is preferred when fewer than about 25 people changed. With many switchers, all three versions agree closely.
Someone who answered “yes” both times gives no information about whether the treatment changes answers. Only switchers do.
Subtracting 1 from |b − c| makes the chi-square approximation closer to the exact test for small counts, at the cost of being slightly conservative.
Yes. Rows are test A positive/negative, columns test B positive/negative, on the same patients.
The Stuart–Maxwell test extends McNemar’s test to paired tables larger than 2 × 2.
The exact version is a sign test on the switchers: each change is a “+” or “−”.
mcnemar.test(matrix(c(40, 15, 5, 40), nrow = 2)) gives the corrected chi-square version.
Quinn McNemar, an American psychologist and statistician, who published the test in 1947.
Related Tools