What Is McNemar's Test? (Definition)
Quinn McNemar introduced the test in 1947 in the journal Psychometrika. Its core insight is economical: if you want to know whether a treatment shifted outcomes, subjects who stayed positive throughout (cell a) or stayed negative throughout (cell d) give you no information about the direction or magnitude of change. Only the subjects who switched tell the story — those who went from positive to negative (cell b) and those who went from negative to positive (cell c).
The test asks a straightforward question: under the null hypothesis, should we expect roughly equal numbers of each switching direction? If b and c are close, there is no net shift. If one far exceeds the other, the proportions changed. The test statistic measures how asymmetric that split is, relative to sampling variability.
McNemar's Test is a non-parametric statistical test for paired binary data. It compares two proportions from the same subjects measured twice — before and after a treatment, under two diagnostic methods, or in a matched-pairs design. The test statistic χ² = (b − c)² / (b + c) is calculated from the discordant cells of a 2×2 contingency table, where b and c count subjects who changed outcome in each direction. A significant result means the probability of changing one way differs from the probability of changing the other way, indicating a real shift in the population proportion.
The 2×2 Contingency Table
McNemar's Test operates on a 2×2 contingency table where the rows represent the outcome under Condition 1 (or Time 1) and the columns represent the outcome under Condition 2 (or Time 2). Every subject contributes one cell to this table based on their pair of outcomes.
| Condition 2 (or Time 2) | Row Total | ||
|---|---|---|---|
| Condition 1 (or Time 1) | Positive (+) | Negative (−) | |
| Positive (+) | a | b | a + b |
| Negative (−) | c | d | c + d |
| Column Total | a + c | b + d | n |
Reading the four cells:
- Cell a (blue): Subjects positive under both conditions — concordant pair. Ignored by the test.
- Cell b (yellow): Subjects positive under Condition 1 but negative under Condition 2. These are discordant — they changed from + to −.
- Cell c (pink): Subjects negative under Condition 1 but positive under Condition 2. These changed from − to +.
- Cell d (green): Subjects negative under both conditions — concordant pair. Also ignored.
Cells a and d do not change between conditions. They carry no information about whether Condition 1 or Condition 2 produces a higher positive rate. Only subjects who switched (b and c) can reveal whether one condition genuinely differs from the other in terms of its proportion of positive outcomes.
Assumptions of McNemar's Test
McNemar's Test has four assumptions. Checking them before running the test prevents misapplication and misleading conclusions.
1. Paired observations (within-subjects design)
Each subject contributes exactly two observations — one per condition or time point. The pairs must be linked: the same patient tested with two diagnostic methods, the same voter surveyed before and after a debate, the same product rated by the same reviewer twice. If the two groups are independent, use the Chi-Square Test instead.
2. Binary (dichotomous) outcome variable
The response variable must have exactly two categories — yes/no, positive/negative, pass/fail, agree/disagree. For outcomes with three or more ordered categories assessed across two conditions, use the McNemar-Bowker Test (a generalization). For more than two time points or conditions, consider Cochran's Q Test.
3. One pair per subject
Each subject appears in exactly one cell of the 2×2 table. Subjects cannot appear in multiple rows or contribute data to more than two conditions (if they do, the data structure is no longer a 2×2 McNemar table).
4. Sufficient discordant pairs (b + c ≥ 10 for the asymptotic test)
The chi-square approximation becomes unreliable when b + c < 10. In that case, switch to the exact McNemar's Test, which uses the binomial distribution directly. This threshold is widely cited in biostatistics textbooks, including Alan Agresti's Categorical Data Analysis.
McNemar's Test Formula
Standard (Asymptotic) Formula
b = cell b: changed from + to −
c = cell c: changed from − to +
b + c = total discordant pairs
df = 1 = degrees of freedom
The formula squares the difference between b and c to make it positive, then divides by the total number of discordant pairs to scale the result. When b and c are equal, the numerator is zero — no evidence of a net shift. As the imbalance between b and c grows, the test statistic grows, eventually exceeding the critical value.
Edwards's Continuity-Corrected Formula
Exact McNemar's Test
Under H₀, if the total number of switchers is n = b + c, then each switcher is equally likely to go in either direction (probability 0.5 each). Cell b follows a Binomial(n, 0.5) distribution. The exact p-value is twice the probability of observing a value as extreme as or more extreme than the smaller of b and c.
How to Perform McNemar's Test: 5 Steps
State the hypotheses
H₀: The marginal proportions are equal — P(Condition 1 positive) = P(Condition 2 positive). Equivalently, the number of + → − changes equals the number of − → + changes in the population (b = c). H₁: The marginal proportions differ (two-tailed) or one exceeds the other (one-tailed). Most applied work uses the two-tailed version.
Construct the 2×2 contingency table
Tally each subject's pair of outcomes into cells a, b, c, d. Confirm that each subject appears exactly once. Record b (+ to −) and c (− to +) separately — they are the discordant pairs that drive the test. Verify b + c ≥ 10 before proceeding with the asymptotic formula; otherwise use the exact test.
Calculate the test statistic
Apply χ² = (b − c)² / (b + c). If b + c is between 10 and 25 and you prefer a conservative approach, use Edwards's continuity-corrected version: χ² = (|b − c| − 1)² / (b + c). The result follows a chi-square distribution with 1 degree of freedom under H₀.
Find the p-value
Compare your χ² value to the critical value from the chi-square table with df = 1. At α = 0.05, the critical value is 3.841. Alternatively, read the exact p-value from software. If using the exact method, compute the two-tailed binomial p-value directly.
State the conclusion
If p < α: reject H₀ and conclude that the two marginal proportions differ statistically. If p ≥ α: fail to reject H₀ — the data do not provide sufficient evidence of a net shift. Report the test statistic, degrees of freedom, sample size, p-value, and direction of the observed difference (which of b or c was larger).
Worked Examples
Example 1 — Diagnostic Test Comparison (Healthcare)
Problem: A hospital evaluates two screening tests for a disease. Both tests are applied to the same 100 patients. Test A classifies 62 patients as positive. Test B classifies 55 as positive. The 2×2 breakdown by paired results is shown below. At α = 0.05, do the two screening tests differ in their positive rate?
| Test B | Total | ||
|---|---|---|---|
| Test A | Positive | Negative | |
| Positive | 50 (a) | 12 (b) | 62 |
| Negative | 5 (c) | 33 (d) | 38 |
| Total | 55 | 45 | 100 |
Hypotheses: H₀: The positive rates of Test A and Test B are equal in the population (b = c). H₁: The positive rates differ (two-tailed).
Identify discordant pairs: b = 12 (positive on Test A, negative on Test B). c = 5 (negative on Test A, positive on Test B). Total discordant pairs = b + c = 17. Since 17 ≥ 10, the asymptotic formula is appropriate.
Calculate the test statistic:
χ² = (b − c)² / (b + c) = (12 − 5)² / (12 + 5) = 49 / 17 = 2.882
Find p-value: χ²(1) = 2.882. The critical value at α = 0.05 with df = 1 is 3.841. Since 2.882 < 3.841, p > 0.05 (exact p ≈ 0.090).
Decision: Fail to reject H₀. Although Test A gave 7 more positive results than Test B (62 vs. 55), the difference in discordant pairs is not statistically significant at the 5% level.
✅ Conclusion: There is insufficient evidence at α = 0.05 to conclude that the two screening tests differ in their population positive rate, χ²(1, N = 100) = 2.88, p = .090. A larger sample may be needed to detect this magnitude of difference.
Example 2 — Before-and-After Survey (Social Science)
Problem: Researchers survey 200 registered voters on their support for a policy before and after a public information campaign. The table below shows their responses. Did the campaign produce a statistically significant change in support at α = 0.01?
| After Campaign | Total | ||
|---|---|---|---|
| Before Campaign | Support | Oppose | |
| Support | 85 (a) | 15 (b) | 100 |
| Oppose | 45 (c) | 55 (d) | 100 |
| Total | 130 | 70 | 200 |
Hypotheses: H₀: The proportion supporting the policy before the campaign equals the proportion supporting it after (b = c in the population). H₁: The proportions differ (two-tailed).
Discordant pairs: b = 15 (switched from support to oppose). c = 45 (switched from oppose to support). b + c = 60. Net change: 45 − 15 = 30 more people moved toward support than away from it.
Test statistic:
χ² = (b − c)² / (b + c) = (15 − 45)² / 60 = (−30)² / 60 = 900 / 60 = 15.00
p-value: χ²(1) = 15.00. The critical value at α = 0.01 with df = 1 is 6.635. Since 15.00 > 6.635, p < 0.001.
Decision: Reject H₀. The campaign shifted voter support — many more people moved from oppose to support (c = 45) than from support to oppose (b = 15).
✅ Conclusion: Support for the policy changed significantly following the campaign, χ²(1, N = 200) = 15.00, p < .001. Support increased from 50% (100/200) before the campaign to 65% (130/200) after, with 45 opponents converting to supporters compared to 15 supporters reversing their position.
Example 3 — Exact McNemar's Test (Small Sample)
Problem: A pilot study tests a new drug in 20 patients with a matched design. Each patient is rated for symptom improvement (Yes/No) before and after the drug. Only 8 patients changed their response. Is there evidence the drug changed response rates? (b = 2, c = 6, b + c = 8 < 10 → use exact test.)
| After Drug | Total | ||
|---|---|---|---|
| Before Drug | Improved | Not Improved | |
| Improved | 5 (a) | 2 (b) | 7 |
| Not Improved | 6 (c) | 7 (d) | 13 |
| Total | 11 | 9 | 20 |
b + c = 2 + 6 = 8 < 10. The chi-square approximation is unreliable here. Use the exact binomial test instead.
Hypotheses: H₀: p = 0.5 (under H₀, discordant pairs split 50/50). H₁: p ≠ 0.5.
Set up binomial: Under H₀, b ~ Binomial(n = 8, p = 0.5). We observed b = 2 (the smaller discordant count; c = 6 is the larger).
Exact p-value calculation:
p-value (two-tailed) = 2 × P(X ≤ 2) where X ~ Binomial(8, 0.5)
P(X=0) = C(8,0)(0.5⁸) = 1/256 ≈ 0.0039
P(X=1) = C(8,1)(0.5⁸) = 8/256 ≈ 0.0313
P(X=2) = C(8,2)(0.5⁸) = 28/256 ≈ 0.1094
P(X≤2) = (1+8+28)/256 = 37/256 ≈ 0.1445
Two-tailed p = 2 × 0.1445 = 0.289
Decision: p = 0.289 > α = 0.05. Fail to reject H₀. With only 8 discordant pairs, the sample size is too small to reliably detect even a substantial imbalance.
✅ Conclusion: Using the exact McNemar's Test, there is insufficient evidence to conclude that the drug changed response rates in the population, exact p = .289 (two-tailed). The pilot study should be used to estimate sample size for a larger confirmatory trial.
McNemar's Test vs. Similar Tests
Choosing the right test depends on your study design, number of groups, and data type. The table below shows when each test applies versus McNemar's.
| Feature | McNemar's Test | Chi-Square Test | Fisher's Exact Test | Cochran's Q Test |
|---|---|---|---|---|
| Study design | Paired (within-subjects) | Independent groups | Independent groups | Paired (within-subjects) |
| Outcome type | Binary | Categorical (any) | Binary | Binary |
| Number of groups | 2 conditions | 2 or more | 2 groups | 3 or more conditions |
| Sample size requirement | b + c ≥ 10 (or use exact) | Expected cell ≥ 5 | Any (exact) | Larger samples preferred |
| Handles small samples | ✓ (exact version) | ✗ | ✓ | ✗ |
| Accounts for pairing | ✓ | ✗ | ✗ | ✓ |
| Common application | Before/after, matched pairs, diagnostic accuracy | Survey responses, frequencies by group | Small-sample 2×2 tables | Crossover trials, repeated measures |
McNemar's Test vs. Chi-Square Test: The Critical Distinction
The most common mistake in analyzing paired binary data is applying the Pearson Chi-Square Test instead of McNemar's Test. These two tests answer different questions:
Using the Pearson Chi-Square Test on paired binary data treats subjects as independent when they are not. This violates the independence assumption and produces an inflated Type I error rate — meaning you will find "significant" results far more often than your chosen α warrants. If the same subjects were measured twice, use McNemar's Test.
The Chi-Square Test compares the observed and expected frequencies across all four cells of the 2×2 table. McNemar's Test discards cells a and d entirely, focusing only on the b and c cells. The two tests can give dramatically different conclusions on the same data, and McNemar's is always correct for the paired design.
When to Use McNemar's Test: Decision Guide
Which Test for Categorical Paired Data?
Real-World Applications
Diagnostic Test Comparison
Evaluate whether two diagnostic tests applied to the same patients differ in their positive detection rates. A standard use case in clinical epidemiology.
Treatment Efficacy
Measure whether a drug or intervention shifts patient status from negative to positive (or from disease to remission) more than it shifts in the opposite direction.
Public Opinion Surveys
Test whether a policy debate, advertisement, or information campaign changed voter or consumer preferences among the same panel of respondents.
Educational Research
Determine whether students' pass/fail status on a topic changed after a teaching intervention by comparing pre-test and post-test outcomes within the same student group.
Genetic Concordance Studies
Compare genetic test results from two methods or labs applied to the same biological samples to detect systematic disagreement in classification.
A/B Testing (Marketing)
In crossover designs where the same users experience both versions of a product or webpage, McNemar's Test compares conversion rates between versions.
Vaccine and Screening Studies
Compare seroconversion or screening positivity rates in matched pairs from vaccine trials, including case-control studies with matched subjects.
Inter-Rater Agreement Research
Two raters classify the same items on a binary scale. McNemar's Test checks whether the rates of disagreement are symmetric — a different question from Cohen's Kappa.
Case Study
Vaccine Effectiveness: Matched Serology Study
In a matched cohort study, 150 pairs of vaccinated and unvaccinated individuals are tested for antibody presence (positive/negative). Cell a = 95 (both positive), b = 30 (vaccinated positive, unvaccinated negative), c = 10 (vaccinated negative, unvaccinated positive), d = 15 (both negative).
χ² = (30 − 10)² / (30 + 10) = 400 / 40 = 10.00, p = 0.0016. This is a statistically significant difference — the vaccinated group tested positive at a higher rate than the matched unvaccinated group, confirming a seropositivity advantage.
McNemar's Test in R, Python, and SPSS
# McNemar's Test in R
# Construct the 2x2 contingency table
# Rows = Condition 1, Columns = Condition 2
table_data <- matrix(
c(85, 15, 45, 55), # a, b, c, d
nrow = 2,
dimnames = list(
"Before" = c("Support", "Oppose"),
"After" = c("Support", "Oppose")
)
)
# Run McNemar's Test (with continuity correction by default)
mcnemar.test(table_data)
# Without continuity correction
mcnemar.test(table_data, correct = FALSE)
# Exact McNemar's Test (for small samples, b+c < 10)
# install.packages("exact2x2")
library(exact2x2)
mcnemar.exact(table_data)
# McNemar's Test in Python using SciPy
from scipy.stats import chi2
import numpy as np
# Cell counts: a=85, b=15, c=45, d=55
b = 15
c = 45
# Standard McNemar statistic (no continuity correction)
chi2_stat = (b - c)**2 / (b + c)
p_value = 1 - chi2.cdf(chi2_stat, df=1)
print(f"χ² = {chi2_stat:.4f}")
print(f"p-value = {p_value:.4f}")
# With continuity correction (Edwards's formula)
chi2_cc = (abs(b - c) - 1)**2 / (b + c)
p_cc = 1 - chi2.cdf(chi2_cc, df=1)
print(f"χ² (corrected) = {chi2_cc:.4f}, p = {p_cc:.4f}")
# Exact McNemar's Test via statsmodels
from statsmodels.stats.contingency_tables import mcnemar
import numpy as np
table = np.array([[85, 15], [45, 55]])
result = mcnemar(table, exact=True) # exact=False for asymptotic
print(result)
* McNemar's Test in SPSS via menus:
* Analyze → Descriptive Statistics → Crosstabs
* Move Condition1 to Row, Condition2 to Column
* Click "Statistics" → check "McNemar"
* Click Continue → OK
* SPSS crosstabs syntax for McNemar's Test:
CROSSTABS
/TABLES = Condition1 BY Condition2
/FORMAT = AVALUE TABLES
/STATISTICS = MCNEMAR
/CELLS = COUNT
/COUNT ROUND CELL.
* Output: SPSS labels the test "McNemar Test"
* and reports p-value under "Exact Sig. (2-tailed)"
Manual calculation in Excel:
Step 1: Enter b and c in cells B1 and C1
B1 = 15 (b: switched from + to −)
C1 = 45 (c: switched from − to +)
Step 2: Chi-square statistic (no correction)
D1 = (B1-C1)^2 / (B1+C1)
Result: 15.00
Step 3: p-value using CHISQ.DIST.RT()
E1 = CHISQ.DIST.RT(D1, 1)
Result: 0.000108
Step 4: With continuity correction
F1 = (ABS(B1-C1)-1)^2 / (B1+C1)
G1 = CHISQ.DIST.RT(F1, 1)
Note: Excel has no built-in McNemar function.
Use the formula approach above for manual work.
How to Report McNemar's Test in APA Format
Applied APA Example (from Example 2)
Include: (1) test name and formula type (standard or exact), (2) degrees of freedom df = 1, (3) total N, (4) χ² test statistic rounded to 2 decimal places, (5) exact p-value (or p < .001 if very small), (6) direction and magnitude of the observed change, and (7) the contingency table as a Table in the manuscript.
McNemar's Test Quick Reference
| Term | Definition / Value |
|---|---|
| Test purpose | Compare two paired proportions from the same subjects with binary outcomes |
| Null hypothesis | H₀: p_b = p_c (the probability of + → − equals the probability of − → +) |
| Alternative hypothesis | H₁: p_b ≠ p_c (two-tailed) or directional (one-tailed, rare) |
| Test statistic formula | χ² = (b − c)² / (b + c), df = 1 |
| With continuity correction | χ² = (|b − c| − 1)² / (b + c) |
| Exact version | b ~ Binomial(b + c, 0.5); p = 2 × P(X ≤ min(b, c)) |
| Critical value (α = 0.05) | χ²(1) = 3.841 |
| Critical value (α = 0.01) | χ²(1) = 6.635 |
| Critical value (α = 0.001) | χ²(1) = 10.828 |
| When to use exact test | b + c < 10 |
| Discordant pairs | Subjects who changed outcome: b (+ → −) and c (− → +) |
| Concordant pairs | Subjects who did not change: a (+ to +) and d (− to −). Not used in the test. |
| Effect size (odds ratio) | OR = c / b (ratio of the two types of discordant pairs) |
| R function | mcnemar.test(table) |
| Python (statsmodels) | mcnemar(table, exact=False) |
| SPSS menu | Analyze → Crosstabs → Statistics → McNemar |
| Named after | Quinn McNemar, American psychologist and statistician (1900–1986) |
Common Mistakes and Misconceptions
| Misconception | Wrong Thinking | Correct Approach |
|---|---|---|
| Using Chi-Square on paired data | My data is in a 2×2 table, so Chi-Square works | If the same subjects were measured twice, use McNemar's Test — paired structure requires a paired test |
| Ignoring the exact test | Chi-square approximation is always fine | When b + c < 10, the chi-square approximation breaks down; use the exact binomial version |
| Including concordant pairs | All four cells should factor into the calculation | Cells a and d (subjects who did not change) contribute zero information about directional change and are deliberately excluded |
| Interpreting significance as a large effect | p < 0.05 means a large or important difference | Statistical significance depends on sample size. Report the odds ratio (c/b) alongside the p-value to convey effect magnitude |
| Using McNemar's for 3+ time points | I can run McNemar's between each pair of time points | For three or more repeated binary measures, use Cochran's Q Test to maintain the family-wise error rate |
| Treating b and c as row/column marginals | b is the total positives at Time 2 | b is the count of subjects who switched from + (Time 1) to − (Time 2). It is one off-diagonal cell, not a marginal total |
McNemar's Test Calculator
McNemar's Test Calculator
Enter the four cell counts from your 2×2 contingency table. The calculator shows the asymptotic test statistic and p-value; if b + c < 10 it will alert you to use the exact test.
Frequently Asked Questions
χ² = (b − c)² / (b + c), which follows a chi-square distribution with 1 degree of freedom.
OR = c / b. An odds ratio greater than 1 indicates that more participants changed from the negative category to the positive category than vice versa. Researchers may also report the absolute change in the marginal proportions as an easily interpreted measure of practical significance.
b + c ≥ 25 discordant pairs for reliable large-sample inference. Formal power analysis provides a more accurate sample size estimate for a specific study.
References and Further Reading
The following primary sources and reference texts support the methods described on this page.