Skip to main content

Biostatistics in Practice: Principles and Procedures - A MedCalc companion e-book

McNemar Test

When the same individuals provide two binary measurements — before and after a treatment, with two different diagnostic tests, or as matched case–control pairs — the observations are paired, and independence between groups cannot be assumed. The standard chi-squared test, which compares counts across independent groups, is inappropriate for this structure. The McNemar test tests whether the marginal proportions of a binary outcome are equal across two paired measurements. Its key insight is that concordant pairs — those where both measurements agree — carry no information about differential response; only discordant pairs, where the two measurements disagree, provide evidence for or against a difference in proportions.

Paired Binary Data and the 2×2 Table

The data are arranged in a 2×2 contingency table, but the meaning of the cells differs fundamentally from the independent-samples case. Each cell represents a pair of observations:

Measurement 2: positive Measurement 2: negative Total
Measurement 1: positive $a$$b$$a + b$
Measurement 1: negative $c$$d$$c + d$
Total $a + c$$b + d$$n$

Cells $a$ (positive on both) and $d$ (negative on both) are the concordant pairs: they agree and contribute no information about whether the two measurements differ in their rate of positive results. Cells $b$ (positive on measurement 1, negative on measurement 2) and $c$ (negative on measurement 1, positive on measurement 2) are the discordant pairs: they disagree, and it is their relative frequency alone that drives the test.

The null hypothesis is that among discordant pairs, each type is equally likely — that is, $\text{P}(\text{type } b) = \text{P}(\text{type } c) = \tfrac{1}{2}$. This is equivalent to asserting that the two marginal proportions are equal: $(a + b)/n = (a + c)/n$. Under $H_0$, the count $b$ follows a $\text{Binomial}(n_d,\, \tfrac{1}{2})$ distribution, where $n_d = b + c$ is the total number of discordant pairs.

The McNemar Test Statistic

When the number of discordant pairs $n_d = b + c$ is large (conventionally $n_d \geq 25$), the binomial distribution is well approximated by a normal, and the chi-squared statistic

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

follows a $\chi^2$ distribution with 1 degree of freedom under $H_0$. If $b$ and $c$ are equal there is no asymmetry in either direction and the statistic is zero; the further they diverge, the stronger the evidence against $H_0$.

A continuity correction — analogous to Yates' correction in the ordinary chi-squared test — compensates for the approximation of a discrete distribution by a continuous one:

$$ \chi^2_{\text{cc}} = \frac{(|b - c| - 1)^2}{b + c} $$

The corrected statistic is more conservative and is preferable when $n_d$ is moderate. For large $n_d$ the two versions give virtually identical $P$ values.

Exact McNemar Test

When $n_d < 25$, the normal approximation is unreliable. The exact binomial test should be used instead. Under $H_0$, the smaller discordant count $\min(b, c)$ has probability:

$$ P = 2 \sum_{k=0}^{\min(b,\,c)} \binom{n_d}{k} \left(\tfrac{1}{2}\right)^{n_d} $$

This is the two-tailed probability of observing a split as extreme as, or more extreme than, the one observed, given that each discordant pair is equally likely to fall into either cell. The logic is identical to that of the exact binomial test: the factor of 2 accounts for both tails. For small samples this calculation is exact and avoids the inflated Type I error that the chi-squared approximation produces when discordant counts are sparse — just as Fisher's exact test is preferred over the chi-squared test when expected cell counts are small.

Worked Example

A diagnostic study applies two tests for deep-vein thrombosis (DVT) — a D-dimer assay and compression ultrasonography — to the same 85 patients presenting with clinically suspected DVT. The question is whether the two tests classify patients at significantly different rates.

Ultrasound: positive Ultrasound: negative Total
D-dimer: positive321547
D-dimer: negative43438
Total364985

The D-dimer assay classified 47 of 85 patients (55.3%) as positive; ultrasound classified 36 of 85 (42.4%). The concordant pairs ($a = 32$, $d = 34$) are irrelevant to this comparison. The discordant pairs are $b = 15$ (D-dimer positive, ultrasound negative) and $c = 4$ (D-dimer negative, ultrasound positive), giving $n_d = 19$.

Since $n_d = 19 < 25$, the exact binomial test is used. Under $H_0$, $\min(b, c) = 4$ follows $\text{Binomial}(19, \tfrac{1}{2})$. The exact two-tailed $P$ value is:

$$ P = 2 \sum_{k=0}^{4} \binom{19}{k} \left(\tfrac{1}{2}\right)^{19} = \frac{2(1 + 19 + 171 + 969 + 3876)}{2^{19}} = \frac{10\,072}{524\,288} \approx 0.019 $$

The asymmetry between discordant pairs is statistically significant ($P = 0.019$). D-dimer classifies significantly more patients as positive than ultrasound. Whether this reflects greater sensitivity, lower specificity, or different diagnostic thresholds is a clinical rather than statistical question.

MedCalc computes the McNemar test, the exact two-tailed $P$ value, the matched odds ratio, and its confidence interval in its McNemar test procedure.