Quant Memo
Advanced

McNemar's Test for Paired Proportions

A test for whether two paired classifiers or models disagree symmetrically or one systematically outperforms the other, using only the cases where they disagreed.

Suppose you have two classifiers — say, two versions of a model predicting whether a stock beats earnings — and you run both on the same set of names. You want to know if one model is genuinely better, not just different on the overall hit rate, which can hide a lot. McNemar's test does this cleanly by looking only at the cases where the two models disagreed: cases where both were right or both were wrong tell you nothing about which is better, so they're discarded entirely.

Build a 2×2 table of disagreements: n01n_{01} counts cases where model 1 was wrong and model 2 was right, and n10n_{10} counts the reverse. Under the null hypothesis that neither model is systematically better, these two counts should be roughly equal. The test statistic is

χ2=(n01n10)2n01+n10,\chi^2 = \frac{(n_{01} - n_{10})^2}{n_{01} + n_{10}} ,

compared against a chi-squared distribution with one degree of freedom. In plain English: it asks whether the disagreements lean lopsidedly toward one model, using only the disagreement counts and ignoring every case both models agreed on.

Worked example

Testing two earnings-surprise classifiers on 200 stocks: both right on 120, both wrong on 50, model 1 right where model 2 was wrong on 10 stocks (n10=10n_{10}=10), and model 2 right where model 1 was wrong on 20 stocks (n01=20n_{01}=20). Then

χ2=(2010)220+10=100303.33,\chi^2 = \frac{(20-10)^2}{20+10} = \frac{100}{30} \approx 3.33 ,

which falls short of the standard 3.84 cutoff for significance at the 5% level with 1 degree of freedom — so despite model 2 winning twice as often on the disagreement cases, the sample of 30 disagreements isn't yet large enough to rule out that this lean is just noise.

McNemar's test compares two paired classifiers using only the cases where they disagreed, checking whether the disagreements lean lopsidedly toward one model rather than splitting roughly evenly — a cleaner comparison than raw accuracy, which is diluted by every case both models got right or wrong together.

Related concepts

Practice in interviews

Further reading

  • McNemar, Psychometrika 1947
ShareTwitterLinkedIn