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

Variable & Condition LabelsOptional customization
Frequencies MatrixOff-diagonals (b, c) drive the test
Condition 1 (Before)
Condition 2 (After)
[Positive (+)]
Condition 2 (After)
[Negative (-)]
Row Total
Positive (+)(Condition 1 +)
a (+ / +)Concordant
b (+ / -)Discordant
73a + b
Negative (-)(Condition 1 -)
c (- / +)Discordant
d (- / -)Concordant
27c + d
Column Total
42a + c
58b + d
N = 100Grand Total
Concordant (a + d)
55 (55.0%)
No change between tests
Discordant (b + c)
45 (45.0%)
Used for hypothesis test
Why Concordant Pairs (a & d) Do Not Affect the P-Value

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.

Statistical Decision (α = 0.05)
Statistically Significant Difference (Reject H₀)
Recommended Test: Edwards Continuity-Corrected Chi-Square

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.

Exact Binomial p
3.1213e-6
Under H₀: b ~ Binomial(45, 0.5)
Edwards Corrected χ²Recommended
20.0000
p = 7.7511e-6 (df = 1)
Uncorrected χ²
21.3556
p = 3.8192e-6 (df = 1)
Marginal Difference (Δp)
-31.00%
95% CI: [-42.66%, -19.34%]
Discordant Odds Ratio (c / b)
0.184
95% CI: [0.082, 0.412]
Cohen's g Effect Size
0.344
Large effect
Marginal Positive Proportions ComparisonDifference: -31.00%
Condition 1 (Before) Positive Rate:73.00% (73/100)
Condition 2 (After) Positive Rate:42.00% (42/100)
Discordant Directional Shifts
Shift from Positive → Negative (b)
38
84.4% of discordant pairs
Shift from Negative → Positive (c)
7
15.6% of discordant pairs

Complete Step-by-Step Mathematical Derivation

Detailed formula walkthrough with your exact numbers

1Identify Concordant and Discordant Pairs

From the 2×2 contingency table with grand total N = 100:

Concordant pairs (unchanged): a + d = 35 + 20 = 55
Discordant pairs (changed): n_d = b + c = 38 + 7 = 45
2Define Statistical Hypotheses
Null Hypothesis (H₀): p_b = p_c = 0.5 (Discordant shifts are equally likely)
Alternative Hypothesis (H₁): p_b ≠ p_c (Two-sided test: marginal rates differ)
3Exact Binomial McNemar Test Calculation

Conditioned on the 45 discordant pairs, the count follows a binomial distribution B(45, 0.5):

Smaller discordant cell: k = min(b, c) = min(38, 7) = 7
Two-sided p-value = 2 × ∑ [i=0 to 7] (45 choose i) × 0.5^45
Exact P-Value = 3.1213e-6
4Edwards Continuity-Corrected Chi-Square (χ²)
Formula: χ²_corrected = (|b - c| - 1)² / (b + c)
χ²_corrected = (|38 - 7| - 1)² / (38 + 7)
χ²_corrected = (31 - 1)² / 45 = 900 / 45 = 20.0000
χ²_corrected P-Value = 7.7511e-6 (df = 1)
5Marginal Proportions and Risk Difference (Confidence Interval)
p₁ (Condition 1 (Before)) = (35 + 38) / 100 = 0.7300 (73.00%)
p₂ (Condition 2 (After)) = (35 + 7) / 100 = 0.4200 (42.00%)
Δp = p₂ - p₁ = (7 - 38) / 100 = -0.3100 (-31.00%)
SE(Δp) = √[ (b + c) - (b - c)² / N ] / N = 0.0595
95% CI: Δp ± 1.96 × 0.0595 = [-42.66%, -19.34%]
6Final Research Conclusion at α = 0.05

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 NameSample DesignOutcome VariableKey Distinguishing Feature
McNemar's TestPaired / Repeated (2 conditions)Binary (Yes/No, Pass/Fail)Evaluates discordance in paired 2×2 tables.
Pearson's Chi-Square TestIndependent groupsCategorical (2 or more levels)Requires independent subjects; cannot be used for pre/post testing.
Paired Samples t-TestPaired / Repeated (2 conditions)Continuous (Interval / Ratio)Compares means of continuous difference scores.
Cochran's Q TestPaired / Repeated (3 or more conditions)Binary (Yes/No)The multi-condition extension of McNemar's test for ≥ 3 time points.
Bowker's Test of SymmetryPaired / 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:

χ²_corrected = (|b - c| - 1)² / (b + c)

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

Medical Research CaseRepeated Measures

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₀).
Diagnostic Tool AuditSmall Sample Exact

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:

R (stats::mcnemar.test)Standard
# 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)
Python (statsmodels / scipy)Statsmodels
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

William Davis

Created by William Davis

Last updated: October 14, 2026

Add to Google Preferred