McNemar’s test
Proportions (counts) · Two paired samples · reference distribution: χ²(1)
When to use it
Compare a proportion measured twice on the same individuals, such as opinion before and after a campaign.
Null hypothesis
The proportion did not change: switches in one direction and the other are equally likely.
Assumptions
- Paired binary response
- b + c not too small (otherwise, the exact version)
Test statistic
\chi^2 = \dfrac{(b - c)^2}{b + c}Effect size
Paired odds ratio: how many times one switch is more common than the other.
OR = \dfrac{b}{c}How to report it
b = 18, c = 6, χ²(1) = 6.00, p = .014, OR = 3.0
In R and Python
mcnemar.test(table, correct = FALSE)
from statsmodels.stats.contingency_tables import mcnemar
mcnemar(table, exact=False, correction=False)
In Python, stats is scipy.stats and np is numpy.
Variants and alternatives
- Exact binomial version, for small b + c
Where it sits in the catalog
Proportions (counts). For categorical answers, such as yes or no, hit or miss: the data are how often each category appears, and the test compares proportions.
Two paired samples. Two measurements linked in pairs: the same individual before and after, or matched pairs, such as twins. The test uses the difference within each pair.
In the decision tree
- What do you want to do? Compare groups, or one group with a reference value
- What kind of response did you measure? Categorical: yes or no, or categories
- How many groups or measurements? Two measurements on the same individuals