Understanding the McNemar's test calculator — concept and principle
This calculator runs McNemar's test on a paired 2 × 2 table, for example the same people answering yes or no before and after a campaign, or two diagnostic tests on the same patients. It gives the χ² statistic and p-value, the continuity-corrected version, the exact binomial p-value, the number of discordant pairs and the yes-proportions at both times, and says which p-value to use.
How it is calculated
χ² = (b − c)² ÷ (b + c), compared with the chi-square distribution with 1 degree of freedom
With continuity correction: (|b − c| − 1)² ÷ (b + c)
Exact version: b is binomial with n = b + c and p = 0.5
- a = yes/yes, b = yes→no, c = no→yes, d = no/no.
- Proportion yes first = (a + b) ÷ N; second = (a + c) ÷ N.
- When b + c > 20 the χ² p-value is fine; for smaller counts use the exact binomial p-value.
The principle
In paired data, people who answered the same way both times (a and d) say nothing about change. Only the discordant pairs matter: b changed from yes to no and c from no to yes. If nothing changed systematically, a discordant pair is equally likely to be of either kind, like a fair coin, so b and c should be about equal. The test measures how lopsided the split between b and c is.
Worked example
Default inputs: a = 45, b = 18, c = 6, d = 31 (N = 100).
- Proportion yes at first = (45 + 18) ÷ 100 = 63 %; at second = (45 + 6) ÷ 100 = 51 %.
- Discordant pairs b + c = 24.
- χ² = (18 − 6)² ÷ 24 = 144 ÷ 24 = 6, p = 0.01431.
- With continuity correction: (12 − 1)² ÷ 24 = 5.042, p = 0.02474; exact binomial p = 0.02266.
- Which p-value to use: b + c > 20: the χ² p-value is fine.
How to read the result
All three p-values are below 0.05, so the drop from 63 % to 51 % yes is unlikely to be chance alone. The direction comes from b and c: 18 people switched from yes to no and only 6 the other way. Report the change in proportions with a confidence interval alongside the p-value.
Common mistakes
- Using an ordinary chi-square test of independence on paired data.
- Including a and d in the test statistic.
- Swapping b and c, which flips the direction of change.
- Using the χ² approximation when b + c is small.
Frequently asked questions
When is McNemar's test used?
For paired yes/no data, such as before-and-after measurements on the same people.
Why are only b and c used?
Pairs that answered the same way both times carry no information about change.
When should I use the exact p-value?
When the number of discordant pairs b + c is small, typically 20 or fewer.
Sources: NIST Dataplot Reference Manual, "McNEMAR TEST" · W. J. Conover (1999), Practical Nonparametric Statistics, 3rd ed., Wiley