McNemar’s Test Calculator
Before and after. Treated and untreated, in the same patients. Two raters judging the same items. Whenever binary outcomes come in pairs, the ordinary chi-square test is the wrong instrument — it cannot see the pairing — and McNemar’s test is the right one. It looks only at the pairs that changed: enter the count that switched one way (b) and the count that switched the other (c), and this calculator returns the chi-square statistic with continuity correction, its p-value, and the exact binomial p-value that needs no approximation at all. Two numbers in, a verdict with its evidence itemised — the test Fisher would have designed if the tea lady had been measured twice.
Why Only the Changers Count
The logic is a small masterpiece of discarding. Lay the pairs in their 2×2: yes→yes (call it a), yes→no (b), no→yes (c), no→no (d). The concordant pairs, a and d, look identical before and after — they testify that something persisted, but about the question “did the balance of change favour one direction?” they are silent witnesses. Under the null hypothesis of no systematic change, a pair that changes should be equally likely to change either way: the discordant pairs are coin flips, and b should hover near c near (b+c)/2. McNemar’s statistic measures the imbalance, χ² = (|b − c| − 1)² / (b + c) with the −1 a continuity correction for approximating a discrete count by a continuous curve, on 1 degree of freedom. And because the null is literally a fair coin over n = b + c flips, the exact p-value is a binomial tail — the calculator computes both, and their agreement (or instructive disagreement at small n) is printed side by side.
Worked Example: Twenty-Five Against Eight
The defaults describe a treatment evaluated before-and-after: 25 patients switched from symptom to no symptom, 8 switched the other way — with, say, 60 stable pairs completing a study of 93 (the stable pairs, remember, do not enter the arithmetic). Discordant total n = 33; imbalance |25 − 8| = 17, corrected to 16; χ² = 16²/33 = 7.758, whose chi-square p-value is 0.0053. The exact computation — the probability that a fair coin flipped 33 times lands 25 or more on one side, doubled — gives p = 0.0046. Two methods within a hair of each other at this n, both far below any conventional threshold: the switches ran one way, 3-to-1, and chance is a poor explanation. Contrast the uncorrected instinct a paired design protects against: run the same margins through an ordinary chi-square as if the befores and afters were strangers, and the pairing’s information — that these were the same patients — evaporates, typically diluting a real effect into the noise floor.
The Design Family This Test Serves
McNemar’s is the binary member of the paired family, and recognising the family resemblance prevents a shelf of errors. Paired continuous outcomes take the paired t-test (or its rank cousin, Wilcoxon’s signed-rank); paired ordinal outcomes, the signed-rank again; paired binary outcomes measured at three or more times take Cochran’s Q, McNemar’s direct generalisation; and two related-but-independent proportions take Fisher or chi-square, the unpaired instruments of the neighbouring item. The diagnostic question is always the same: are these two columns the same units measured twice? Marketing panels (same households, two campaigns), diagnostic comparisons (same patients, two tests), matched case–control studies (each case yoked to a control) and inter-rater studies (same films, two radiologists) all answer yes, and for all of them a test that ignores the yoking is not merely weaker — it answers a question nobody asked, about populations of strangers.
Reporting and the Discordant Fraction
Two reporting disciplines belong with the statistic. First, report the discordant counts themselves — b and c, not merely the p: a reader given “25 against 8, p = .005” can audit the test from the sentence, and can also see what a bare p conceals, that the evidence rests on 33 informative pairs regardless of how large the study’s headline N parades. Second, mind the effective sample size when designing: a paired study’s power lives entirely in its discordant fraction, so a treatment expected to move few pairs needs a large cohort to harvest enough switchers — power calculations for McNemar designs are done on the expected b + c, not on enrolment. The calculator’s indifference to a and d is thus the design’s central fact wearing arithmetic dress: recruit for changers, analyse the changers, report the changers.
A Smaller Split, An Honest Non-Verdict
Contrast disciplines the intuition: run b = 9 against c = 2 — a 4.5-to-1 split that feels decisive. The discordant total is only 11: χ² = (7 − 1)²/11 = 36/11 ≈ 3.27, p ≈ 0.070; the exact binomial — a fair coin landing 9 or more of 11 on one side, doubled — is 134/2048 ≈ 0.065. Both methods, at this size, withhold conviction: nine-and-two is the kind of split chance produces one time in fifteen, and the test’s refusal is information, not timidity. Place the two examples side by side — 25:8 convicts, 9:2 does not — and the real variable announces itself: not the ratio of the split but the count of discordant pairs behind it. Ratios impress; counts convict — in paired designs above all, where the pairs are the sample.
The Percentages the Test Is Quietly Judging
Anchor the worked example in its full table to see what McNemar adjudicates. Complete the 93 patients as a = 40 (symptom both times), d = 20 (clear both times), with b = 25 and c = 8: the symptom rate before is (40 + 25)/93 ≈ 69.9%, and after is (40 + 8)/93 ≈ 51.6% — an 18-point improvement whose entire evidential weight rides on the 33 switchers, exactly as the test’s design says. Report those marginals beside the p-value and the reader sees both the clinical size of the change and the count of patients who actually changed; report the p alone and the second fact — the one a clinician acts on — has been computed and then thrown away by the author on the reader’s behalf.
Related Tools
More from the Statistics Calculators hub: the Fisher’s Exact Test Calculator for the unpaired 2×2, the t-statistic Calculator for paired continuous outcomes’ parametric cousin, and the Critical Value Calculator for the chi-square thresholds this statistic is judged against.
Frequently Asked Questions
Why can’t I just use a chi-square test on the 2×2 table?
Because the ordinary chi-square assumes every cell count comes from an independent observation. In paired data the two measurements on one subject are correlated — often strongly — and the independence assumption understates or overstates the evidence unpredictably. McNemar’s restructure (discard the concordant pairs, test the discordant split against a fair coin) is precisely the correction that restores validity; the two tests on the same table can and do reach opposite conclusions, and when they do, McNemar’s is the one answering the paired question.
Which p-value should I report, chi-square or exact?
The exact binomial p whenever b + c is small (the usual guidance: below about 25 discordant pairs, and it costs nothing at any size this side of the thousands), and either when the discordant count is large, where they agree to the precision anyone reports. State which you used. The continuity-corrected chi-square printed here is the classical textbook statistic; some software drops the correction, which is the commonest reason two packages quote slightly different p-values for the same table.
What if b + c is zero?
Then nothing changed in either direction and there is no evidence to weigh — the calculator says so rather than dividing by zero. Substantively, a study with zero discordant pairs is either a triumph of stability or a measurement that could not register change, and the report should say which; statistically the file is closed, and honestly so.
Can McNemar handle more than two outcome categories?
Not directly — the test is intrinsically binary. The extensions exist and have names: the McNemar–Bowker test examines symmetry in a square table of paired categories (did switches between every pair of categories balance?), and Stuart–Maxwell tests marginal homogeneity. Collapsing categories to binary to appease McNemar discards structure the extensions keep; choose by the question, and if the binary collapse is the question (improved versus not), McNemar remains exactly right.
Does the test work for matched case–control studies?
Yes — that is one of its ancestral homes. Each matched pair (case, control) is classified by exposure: pairs where the case was exposed and the control not are one discordant type; the reverse pattern is the other; McNemar’s machinery then tests whether exposure associates with case status, with the matched odds ratio estimated simply as b/c — 25/8 ≈ 3.1 in the worked example’s shape. The concordant pairs, once again, inform the design’s cost but not its verdict.
What sample size do I need?
Plan in discordant pairs: the test’s power is governed by how many pairs will change and how lopsided the change will be. As a scale sense, detecting a 3:1 split needs only a few dozen discordant pairs (the worked example convicts at 33), while a 3:2 split needs several hundred — and the cohort must be inflated by the expected rate of changing at all. Pilot the discordant fraction before promising the funder a number; enrolment is the budget, but switchers are the evidence.