Bell Statistics

What is McNemar's test?

McNemar's test compares two binary measurements taken on the same subjects. It looks only at the cases that changed in one direction versus the other, discarding everyone whose answer was the same both times because they carry no information about which condition is better.

Also called
mcnemar test, paired proportions test, matched pairs chi-square
Allon Korem

Written by Allon Korem

Chief Executive Officer

Last updated

In plain English

When the same subjects are measured twice on a yes-or-no outcome, the four possible outcomes are: yes both times, no both times, yes then no, and no then yes. McNemar's test looks at the last two and ignores the first two entirely. The reasoning is that a subject who converted under both conditions, or under neither, tells you nothing about which condition is better — they would have landed in the same place regardless, and including them only dilutes the comparison.

That makes it the binary counterpart of the paired t-test, and it inherits the same advantage. Between-subject variation is removed from the comparison, because each subject serves as their own control. A population where some people are eager converters and others never buy no longer swamps the signal, since the eager converters and the never-buyers both fall into the discarded agreement cells. What remains is only the people the treatment actually moved.

The discarding is what people find counterintuitive, and it is worth being precise about why it is correct rather than wasteful. Suppose 900 subjects convert under both conditions, 30 convert only under A, and 70 only under B. The question is whether B genuinely moves more people than A, and the evidence for that lives entirely in the 30 versus 70 split. The 900 are consistent with A and B being identical and equally consistent with B being far better; they simply do not discriminate. Adding them to the denominator would make the test less sensitive, not more honest.

Its natural home in experimentation is anywhere the same unit sees both conditions: interleaving experiments in search and recommendations, where one user is shown a blended result set and their click reveals a preference; before-and-after studies on a binary outcome; and diagnostic or model comparisons where two classifiers score the same set of cases. It is not applicable to a standard A/B test, where each user sees one variant and there is no second measurement to pair with.

The classical version uses a chi-square approximation with one degree of freedom, and it needs a reasonable number of discordant pairs — the usual guidance is at least 25. Below that the approximation is unreliable and the exact binomial version is the right choice, which is the same relationship Fisher's exact test has with chi-square on unpaired data. Note that the threshold applies to the discordant pairs alone, so a study with 5,000 subjects and 18 changers still needs the exact test.

The formula

Only two of the four cells appear anywhere in the arithmetic, which is the whole idea stated as a formula.

The statistic
χ² = ( b − c )² / ( b + c )

b and c are the two discordant counts. The concordant cells a and d appear nowhere at all.

With continuity correction
χ² = ( |b − c| − 1 )² / ( b + c )

Yates' version, still the default in some software. Conservative, and largely superseded by the exact test when b + c is small.

The exact version
p = 2 · P( X ≥ max(b, c) ), X ~ Binomial( b + c, 0.5 )

Under the null each discordant pair is a coin flip. Use when b + c < 25 — see the McNemar's calculator.

The effect it estimates
difference in proportions = ( b − c ) / n

n is all subjects, including the concordant ones. The test ignores them; the effect size does not.

Worked example

A search team runs an interleaving experiment on 4,200 sessions, showing each user results blended from two ranking models and recording which model produced the clicked result. In 3,540 sessions the click was ambiguous or both models would have surfaced the same item; 268 sessions favoured model A and 392 favoured model B.

Total sessions
4,200
Uninformative (concordant)
3,540
Favoured model A (b)
268
Favoured model B (c)
392
Discordant pairs
660 — well above 25, so the chi-square form is fine
Statistic
(392 − 268)² / 660 = 23.30

p = 0.0000014 on one degree of freedom. Model B is preferred in 59.4% of the sessions that discriminated between the two.

The test rests on 660 sessions out of 4,200, and that is the design working rather than data being wasted. The other 3,540 sessions were genuinely uninformative about which model ranks better — both models would have produced the same click — so including them would have diluted a clear signal into a muddy one. Two cautions. The 59.4% preference is among discriminating sessions only, and translating it into a business impact needs the whole denominator: the difference across all sessions is (392 − 268) / 4,200, or 3.0 percentage points, which is the number a stakeholder should hear. And interleaving measures preference between two rankings, not whether either ranking increases revenue — a model users prefer click-for-click can still perform worse on the outcome the business cares about.

Common misconceptions

Discarding the agreements throws away most of your data.
It discards the observations that cannot distinguish the two conditions. A subject who converted under both would have converted whichever they saw, so they contribute nothing to the question of which is better. Including them would shrink the apparent effect and reduce sensitivity — the exclusion makes the test more powerful, not less.
McNemar's test can be used on any two proportions.
Only paired ones, where the same subjects generate both measurements. Applying it to two independent groups is a genuine error: the discordant-pair structure it depends on does not exist, and there is no principled way to build the b and c cells. Independent proportions need a z-test or a chi-square test.
A significant McNemar's test means the treatment works for most people.
It means more people moved in one direction than the other among those who moved at all. If 660 of 4,200 subjects were affected and B won 392 of those, the treatment changed the outcome for about 3% of the population. That can be a valuable effect and it is not the same claim as the 59% figure the discordant split suggests.

Frequently asked questions

How many discordant pairs does McNemar's test need?
At least about 25 for the chi-square approximation to be trustworthy. Note this is a condition on the discordant pairs alone, not on the study size — a trial with 5,000 subjects where only 18 changed still fails it. Below the threshold the exact binomial version is the correct choice, and since it is cheap to compute there is little reason not to use it whenever the count is marginal.
How does McNemar's test relate to the paired t-test?
They solve the same problem for different outcome types. Both compare two measurements on the same units and both gain their power by removing between-unit variation. The paired t-test works on measured quantities and analyses the mean of the within-pair differences; McNemar's works on binary outcomes, where a difference can only be −1, 0 or +1, so the analysis reduces to counting the two non-zero cases.
What if the outcome has more than two categories?
Use the Stuart-Maxwell test, which generalises McNemar's to a square table with more than two levels and tests whether the marginal distributions differ overall. If the categories are ordered — a satisfaction rating, for example — a test that respects the ordering will be substantially more powerful than one treating the levels as unrelated labels.

Related terms

  • Chi-square test

    The test for counts in a table — the standard SRM check, and the reason expected counts matter more than sample size.

  • Fisher's exact test

    Counts the possible tables instead of approximating them — the right test when a cell expects fewer than five.

  • Interaction effect

    When two changes stop being independent — the reason concurrent tests can both read as wins and lose money together.

  • Paired t-test

    When every observation has a partner, pairing removes the differences between units and can cut the sample you need by an order of magnitude.

Calculate it

  • McNemar's test

    Paired yes/no data — only the pairs that disagree carry any information, and this sizes on them.

  • Chi-square test

    Test a contingency table of counts for association — any number of rows and columns.

Knowing the term is the easy part

Applying it to a live measurement problem is the part that goes wrong. If you are designing an experiment, reading a result you do not trust, or trying to work out what your marketing actually caused, that is the work we do.