McNemar's Test Calculator

McNemar's Test Calculator

Test whether a yes/no outcome changed for the same people measured twice, such as before and after treatment, with exact and chi-square p-values.

χ² = (b − c)² ÷ (b + c)

Enter the counts of each before-and-after combination
After: yesAfter: no
Before: yes
Before: no

Count each person once, in the box for their before-and-after pair. Only the two "changed" boxes, b and c, drive the test.

Fill in all four cells

What is McNemar's Test?

McNemar's test checks whether a yes/no outcome changed when the same people are measured twice. It's the paired-data counterpart of the chi-square test, just as the paired t-test is for averages.

People who answered the same both times tell you nothing about change, so the test ignores them. It focuses on the two kinds of switchers: yes-to-no and no-to-yes. With no real change those should be about equal.

It suits before-and-after studies, comparing two diagnostic tests on the same patients, and matched case–control pairs.

McNemar's Test Formula

As given by McNemar (1947) and Agresti, Categorical Data Analysis, section 11.1. See Sources.

1. Keep only the people who changed

b = yes → no · c = no → yes

2. Chi-square version

χ² = (b − c)² ÷ (b + c), 1 df
With continuity correction: (|b − c| − 1)² ÷ (b + c)

3. Exact version

p = 2 × P(X ≤ min(b, c)), X ~ Binomial(b + c, 0.5)

Under no change, each switcher is equally likely to go either way, like a coin flip.

Worked Example: A Symptom Before and After Treatment

Given:
100 patients asked about a symptom before and after a course of exercise. Symptom both times 40; lost it 15; gained it 5; neither time 40.
Step 1:
Switchers:
15 lost it, 5 gained it → 20 changed
Step 2:
Chi-square:
(15 − 5)² ÷ 20 = 5.0 → p = 0.025
Step 3:
Exact binomial:
2 × P(X ≤ 5 | n = 20, p = 0.5) = 0.041
Result:
Exact p = 0.041

The symptom rate fell from 55% to 45%, and three times as many patients lost it as gained it: a significant improvement at the 5% level.

Three Versions of the McNemar P-Value

For different numbers of switchers split 3 to 1, showing how the versions converge as counts grow.

Exact, corrected and uncorrected McNemar p-values
b, cExactCorrected χ²Plain χ²
6, 20.28910.28880.1573
15, 50.04140.04420.0253
30, 100.00220.00270.0016
75, 255.64e-79.58e-75.73e-7

Common McNemar's Test Mistakes

  • Using a regular chi-square on paired data. Counting the before and after answers as separate groups ignores that they're the same people.
  • Entering totals instead of the four combinations. "55 yes before, 45 yes after" isn't enough; you need how many switched each way.
  • Using the chi-square version with few switchers. Below about 25 changes, prefer the exact p-value.
  • Forgetting the unchanged people still matter. They don't affect the p-value, but they show how big the change is relative to everyone.

McNemar's Test FAQs

Which p-value should I report?

The exact one is always valid and is preferred when fewer than about 25 people changed. With many switchers, all three versions agree closely.

Why are the unchanged people ignored?

Someone who answered “yes” both times gives no information about whether the treatment changes answers. Only switchers do.

What is the continuity correction?

Subtracting 1 from |b − c| makes the chi-square approximation closer to the exact test for small counts, at the cost of being slightly conservative.

Can I compare two diagnostic tests with it?

Yes. Rows are test A positive/negative, columns test B positive/negative, on the same patients.

What if I have more than two categories?

The Stuart–Maxwell test extends McNemar’s test to paired tables larger than 2 × 2.

Is it the same as a sign test?

The exact version is a sign test on the switchers: each change is a “+” or “−”.

How do I run it in R?

mcnemar.test(matrix(c(40, 15, 5, 40), nrow = 2)) gives the corrected chi-square version.

Who was McNemar?

Quinn McNemar, an American psychologist and statistician, who published the test in 1947.

Sources

Related Tools