McNemar Test Calculator for Paired 2x2 Tables

McNemar Test Calculator for Paired 2x2 Tables

Emerging AI Skill PRO

Enter Calculation

Formula

T1′=(|b: X=0, Y=1−c: X=1, Y=0|−1)2b: X=0, Y=1+c: X=1, Y=0T_1^{\prime}=\frac{(|\text{b: X=0, Y=1}-\text{c: X=1, Y=0}|-1)^2}{\text{b: X=0, Y=1}+\text{c: X=1, Y=0}}
Show calculation steps (1)
  1. Chi-square statistic

    T1=(b: X=0, Y=1−c: X=1, Y=0)2b: X=0, Y=1+c: X=1, Y=0T_1=\frac{(\text{b: X=0, Y=1}-\text{c: X=1, Y=0})^2}{\text{b: X=0, Y=1}+\text{c: X=1, Y=0}}

    Used when b+c is greater than 20.

Usage stats

Advertisement

Results

Decision
Reject H0
Method used Chi-square
Chi-square (no correction) 11.5600
Chi-square (corrected) 10.2400
p-value (no correction) 0.000674
p-value (corrected) 0.001374
Exact binomial p-value 0.000911
p-value used 0.000674
b + c 25

Report an error on this page

What the McNemar test calculator does

This calculator applies the McNemar test to a paired 2x2 table of counts. It checks whether two paired binary measurements, such as a before-and-after result or two diagnostic tests on the same subjects, change in one direction more often than the other. Only the discordant pairs matter. The calculator returns the chi-square statistic with and without continuity correction, the matching p-values, an exact binomial p-value, and a reject or do-not-reject decision.

Paired 2x2 table with cells a, b, c, d; off-diagonal cells b and c highlighted
McNemar's test only uses the discordant cells b and c; the concordant cells a and d drop out.

How to use it

Enter the four cell counts in the order of the form. Cell a is X=0, Y=0. Cell b is X=0, Y=1. Cell c is X=1, Y=0. Cell d is X=1, Y=1. Counts must be non-negative whole numbers. Cells a and d are concordant pairs and do not affect the result. Then choose the two-sided significance level (0.50, 0.20, 0.10, 0.05 or 0.01) and choose whether the large-sample decision uses the statistic with or without continuity correction. The test is undefined when b + c = 0.

Formula

For the large-sample case, with \(b\) and \(c\) the discordant counts:

$$T_1=\frac{(b-c)^2}{b+c}$$$$T_1'=\frac{(|b-c|-1)^2}{b+c}$$

\(T_1\) is the uncorrected statistic and \(T_1'\) the continuity-corrected one. Both are compared with a chi-square distribution with 1 degree of freedom, and the p-value is

$$p=\operatorname{erfc}\left(\sqrt{\tfrac{T}{2}}\right)$$

For small samples, \(T_2=b\) is compared with a Binomial(\(b+c\), 0.5) distribution, and the two-sided exact p-value is

$$p=\min\left(1,\;2\sum_{i=0}^{k}\binom{n}{i}\frac{1}{2^n}\right),\quad n=b+c,\;k=\min(b,c)$$
Advertisement
Discordant counts b and c feeding into a chi-square curve with a shaded right-tail rejection region
The statistic (b − c)² / (b + c) is compared with a chi-square distribution with 1 degree of freedom; values in the shaded tail lead to rejecting marginal homogeneity.

Conventions and assumptions

  • Cell layout: rows are variable X and columns are variable Y, so b and c are the discordant counts.
  • Hypotheses: H0 states P(X=0,Y=1) = P(X=1,Y=0); the alternative is that they differ (two-sided).
  • Method switch: if b + c is greater than 20, the chi-square statistic is used. If b + c is 20 or less, the exact binomial method is used. The source sample output mentions N ≥ 20, but its formula text says b + c > 20, and that threshold is followed here.
  • Continuity correction: both statistics are reported, and the selector decides which one drives the large-sample decision.
  • Chi-square p-value: the upper tail of chi-square with 1 df. Reject H0 when p ≤ alpha. This is a design choice, since the source gives no p-value formula.
  • Exact p-value: doubled lower tail of the binomial, capped at 1. This is also a design choice.
  • Rounding: raw values are computed; statistics are displayed to 4 decimals and p-values to 6.
  • When b = c, the uncorrected statistic is 0 and p = 1, while the corrected statistic is positive and its p-value is reported as computed.
Binomial distribution bars with both tails highlighted as the exact two-sided p-value
The exact McNemar p-value treats b as a binomial count out of b + c with p = 0.5 and adds up both tails.

Worked example

Take a = 63, b = 21, c = 4, d = 12, alpha = 0.05, and no continuity correction. The discordant total is \(b+c=25\), which is above 20, so the chi-square method applies.

$$T_1=\frac{(21-4)^2}{25}=11.56$$$$T_1'=\frac{(|21-4|-1)^2}{25}=10.24$$

The p-value without correction is 0.000674 and with correction 0.001374. The exact binomial p-value is 0.000911 for reference. The decision uses the uncorrected p-value of 0.000674, which is at most 0.05, so the result is REJECT.

Advertisement

Reading the result and limitations

A REJECT decision means the two kinds of discordant pairs are unlikely to be equally frequent, which points to a real shift between the paired measurements. DO_NOT_REJECT means the data do not show such a difference at the chosen level. It does not prove equality. The test ignores concordant pairs, so it says nothing about agreement overall. It assumes pairs are independent and that each subject is measured twice on a binary outcome. With few discordant pairs, rely on the exact p-value. The chi-square p-value is an approximation, and the corrected statistic is more conservative.

FAQ

Why do cells a and d not matter?

The test asks whether switches from 0 to 1 are as common as switches from 1 to 0. Pairs that did not change carry no information about that question.

When is the exact test used?

When b + c is 20 or fewer. The chi-square approximation is unreliable for such small totals, so the binomial reference is used.

Should I use the continuity correction?

The correction makes the test more conservative and is often preferred for moderate totals. Both statistics are shown so the two can be compared.

What if b equals c?

The uncorrected statistic is 0 and p = 1. The corrected statistic is still positive, and its p-value is shown as computed.

Is the test one-sided or two-sided?

It is two-sided: the alternative is that the two discordant probabilities differ in either direction.

Sources

Sources & References

  • McNemar Test (Dataplot reference manual) — NIST Information Technology Laboratory. Primary NIST documentation; cites Conover (1999) and Fleiss, Levin and Paik (2003). · Effective from 2023-12-11 · Verified 2026-11-04
Last updated:

Most popular in Math and Statistics

View all Math and Statistics calculators