McNemar's test
Shown in the app as mcnemar. Part of the method reference, under Association and correlation.
When to use
Two paired binary measurements on the SAME subjects (e.g. before/after, two raters on one occasion): tests whether the proportion changes.
What you provide
- The two paired categorical variables: two categorical columns.
Options
Missing data
- Complete case (listwise deletion)
Multiple comparisons
- Not adjustable for this method. Where it makes post-hoc comparisons, the procedure applies its own correction.
Confidence level
Every interval in the result is reported at the level you choose:
- 90%
- 95%
- 99%
Related methods
Other methods under Association and correlation:
Guides that discuss this method
- Chi-square or Fisher's exact test: which to use?
- How to choose a statistical test for your data
- McNemar's test for paired proportions
How to read the output
McNemar’s test compares two yes/no measurements taken on the same units, for example whether the same respondents approved of a policy in two surveys, or whether the same field plots were infested before and after a treatment. Both columns must hold the same two categories.
What it tests. Only the units that changed carry information about change: those that went from the first category to the second, and those that went the other way. The test asks whether those two counts differ by more than chance would allow. A small p-value means change in one direction was more common than change in the other. Units that stayed the same do not enter the test. The p-value includes Edwards’ continuity correction (R’s default), and the Methods text says so.
How large the change is. The effect size is the odds ratio of the two kinds of change: the number that changed one way divided by the number that changed the other way. It comes with an exact confidence interval computed from those changed units alone (a Clopper-Pearson interval for the share of changes in one direction, converted to the odds-ratio scale). When nobody changed in one direction, the odds ratio has no finite value and its interval has no upper bound; when nobody changed at all, it cannot be estimated.
Options. The confidence level can be 90%, 95% (the default) or 99%. The test is two-sided.
Missing values. A unit with either measurement missing is left out (complete-case analysis); filling a missing category with a mean or median would invent a category that was never observed.
Level order. The two columns are lined up by category before counting, so a different category order in the two columns cannot pair the wrong cells.
Sources: McNemar Q (1947), Psychometrika 12(2):153-157, doi:10.1007/BF02295996. Clopper CJ, Pearson ES (1934), Biometrika 26(4):404-413, doi:10.1093/biomet/26.4.404.
Worked examples
Celeus's result on a published or illustrative dataset, next to an independent computation and, where one exists, a published value. The data themselves are not reproduced here.
synthetic fixture from the McNemar's test Wikipedia worked example
- Source: Illustrative or synthetic example data
- Licence: text CC BY-SA 4.0 (Wikipedia); the 2x2 counts are an illustrative textbook-style table, not real patient data
- Reference: Wikipedia contributors, "McNemar's test" (worked example: n=314 patients, disease diagnosis before/after a drug), retrieved 2026-07-13
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Test statistic | 20.6722 | 20.6722 | - | Yes |
| p-value | 5.45009e-06 | 5.45009e-06 | - | Yes |
HSAUR::respiratory (baseline vs month-4 status)
- Source: Published dataset distributed with an R package
- Licence: HSAUR (GPL-2 | GPL-3)
- Reference: Davis (1991), Statistics in Medicine 10:1959-1980
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Test statistic | 1.93939 | 1.93939 | - | Yes |
| p-value | 0.163734 | 0.163734 | - | Yes |
Agresti (1990) presidential approval in two surveys, as printed in R's ?mcnemar.test
- Source: Values entered from a table in the cited publication
- Licence: base R (GPL)
- Reference: Agresti (1990), Categorical Data Analysis, p. 350, as printed in R's ?mcnemar.test
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Test statistic | 16.8178 | 16.8178 | - | Yes |
| Degrees of freedom | 1 | 1 | - | Yes |
| p-value | 4.11456e-05 | 4.11456e-05 | - | Yes |
| Effect size | 0.573333 | 0.573333 | - | Yes |
| Effect size confidence interval | 0.434598, 0.752316 | 0.434598, 0.752316 | - | Yes |
Agresti (1990) presidential approval in two surveys, as printed in R's ?mcnemar.test
- Source: Values entered from a table in the cited publication
- Licence: base R (GPL)
- Reference: Agresti (1990), Categorical Data Analysis, p. 350, as printed in R's ?mcnemar.test
| Quantity | Celeus | Independent computation | Published value | Agrees |
|---|---|---|---|---|
| Effect size confidence interval | 0.454029, 0.721548 | 0.454029, 0.721548 | - | Yes |
References
- McNemar, Q. (1947). Note on the sampling error of the difference between correlated proportions or percentages. Psychometrika 12: 153-157. doi:10.1007/BF02295996 doi:10.1007/BF02295996