McNemar Test Calculator
Perform McNemar's paired contingency test for repeated-measures and matched-pair binary data. Computes exact binomial p-values, Edwards continuity-corrected χ², discordant odds ratios, and marginal risk differences with confidence intervals.
2 × 2 Paired Contingency Table
Enter matched or repeated binary counts
[Positive (+)]
[Negative (-)]
In McNemar's test, subjects who were positive on both occasions (cell a) or negative on both occasions (cell d) did not change their outcome. Statistical significance is determined exclusively by comparing the subjects who converted one way (b) versus the other way (c). However, cells a and d are crucial for calculating overall marginal proportions and the risk difference.
Discordant total b + c = 45 (≥ 25). The Edwards continuity-corrected chi-square test and the exact binomial test are both highly accurate and yield congruent conclusions.
Complete Step-by-Step Mathematical Derivation
Detailed formula walkthrough with your exact numbers
From the 2×2 contingency table with grand total N = 100:
Conditioned on the 45 discordant pairs, the count follows a binomial distribution B(45, 0.5):
Because the primary p-value (7.7511e-6) is less than α = 0.05, we reject the null hypothesis. There is statistically significant evidence of a differential change in outcomes between Condition 1 (Before) and Condition 2 (After) (Risk Difference Δp = -31.00%, Odds Ratio = 0.18).
What is McNemar's Test?
McNemar's test is a non-parametric statistical hypothesis test introduced in 1947 by Quinn McNemar for analyzing paired, matched-pairs, or repeated-measures nominal data with a dichotomous (binary) outcome. Whenever the exact same research subjects are evaluated at two distinct time points (such as before and after an intervention) or under two different experimental conditions, the observations are paired and inherently correlated.
Standard independent tests—most notably Pearson's Chi-Square Test of Independence—assume that all observations in the table are independent of one another. Applying Pearson's test to paired or repeated-measures binary data violates the core independence assumption and inflates the probability of committing a Type I or Type II error. McNemar's test properly accounts for the matched structure by conditioning exclusively on the discordant pairs (the subjects whose outcome changed).
McNemar's Test vs. Alternative Statistical Tests
Choosing the correct test depends on study design, pairing status, and the number of treatment conditions:
| Test Name | Sample Design | Outcome Variable | Key Distinguishing Feature |
|---|---|---|---|
| McNemar's Test | Paired / Repeated (2 conditions) | Binary (Yes/No, Pass/Fail) | Evaluates discordance in paired 2×2 tables. |
| Pearson's Chi-Square Test | Independent groups | Categorical (2 or more levels) | Requires independent subjects; cannot be used for pre/post testing. |
| Paired Samples t-Test | Paired / Repeated (2 conditions) | Continuous (Interval / Ratio) | Compares means of continuous difference scores. |
| Cochran's Q Test | Paired / Repeated (3 or more conditions) | Binary (Yes/No) | The multi-condition extension of McNemar's test for ≥ 3 time points. |
| Bowker's Test of Symmetry | Paired / Repeated (2 conditions) | Polytomous (> 2 categories) | Extension of McNemar's test for tables larger than 2×2 (e.g., 3×3). |
Exact Binomial Test vs. Edwards Continuity-Corrected χ²
Exact Binomial Test (b + c < 25)
Under the null hypothesis, each discordant subject is equally likely to convert from positive to negative as from negative to positive. Therefore, the count of one discordant cell follows a Binomial distribution with parameters n = b + c and p = 0.5.
Because this method makes no asymptotic approximations, it is exact for any sample size. Statistical packages like R (exact2x2::mcnemar.exact) and Python recommend this test whenever the total number of discordant pairs is under 25.
Edwards Continuity Correction (b + c ≥ 25)
In 1948, Allen Edwards introduced a continuity correction to McNemar's asymptotic formula to bridge the gap between the discrete binomial distribution and the continuous 1-degree-of-freedom chi-square distribution:
Subtracting 1 in the numerator prevents over-optimistic (artificially deflated) p-values and controls the empirical Type I error rate near the nominal 5% level.
Real-World Research Examples
Hypertension Medication Efficacy Trial
120 patients with elevated systolic pressure are measured Before and 6 weeks After starting a calcium-channel blocker. High blood pressure is coded as Positive (+), normal as Negative (-).
- Cell a (High → High): 30 patients
- Cell b (High → Normal): 45 patients (Discordant improvement)
- Cell c (Normal → High): 5 patients (Discordant relapse)
- Cell d (Normal → Normal): 40 patients
- Discordant Pairs: b + c = 50 (≥ 25)
- Edwards χ²: (|45 - 5| - 1)² / 50 = 39² / 50 = 30.42, p < 0.0001
- Conclusion: Statistically significant reduction in hypertension prevalence (Reject H₀).
AI Radiology Screening vs. Radiologist
20 chest CT scans are classified for nodule malignancy by an experienced Radiologist (Test A) and a new AI deep learning algorithm (Test B).
- Cell a (+ / +): 6 scans agreed positive
- Cell b (Rad + / AI -): 7 scans
- Cell c (Rad - / AI +): 1 scan
- Cell d (- / -): 6 scans agreed negative
- Discordant Pairs: b + c = 8 (< 25 → Exact Binomial required)
- Exact Two-Sided P-Value: 2 × BinomCDF(8, 1, 0.5) = 2 × 0.0352 = 0.0703
- Decision at α = 0.05: Fail to reject H₀ (0.0703 > 0.05). Sensitivity differences are not statistically significant at 95% confidence.
Verifying Results in R, Python, and SPSS
Our calculator matches the exact numerical outputs of major statistical and scientific computing suites:
# Create 2x2 matrix: matrix(c(a, c, b, d), nrow=2)
# Note: R fills column-by-column!
mat <- matrix(c(35, 7, 38, 20), nrow = 2,
dimnames = list("Before" = c("+", "-"),
"After" = c("+", "-")))
# Edwards Continuity-Corrected McNemar Test:
mcnemar.test(mat, correct = TRUE)
# Exact Binomial McNemar Test (exact2x2 package):
# exact2x2::mcnemar.exact(mat)from statsmodels.stats.contingency_tables import mcnemar
# 2x2 contingency table: [[a, b], [c, d]]
table = [[35, 38],
[7, 20]]
# Exact Binomial test:
res_exact = mcnemar(table, exact=True)
print("Exact p-value:", res_exact.pvalue)
# Continuity-corrected Chi-Square:
res_chi2 = mcnemar(table, exact=False, correction=True)
print("Chi2:", res_chi2.statistic, "p:", res_chi2.pvalue)Frequently Asked Questions
Related Calculators
Created by William Davis
Last updated: October 14, 2026