McNemar's Test, Explained

After reading this you will know how to test whether a paired binary outcome changed direction more often one way than the other, using McNemar's chi-square and the exact binomial version, and why only two cells of the table matter.

What McNemar's test does

McNemar's test compares two paired binary measurements on the same subjects. The classic setup is before and after: you measure a yes/no outcome, apply something, then measure the same outcome again on the same people. The question is whether the proportion saying "yes" changed.

Suppose 100 people take a survey before and after watching a training video. The question is "Would you recommend this product?" Before, 40 said yes. After, 50 said yes. You cannot treat these as two independent samples, because the same 100 people answered both times. The answers are paired. McNemar's test handles that pairing correctly by looking only at the people who switched.

Lay the data out as a 2×2 table of the pair of answers. Cell a counts people who said yes both times. Cell d counts people who said no both times. Those are the concordant cells, and McNemar's test ignores them. The two discordant cells carry all the information: b is yes then no, and c is no then yes.

When to use it, and when not

Use McNemar's test when your data are paired and the outcome is binary. Typical cases include the same patients tested with two diagnostic methods, the same voters before and after a debate, or matched case-control pairs where each case is tied to one control.

Do not use it when the two groups are independent. If you have two separate samples and a yes/no outcome, you want a two-proportion z-test or a chi-square test of independence instead. Feeding independent data into McNemar's test throws away the very structure it relies on and gives the wrong answer.

The most common error is confusing the paired table with an ordinary 2×2 contingency table. In a contingency table the two variables are "group" and "outcome". In McNemar's table both axes are the same outcome measured at two times. If you run a chi-square test of independence on paired data you are testing the wrong hypothesis.

The formula and the intuition

The null hypothesis is marginal homogeneity: the probability of yes is the same before and after. In table terms, that means the expected number of switchers in each direction is equal, so b = c in the population.

The uncorrected McNemar statistic is

\chi^2 = \frac{(b - c)^2}{b + c}

Here b and c are the two discordant counts. Under the null hypothesis this statistic follows a chi-square distribution with 1 degree of freedom. The concordant counts a and d never appear, because someone who answered the same way twice tells you nothing about the direction of change.

Because b and c are whole numbers approximated by a continuous curve, many people apply Yates's continuity correction:

\chi^2_c = \frac{(|b - c| - 1)^2}{b + c}

This shrinks the statistic and makes the p-value slightly larger, guarding against a test that rejects too easily with small counts. When b + c is small, drop the chi-square approximation entirely and use the exact binomial test. Under the null, each of the b + c discordant pairs is equally likely to fall in either direction, so b follows a binomial distribution with n = b + c and p = 0.5.

P = 2 \sum_{i=0}^{\min(b,c)} \binom{n}{i} (0.5)^n

That is a two-sided p-value: sum the binomial probability of getting a split as extreme as yours or more extreme, on both tails.

Worked example with the demo data

Twenty switchers, split 5 and 15

The demo uses b = 5 (changed yes to no) and c = 15 (changed no to yes). So 20 people switched, and far more moved into "yes" than out of it.

  1. Compute the difference: b - c = 5 - 15 = -10, so (b-c)^2 = 100.
  2. Uncorrected statistic: \chi^2 = 100 / 20 = 5.0. With 1 degree of freedom that gives p \approx 0.0253.
  3. Continuity-corrected: (|{-10}| - 1)^2 = 81, so \chi^2_c = 81 / 20 = 4.05, giving p \approx 0.0442.
  4. Exact binomial: with n = 20 and p = 0.5, sum the tails from 0 to 5 heads and double it. That gives p \approx 0.0414.

Because b + c = 20 is below 25, report the exact result: p \approx 0.0414. All three methods agree that the shift toward "yes" is unlikely under the null. The concordant counts could be anything (say 30 yes/yes and 50 no/no) and the p-value would not move.

Only the two discordant bars matter. A larger gap between them, relative to their sum, pushes the statistic up.

Explore how the split changes the result

With 20 discordant pairs total, a 10/10 split gives chi-square 0 and p = 1. A 6/14 split gives chi-square 3.2 and p about 0.074. A 5/15 split gives chi-square 5.0 and exact p about 0.041. A 3/17 split gives chi-square 9.8 and exact p about 0.003. The more lopsided the split, the smaller the p-value.

Reading and interpreting the output

The calculator returns three p-values: uncorrected chi-square, continuity-corrected chi-square, and the exact binomial. Pick one before you look at them, based on sample size, and report that one.

Small p-value
Evidence that the two marginal proportions differ. In the demo, the shift from "no" to "yes" is real, not just sampling noise.
Direction
The test itself is two-sided. Read the direction from the counts: c \gt b means more subjects moved into "yes".
Effect size
The raw shift in proportion is (c - b) / n, where n is the total number of pairs. With 100 pairs and a net swing of 10, that is a 10 percentage point increase in "yes".

A significant McNemar result says the proportions changed, not by how much. Always report the discordant counts and the net swing alongside the p-value so a reader can judge whether the change matters in practice.

Common mistakes

Using the wrong denominator is the frequent slip. The statistic divides by b + c, not by the grand total. A table with 5 and 15 discordant among 1000 subjects gives the same statistic as 5 and 15 among 20 subjects. The concordant counts do not dilute the evidence.

Applying the continuity correction and the exact test at the same time double-counts the caution. Choose one. Use the exact binomial when b + c \lt 25, and the uncorrected chi-square when the discordant total is large, say above 40.

Treating a 3×3 or larger paired table as a McNemar problem does not work. For more than two categories you need the McNemar-Bowker test of symmetry, which this calculator does not compute.

Finally, do not run McNemar's test on ordinal or continuous paired data. If your paired outcome is a rank or a score, use the Wilcoxon signed-rank test, or a paired t-test when the differences are roughly normal.

Related calculators

For independent binary groups rather than paired ones, use the chi-square test of independence, or Fisher's exact test when counts are small. To turn a chi-square statistic into a p-value by hand, see the p-value calculator. For a single proportion against a fixed target, use the one-proportion z-test.

Frequently asked questions

Why does McNemar's test ignore cells a and d?

Because concordant subjects answered the same way twice, they give no evidence about whether the marginal proportion shifted. The null hypothesis concerns only the balance between the two switching directions, and that balance lives entirely in b and c.

Should I use the continuity correction?

Use it when the discordant total is modest and you still want the chi-square approximation. When b + c \lt 25, skip both chi-square versions and report the exact binomial p-value, which needs no correction.

What if b + c is zero?

No one switched, so the test is undefined and the p-value is 1 by convention. There is no evidence of any change because nobody changed.

Is McNemar's test one-sided or two-sided?

The standard versions are two-sided. The exact binomial p-value shown here doubles the smaller tail. If you have a directional hypothesis, halve the exact p-value, but state that choice before seeing the data.

How is this different from a paired t-test?

A paired t-test compares means of continuous paired differences. McNemar's test compares proportions of a binary paired outcome. Same pairing idea, different data type.