induwara.lk
induwara.lkStatistics · Model comparison

McNemar's Test Calculator

Enter a paired 2×2 table and find out whether two measures on the same subjects — two classifiers, two diagnostic tests, or a before/after change — differ significantly. Chi-square and exact binomial p-values, discordant pairs, and a plain-English verdict. No signup, sources cited.

By Induwara AshinsanaUpdated Jul 11, 2026
McNemar's testpaired 2×2 table
χ² + exact binomial

Enter the four cell counts

Second: yes
Second: no
First: yes
First: no

The two highlighted cells (b and c) are the discordant pairs — the only ones that affect significance.

Examples
Continuity correction
Test method
Significance level α
Two-sided p-value
0.1003
Method: Chi-square (corrected)
Verdict at α = 0.05
Not significant
Discordant pairs (b + c)
30
b = 20, c = 10
Odds ratio (b / c)
2
Discordance favours the first measure

Auto: 30 discordant pairs (≥ 25) → chi-square test.

The numbers behind the result

Chi-square (uncorrected)
3.333 · p = 0.0679
Chi-square (continuity-corrected)
2.700 · p = 0.1003
Exact binomial p-value
0.0987
Marginal proportion — first measure (a + b) / N
55%
Marginal proportion — second measure (a + c) / N
45%
Difference in marginals
10%
Total subjects (N)
100

Formula with your numbers (df = 1)

χ² = (|b − c| − 1)² / (b + c) = (|20 − 10| − 1)² / 30 = 2.700

Sources cited: McNemar (1947) for the χ² on discordant pairs, Edwards (1948) for the continuity correction, and the NIST/SEMATECH e-Handbook for the exact-binomial small-sample rule. Full links below the tool.

How it works

McNemar's test compares two binary measurements taken on the samesubjects. Arrange the paired data as a 2×2 table where each cell counts subjects (or test items): a = both “yes”, b = first “yes” and second “no”, c = first “no” and second “yes”, d = both “no”. Cells b and c are the discordant pairs — the cases where the two measures disagree. Under the null hypothesis that the two measures are equivalent, disagreements should split evenly, so b and c are each expected to be (b + c)/2. Concordant cells a and d carry no information about that split and drop out of the statistic (McNemar, 1947).

The default statistic is the continuity-corrected chi-square (Edwards, 1948):

χ² = (|b − c| − 1)² / (b + c),   df = 1

Turning the correction off gives the original uncorrected form, χ² = (b − c)² / (b + c). Because the reference distribution has one degree of freedom, the two-sided p-value equals 2 · (1 − Φ(√χ²)), where Φ is the standard-normal CDF; we evaluate Φ with a high-accuracy error-function approximation, no external library (NIST/SEMATECH handbook).

When the number of discordant pairs is small the chi-square approximation is unreliable, so for b + c < 25 the calculator switches to the exact binomial test. It treats the b vs c split as n = b + c coin flips with p = 0.5 and sums the two tails:

p = 2 · Σi=0…min(b,c) C(b + c, i) · 0.5(b + c), capped at 1.0

The binomial probabilities are built up multiplicatively so the coefficients never overflow, even for large counts. If b + c = 0 there are no disagreements and the test is undefined; the tool says so instead of dividing by zero. Alongside the p-value it reports the odds ratio b / c (which direction the disagreements favour), the marginal proportions (a + b)/N and (a + c)/N, and the total sample size N for interpretation. The corrected chi-square here matches R's mcnemar.test and the exact test matches statsmodels' mcnemar(exact=True).

Worked examples

Two diagnostic tests (chi-square, corrected)

Same 100 patients, two tests: a = 35, b = 20, c = 10, d = 35. Discordant = 30 (≥ 25 → chi-square).

  1. χ² = (|20 − 10| − 1)² / (20 + 10)
  2. = (10 − 1)² / 30 = 81 / 30 = 2.700 (df = 1)
  3. p = 2 · (1 − Φ(√2.700)) = 2 · (1 − Φ(1.643))
  4. = 2 · (1 − 0.9498) = 0.1004
  5. At α = 0.05 → not significant. Odds ratio b/c = 2.0.

Two classifiers (exact binomial, small sample)

Same test set, only-A-correct b = 8, only-B-correct c = 1 (a and d large but irrelevant). Discordant = 9 (< 25 → exact).

  1. p = 2 · Σ_{i=0}^{1} C(9, i) · 0.5⁹
  2. = 2 · (C(9,0) + C(9,1)) / 512
  3. = 2 · (1 + 9) / 512 = 20 / 512 = 0.0391
  4. At α = 0.05 → significant — A's edge is unlikely to be chance.
  5. Cross-check corrected χ² = (|8 − 1| − 1)² / 9 = 36 / 9 = 4.000 → p = 0.0455 (also significant).

No difference / continuity-correction quirk (edge case)

A before/after study that changed nobody's mind on balance: a = 10, b = 15, c = 15, d = 10. Discordant = 30 (≥ 25 → chi-square).

  1. Uncorrected χ² = (15 − 15)² / 30 = 0 → p = 1.0000
  2. Corrected χ² = (|0| − 1)² / 30 = 1 / 30 = 0.0333
  3. p = 2 · (1 − Φ(0.1826)) = 2 · (1 − 0.5724) = 0.8551
  4. At α = 0.05 → not significant. Odds ratio b/c = 1.0.
  5. The correction never pushes p exactly to 1 when b = c — expected, and why the exact test is cleaner for tiny samples.

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.