Skip to content

McNemar's Test

Categorical Analysis

Tests whether the proportion of subjects in one category changes between two paired measurements, focusing on the discordant pairs.

When to Use

Use this test when you have paired binary data and want to know whether the proportion changed. For example, testing whether the proportion of patients testing positive changed from before treatment to after treatment, or whether voters changed their preference between two time points.

Assumptions

  • Data are paired: each subject has a binary measurement at two time points or under two conditions.
  • The outcome is dichotomous (two categories).
  • Observations (pairs) are independent of each other.

Required Inputs

InputTypeNotes
Before MeasurementCategorical (2 levels)Binary outcome at the first time point
After MeasurementCategorical (2 levels)Binary outcome at the second time point (same categories as before)

Output Metrics

MetricWhat it means
McNemar Chi-SquareTest statistic: (b - c)^2 / (b + c), where b and c are the discordant pair counts.
DFDegrees of freedom (always 1 for a 2x2 table).
p-valueP-value for the null hypothesis that the marginal proportions are equal.
Discordant Pair Count (b)Number of subjects who changed from category 1 to category 2.
Discordant Pair Count (c)Number of subjects who changed from category 2 to category 1.

Interpretation

  • A significant result indicates that the proportion changed between the two measurements. The direction of change is determined by comparing b and c.
  • Only discordant pairs (subjects who changed category) contribute to the test. Concordant pairs (subjects who stayed the same) provide no information about change.
  • If b > c, the proportion in category 2 increased from the first to the second measurement.
  • For small numbers of discordant pairs (b + c < 25), use the exact binomial version of the test rather than the chi-square approximation.

Common Pitfalls

  • McNemar's test only detects changes in marginal proportions. It does not test for agreement (use Cohen's kappa for that).
  • The chi-square approximation is unreliable when the total number of discordant pairs is small (< 25). Use the exact binomial test.
  • The test assumes the two categories are the same at both time points. If categories differ, the test is not applicable.

How It Works

  1. Construct a 2x2 table where rows represent the first measurement and columns represent the second measurement. Let b = count of (category 1 to category 2) and c = count of (category 2 to category 1).
  2. Under the null hypothesis that marginal proportions are equal, b and c should be approximately equal.
  3. Compute the test statistic: chi-square = (b - c)^2 / (b + c).
  4. Compare to the chi-square distribution with 1 degree of freedom. For small samples, use the exact binomial test with p = 0.5.

Citations

References

  • McNemar, Q. (1947). Note on the sampling error of the difference between correlated proportions or percentages. Psychometrika, 12(2), 153-157.