McNemar test calculator

Enter the four counts of a paired 2 × 2 table to test whether a yes/no outcome changed between two occasions or differs between matched pairs, with the exact p-value and the size of the change.

No accountInstant resultsExact and mid-p

Enter the paired counts

Each pair is one person measured twice, or two matched people, with a yes/no outcome.

PAIRED 2 × 2 TABLE

LIVE RESULT

INSTANT

McNemar's test

Enter pairs, not people: a participant measured before and after counts once, in the cell for their two answers.

When to use McNemar's test

McNemar's test compares two proportions measured on the same people, or on matched pairs: the share passing before and after training, the share preferring product A before and after an advert, or the agreement of two diagnostic tests on the same patients. Because the two proportions come from the same pairs, they are not independent, and the ordinary chi-square or two-proportion test is wrong.

Only the pairs that changed carry information about the difference. Pairs that gave the same answer twice (cells a and d) count towards the sample size but not towards the test.

Before: (a + b) ÷ n; after: (a + c) ÷ n; difference = (c − b) ÷ n
χ² = (b − c)² ÷ (b + c), 1 df; with Edwards' correction (|b − c| − 1)² ÷ (b + c)
Exact test: b is binomial with b + c trials and probability ½
Conditional odds ratio = b ÷ c

The exact binomial version is preferred when there are fewer than about 25 discordant pairs, and it is never wrong to report it. The mid-p version is less conservative and keeps close to the nominal error rate. Results match the mcnemar function in Python's statsmodels.

Worked example

Before a training course, 42 of 66 staff passed a skills check (63.6%); afterwards, 34 did (51.5%). Twelve people who passed before failed afterwards (b) and four who failed before passed afterwards (c). McNemar's χ²(1) = 4.00, p = .046, but with only 16 discordant pairs the exact test is the right choice: p = .077. The data suggest a drop, but are not conclusive at the .05 level.

Treating the two occasions as independent samples gives a different answer: a two-proportion z test on 42 of 66 against 34 of 66 gives p = .159. Ignoring the pairing overstates the uncertainty: people who answered the same way twice cancel out in McNemar's test, so it is usually more powerful than treating the two occasions as separate samples.

Reading and reporting

  • Report both proportions and the change, with its confidence interval, along with the test: “the pass rate fell from 63.6% to 51.5%, a difference of −12.1 points, exact McNemar p = .077”.
  • Direction. The difference shown is after minus before, so a negative value is a decrease.
  • Interval and test can disagree. The confidence interval for the change is a Wald interval and matches the uncorrected χ² test, not the exact test. In the example it just excludes zero while the exact p is .077; with few discordant pairs, base the conclusion on the exact test.
  • More than two occasions or conditions. Use Cochran's Q test, and McNemar's test for pairwise follow-ups with a multiple comparisons correction.
  • Agreement rather than change. To measure how well two raters or tests agree, rather than whether their rates differ, use Cohen's kappa.

For two independent groups, use the two proportions calculator instead.