McNemar test calculator for paired proportions
Test whether a paired yes/no result changed from a 2×2 table of matched outcomes: exact, mid-p and chi-square McNemar p-values, the discordant odds ratio and an interval for the difference.
A clear answer. Here’s how.
The table of n matched pairs has a = positive on both measurements, b = positive first and negative second, c = negative first and positive second, d = negative on both. Under the null hypothesis that the two proportions are equal, a discordant pair is equally likely to be of either kind, so b ~ Binomial(b + c, ½). The exact test gives p = min(1, 2 × P(X ≤ min(b, c))); the mid-p version counts only half of the probability of the observed split, p = min(1, 2 × (P(X ≤ m) − ½ P(X = m))), which is less conservative (Lancaster 1961; Fagerland, Lydersen and Laake 2013 recommend it over the exact test). The chi-square statistic is (b − c)² ÷ (b + c) on 1 degree of freedom, and the continuity-corrected one is (|b − c| − 1)² ÷ (b + c), as R’s mcnemar.test computes it (no correction when b = c). The odds ratio of discordant pairs is b ÷ c, with the exact conditional interval of R’s exact2x2::mcnemar.exact: the Clopper–Pearson limits for b out of b + c, turned into odds p ÷ (1 − p). The difference between the two paired proportions is (b − c) ÷ n; its interval is Newcombe’s (1998) method 10, which combines the Wilson score limits of the two marginal proportions through their correlation φ = (ad − bc) ÷ √((a + b)(c + d)(a + c)(b + d)) with n ÷ 2 taken off the numerator when it is positive, and, for comparison, the Wald interval with SE = √(b + c − (b − c)² ÷ n) ÷ n. The tests use only the discordant pairs, so a table with fewer than about 25 of them (a common rule of thumb) should be read from the exact or mid-p value, and with none (b + c = 0) no test is possible. It assumes independent pairs and a two-category outcome; it does not handle more than two categories (Bowker’s test), more than two measurements (Cochran’s Q), clustered pairs or covariates. It is a calculator, not a substitute for a statistician when decisions depend on the answer.
How this is checked
5 reference checks passed These 5 cases were run when this page was built, on 20 October 2026, and all reproduce within the stated tolerance. The same cases are part of the automated tests that run on every change to Toolmoz. Engine version 1.
See the checks and where each expected answer comes from
Case 1
- Inputs
- The tool’s default inputs
- Expected, and what Toolmoz gave
- Pairs (n) expected 161, Toolmoz 161Discordant pairs (b + c) expected 22, Toolmoz 22Exact McNemar p-value (two-sided) expected 0.053, Toolmoz 0.05247879028320293Mid-p McNemar p-value (two-sided) expected 0.035, Toolmoz 0.0346896648406981McNemar chi-square (no correction) expected 4.55, Toolmoz 4.545454545454546P-value, chi-square (no correction) expected 0.033, Toolmoz 0.033006257661231685McNemar chi-square with continuity correction expected 3.68, Toolmoz 3.6818181818181817P-value, chi-square with continuity correction expected 0.055, Toolmoz 0.05500883362926435
- Where the expected answer comes from
- Wikipedia’s McNemar worked example with 161 subjects (59, 6, 16, 80) prints exact p = 0.053, corrected chi-square 3.68 with p = 0.055, uncorrected 4.55 with p = 0.033 and mid-p 0.035; by hand (16 − 6)² ÷ 22 = 100/22 = 4.545 and 9² ÷ 22 = 3.682. The published values are rounded to 2 or 3 decimals, hence the tolerance
- Allowed difference
- ±0.006
Case 2
- Inputs
- Positive both times (a) 101Positive first, negative second (b) 121Negative first, positive second (c) 59Negative both times (d) 33
- Expected, and what Toolmoz gave
- Pairs (n) expected 314, Toolmoz 314McNemar chi-square (no correction) expected 21.35, Toolmoz 21.355555555555554
- Where the expected answer comes from
- Wikipedia’s first McNemar example (101, 121, 59, 33): chi-square = (121 − 59)² ÷ (121 + 59) = 3844/180 = 21.356, printed there as 21.35 with p below 0.001
- Allowed difference
- ±0.01
Case 3
- Inputs
- Positive both times (a) 20Positive first, negative second (b) 12Negative first, positive second (c) 2Negative both times (d) 16
- Expected, and what Toolmoz gave
- Difference in proportions, first minus second expected 20, Toolmoz 20Exact McNemar p-value (two-sided) expected 0.0129, Toolmoz 0.012939453125000019Mid-p McNemar p-value (two-sided) expected 0.0074, Toolmoz 0.00738525390625001395% CI lower limit, difference (Newcombe) expected 5.6156, Toolmoz 5.61564248417492695% CI upper limit, difference (Newcombe) expected 32.9207, Toolmoz 32.92069954001398
- Where the expected answer comes from
- StatsDirect’s paired-proportions page, from Armitage and Berry (1994, p. 138): 50 sputum specimens on two media, difference 0.2, exact two-sided P 0.0129, mid P 0.0074 and score-based (Newcombe) 95% interval 0.056156 to 0.329207; by hand 2 × (1 + 14 + 91) ÷ 2^14 = 212/16384 = 0.012939 and (212 − 91) ÷ 2^14 = 0.007385, and Newcombe (1998) Table III prints 0.0562 to 0.3292 for the same counts
- Allowed difference
- ±0.00006
Case 4
- Inputs
- Positive both times (a) 35Positive first, negative second (b) 14Negative first, positive second (c) 0Negative both times (d) 1
- Expected, and what Toolmoz gave
- 95% CI lower limit, difference (Newcombe) expected 14.61, Toolmoz 14.60739058646340395% CI upper limit, difference (Newcombe) expected 41.75, Toolmoz 41.746247415539315Exact McNemar p-value (two-sided) expected 0.0001220703125, Toolmoz 0.0001220703125000002
- Where the expected answer comes from
- Newcombe (1998) Table III, row e = 35, f = 14, g = 0, h = 1 (n = 50): method 10 gives 0.1461 to 0.4175 (method 8 without the correction gives 0.1573 to 0.4149); c = 0 so the exact p is 2 × (½)^14 = 2/16384
- Allowed difference
- ±0.006
Case 5
- Inputs
- Positive both times (a) 794Positive first, negative second (b) 150Negative first, positive second (c) 86Negative both times (d) 570
- Expected, and what Toolmoz gave
- McNemar chi-square (no correction) expected 17.35593220338983, Toolmoz 17.35593220338983McNemar chi-square with continuity correction expected 16.81779661016949, Toolmoz 16.81779661016949P-value, chi-square (no correction) expected 0.00003099293441045219, Toolmoz 0.000030992934410451986Difference in proportions, first minus second expected 4, Toolmoz 495% CI lower limit, difference (Wald) expected 2.1283883249668336, Toolmoz 2.12838832496684695% CI upper limit, difference (Wald) expected 5.871611675033167, Toolmoz 5.871611675033154
- Where the expected answer comes from
- Agresti’s presidential approval table (1600 voters, R’s mcnemar.test example): b = 150, c = 86, so chi-square = 64² ÷ 236 = 4096/236 = 17.356 and (64 − 1)² ÷ 236 = 3969/236 = 16.818; the p-value is erfc(√(17.356 ÷ 2)) from an independent Python script; difference (150 − 86) ÷ 1600 = 0.04 with SE √(236 − 64²/1600) ÷ 1600 = √233.44 ÷ 1600 = 0.0095492, so the Wald limits are 0.04 ± 1.959964 × 0.0095492
- Allowed difference
- ±1e-9 relative
What this shows: the engine reproduces independently worked values for these cases. It does not prove every possible input is right. To test an answer you were given, see how to check a number; to see what is and is not checked across Toolmoz, see the accuracy ledger.
See a worked example
Worked example
A fixed demonstration, separate from the values you enter above.
- The pairs are
- Before and after (the same subjects measured twice)
- Positive both times (a)
- 59
- Positive first, negative second (b)
- 6
- Negative first, positive second (c)
- 16
- Negative both times (d)
- 80
- Confidence level
- 95%
Example result
| Measure | Value | 95% CI lower | 95% CI upper | P-value | Method |
|---|---|---|---|---|---|
| Exact McNemar test (binomial, two-sided) | b = 6 of 22 discordant pairs | 0.05248 | Twice the smaller binomial tail with p = 0.5, at most 1 | ||
| Mid-p exact test (two-sided) | 0.03469 | Counts half the probability of the observed split | |||
| Chi-square, no correction | χ² = 4.5455, df 1 | 0.03301 | (b − c)² ÷ (b + c) | ||
| Chi-square, continuity correction | χ² = 3.6818, df 1 | 0.05501 | (|b − c| − 1)² ÷ (b + c), as R’s mcnemar.test | ||
| Odds ratio of discordant pairs (b ÷ c) | 0.375 | 0.1202 | 1.009 | Exact: Clopper–Pearson limits for b of b + c, turned into odds |
Layout: rows are the first measurement (Before), columns the second (After): a = positive both times, b = positive first and negative second, c = negative first and positive second, d = negative both times. McNemar’s test uses only the discordant pairs b and c, because pairs that gave the same answer twice say nothing about whether the proportion changed. Only 22 pairs are discordant, so the chi-square approximation is unreliable: use the exact or mid-p value (the exact value is conservative; mid-p is closer to the nominal level). Intervals are 95%. The Wald interval is shown for comparison and is unreliable when b + c is small or the difference is large; Newcombe’s is preferred. The test assumes each pair is independent of the others and says whether the proportion changed, not why.