McNemar's Test Calculator
McNemar's test determines whether a meaningful change occurred in paired binary (yes/no) responses -- for example, before-and-after a treatment, or in a matched case-control study. Enter the four cells of your 2x2 contingency table and the calculator instantly returns the chi-square statistic, exact binomial p-value, continuity-corrected result, odds ratio for discordant pairs, and a 95% confidence interval for the difference in proportions. Choose your significance level and see whether the change is statistically significant.
What is McNemar's test?
McNemar's test is a non-parametric statistical test for analyzing paired binary data. It was described by Quinn McNemar in 1947 and is used whenever the same subjects (or matched pairs) are measured twice on a dichotomous (yes/no) outcome. Classic examples include testing whether a medical treatment changes symptom presence, comparing diagnostic agreement between two methods on the same patients, and analyzing before-and-after survey responses. The test focuses exclusively on the discordant pairs -- the pairs where the two measurements disagree -- because the concordant pairs (both yes or both no) carry no information about change. Under the null hypothesis of no change, each discordant pair is equally likely to fall into either direction, so the number going from yes to no should equal the number going from no to yes.
The 2x2 contingency table and what each cell means
Enter counts into the four cells of the standard McNemar table: - Cell a (positive/positive): both measurements were yes. These concordant pairs are ignored by the test statistic. - Cell b (positive first, negative second): the pair changed from yes to no. This is a discordant pair. - Cell c (negative first, positive second): the pair changed from no to yes. This is a discordant pair. - Cell d (negative/negative): both measurements were no. Concordant; ignored by the test statistic. Only b and c enter the formula. The chi-square statistic is (b - c)^2 / (b + c), and the test asks whether the imbalance between b and c is greater than would be expected by chance alone.
Choosing between asymptotic and exact methods
When the total number of discordant pairs (b + c) is at least 25, the chi-square approximation works well and is the standard choice. When b + c is less than 25, the chi-square distribution is a poor approximation to the true sampling distribution and an exact binomial p-value is preferred. The exact method treats the number of discordant pairs in direction b as Binomial(b + c, 0.5) under the null hypothesis and computes the exact two-tailed probability. Two continuity corrections are available for the asymptotic test. Edwards' correction subtracts 1 from |b - c| before squaring: (|b - c| - 1)^2 / (b + c). Yates' correction (not separately listed here but implemented in the Edwards form) is similar. These corrections reduce the type I error rate when the sample is moderate. For large samples, the correction has a negligible effect.
Interpreting the outputs: p-value, odds ratio, and confidence interval
A p-value below your significance threshold (typically 0.05) means the data provide sufficient evidence to reject the null hypothesis of no change. The odds ratio for discordant pairs, b/c, measures the direction and size of the imbalance. A ratio of 1 means no imbalance; a ratio greater than 1 means more pairs changed in the b direction (yes to no) than in the c direction. The 95% confidence interval for the difference in proportions quantifies uncertainty around the estimated change. If the interval excludes zero, the result is statistically significant at the 5% level. The difference in proportions is (c - b) / n, where n is the total number of pairs, and it represents the estimated change in the marginal probability from condition 1 to condition 2.
McNemar's Test Decision Guide
| Discordant pairs (b + c) | Recommended method | Notes |
|---|---|---|
| < 25 | Exact binomial | Chi-square approximation is unreliable for small samples |
| 25 or more | Asymptotic chi-square | Standard McNemar formula is appropriate |
| 25 or more (moderate sample) | Continuity correction | Edwards correction reduces type I error rate |
| Any size | Exact binomial | Conservative but always valid; preferred in many clinical contexts |
Choosing the right variant based on sample characteristics.
Frequently asked questions
What is the difference between McNemar's test and a chi-square test?
A standard chi-square test of independence assumes the two groups being compared are independent. McNemar's test is specifically designed for paired or matched data, where the same subjects (or matched pairs) are measured under both conditions. Using a chi-square test on paired data would ignore the correlation between measurements and produce incorrect results. McNemar's test accounts for the pairing by focusing only on the discordant pairs.
When should I use the exact binomial method?
Use the exact binomial method when the total number of discordant pairs (b + c) is less than 25. At this sample size the chi-square approximation is unreliable and can give p-values that are too small, increasing the chance of a false positive. The exact method calculates the precise probability from the binomial distribution, so it is always valid regardless of sample size. For large samples both methods give very similar results.
What does the odds ratio in McNemar's test represent?
The odds ratio is simply b divided by c, the ratio of discordant pairs in each direction. Under the null hypothesis of no change it should equal 1.0. A value greater than 1 means more pairs changed in the b direction (from positive to negative), and a value less than 1 means more pairs changed in the c direction (from negative to positive). Unlike the odds ratio in a standard 2x2 table, this one only considers the discordant pairs.
Do the concordant pairs (a and d) affect McNemar's test?
No. Cells a (both positive) and d (both negative) are concordant pairs that provide no information about whether a change occurred. The test statistic depends entirely on b and c. You should still enter a and d because they contribute to the total n used for computing proportions and the confidence interval.
What does the continuity correction do?
The continuity correction (Edwards correction) improves the accuracy of the chi-square approximation for discrete data. It subtracts 1 from the absolute difference |b - c| before squaring: (|b - c| - 1)^2 / (b + c). This reduces the chi-square value slightly, which raises the p-value and makes the test a bit more conservative. It is most useful when the discordant count is moderate (roughly 25 to 50). For large samples the correction makes almost no difference.
What sample size do I need for McNemar's test to be reliable?
There is no minimum for total pairs, but the test requires at least a handful of discordant pairs to be meaningful. When b + c is less than 25, switch to the exact binomial method. The power of the test grows with the number of discordant pairs, not the total number of concordant pairs, so studies that expect a rare change need more total pairs to achieve adequate power.
Sources
- McNemar, Q. (1947). Note on the sampling error of the difference between correlated proportions or percentages. Psychometrika, 12(2), 153-157.
- Sheskin, D. J. (2011). Handbook of Parametric and Nonparametric Statistical Procedures, 5th ed. Chapman and Hall/CRC.
- Edwards, A. L. (1948). Note on the correction for continuity in testing the significance of the difference between correlated proportions. Psychometrika, 13(3), 185-187.