McNemar's Test Calculator

Test for paired categorical data.

2Γ—2 Table for Paired Data

After: +
After: βˆ’
Before: +
Before: βˆ’

b and c are the discordant pairs (changes between conditions)

Examples:

Enter the 2Γ—2 contingency table values

Use McNemar's test when you measure the same people twice with a yes/no outcome and want to know if the proportion changed. Common scenarios include testing whether opinions shifted after an event, whether a treatment changed someone's status from positive to negative (or vice versa), or whether matched pairs of subjects differ in some binary characteristic. It's the paired-data equivalent of comparing two proportions.

What Is McNemar's Test?

McNemar's test compares paired proportionsβ€”specifically for before-after designs or matched pairs with binary outcomes.

Question answered: "Did the proportion change from before to after?" or "Do matched pairs show different response rates?"

Examples:

  • Did the proportion of voters supporting a candidate change after a debate?
  • Do patients test positive at different rates before vs. after treatment?
  • In matched case-control pairs, is exposure more common in cases?

The 2Γ—2 Table for Paired Data

Unlike chi-square (which compares independent groups), McNemar's uses paired observations:

After: YesAfter: No
Before: Yesab
Before: Nocd
  • a: Yes both times (concordant)
  • d: No both times (concordant)
  • b: Changed from Yes to No (discordant)
  • c: Changed from No to Yes (discordant)

The test focuses only on discordant pairs (b and c).

The Test Statistic

Standard McNemar Test

Ο‡2=(bβˆ’c)2b+c\chi^2 = \frac{(b - c)^2}{b + c}

Follows chi-square distribution with 1 degree of freedom.

With Continuity Correction (Edwards)

Ο‡2=(∣bβˆ’cβˆ£βˆ’1)2b+c\chi^2 = \frac{(|b - c| - 1)^2}{b + c}

Recommended when expected frequencies are small.

Exact Test (Small Samples)

When b+c<25b + c < 25, use exact binomial test:

Under null hypothesis, b∼Binomial(b+c,0.5)b \sim \text{Binomial}(b + c, 0.5)

Example Calculation

Scenario: 100 voters surveyed before and after a debate.

After: SupportAfter: Oppose
Before: Support4010
Before: Oppose2525
  • a = 40 (supported both times)
  • b = 10 (switched from support to oppose)
  • c = 25 (switched from oppose to support)
  • d = 25 (opposed both times)

Discordant pairs: b + c = 35

Test statistic:

Ο‡2=(10βˆ’25)235=22535=6.43\chi^2 = \frac{(10 - 25)^2}{35} = \frac{225}{35} = 6.43

P-value: For Ο‡2=6.43\chi^2 = 6.43 with df = 1: p=0.011p = 0.011

Conclusion: Significant change in support (p=0.011p = 0.011). Support increased (more switched to support than away from it).

Interpretation

Significant Result

The proportion changed between conditions (or cases differ from controls in matched pairs).

Direction: Compare b vs c

  • If c > b: Proportion increased
  • If b > c: Proportion decreased

Non-Significant Result

No evidence of change in proportion.

Confidence Interval for Difference

The difference in proportions:

p^2βˆ’p^1=cβˆ’bn\hat{p}_2 - \hat{p}_1 = \frac{c - b}{n}

Standard error:

SE=b+cβˆ’(bβˆ’c)2/nnSE = \frac{\sqrt{b + c - (b-c)^2/n}}{n}

95% CI:

(p^2βˆ’p^1)Β±1.96Γ—SE(\hat{p}_2 - \hat{p}_1) \pm 1.96 \times SE

From example:

  • Proportion change: (25 - 10)/100 = 0.15 (15% increase)
  • SE β‰ˆ 0.056
  • 95% CI: [0.04, 0.26]

Odds Ratio for Matched Pairs

OR=cbOR = \frac{c}{b}

From example: OR = 25/10 = 2.5

Interpretation: "Voters were 2.5 times more likely to switch to support than away from support."

Confidence Interval for OR

95% CI=OR1Β±1.96/b+c95\% \text{ CI} = OR^{1 \pm 1.96/\sqrt{b+c}}

Applications

Medical Research

Treatment response:

After: Symptom-FreeAfter: Symptoms
Before: Symptom-Free53
Before: Symptoms4250

Did treatment reduce symptoms? Test on b = 3, c = 42.

Matched Case-Control Studies

Exposure in matched pairs:

Control: ExposedControl: Not Exposed
Case: Exposed2035
Case: Not Exposed1035

Is exposure more common in cases? OR = 35/10 = 3.5.

Survey Research

Opinion change:

Pre-post surveys where the same individuals are measured twice.

Diagnostic Testing

Agreement between tests:

Test B: PositiveTest B: Negative
Test A: Positive455
Test A: Negative1535

Do the tests have different positive rates? Focus on discordant pairs.

Exact McNemar Test

For small samples (b + c < 25), use exact binomial test:

p=2Γ—βˆ‘k=0min⁑(b,c)(b+ck)(0.5)b+cp = 2 \times \sum_{k=0}^{\min(b,c)} \binom{b+c}{k}(0.5)^{b+c}

Or use statistical software for the exact p-value.

McNemar-Bowker Test (Extensions)

For tables larger than 2Γ—2 (multiple categories), the McNemar-Bowker test of symmetry extends the concept.

Tests whether pij=pjip_{ij} = p_{ji} for all pairs of categories.

Assumptions

Paired/Matched Data

Each observation in "before" corresponds to exactly one observation in "after."

Binary Outcome

The outcome variable has exactly two categories.

Independent Pairs

Different pairs are independent of each other.

Random Sampling

Pairs are randomly selected from the population.

Common Mistakes

Using Chi-Square Instead

Standard chi-square test treats data as independent. For paired data, you must use McNemar's test.

Including Concordant Pairs

Only discordant pairs (b and c) contribute information. Concordant pairs (a and d) don't affect the test.

Small Sample Without Exact Test

When b + c < 25, the chi-square approximation is poor. Use exact test.

Confusing Direction

b = "changed from yes to no" and c = "changed from no to yes." Be clear about which is which.

Comparison with Related Tests

TestUse Case
McNemar'sPaired binary data
Chi-squareIndependent binary data
Cochran's QMultiple paired binary measurements
Sign testPaired ordinal/continuous data
Paired t-testPaired continuous data

Effect Size

Odds Ratio

OR=cbOR = \frac{c}{b}

ORInterpretation
1No difference
2-3Moderate effect
> 3Large effect

Difference in Proportions

Ξ”p=cβˆ’bn\Delta p = \frac{c - b}{n}

Directly interpretable as percentage point change.

Reporting Results

APA format:

"McNemar's test indicated a significant increase in support for the candidate after the debate, χ²(1) = 6.43, p = .011. Support increased by 15 percentage points (95% CI [4%, 26%]), with an odds ratio of 2.5 for switching to support versus switching away."

Historical Context

Quinn McNemar introduced this test in 1947 for psychological research involving before-after measurements on the same subjects.

The test filled an important gapβ€”researchers needed a way to analyze paired categorical data that respects the dependence structure.

Related Calculations

Summary

McNemar's test compares paired binary outcomes, focusing on discordant pairs where the response changed. Calculate Ο‡2=(bβˆ’c)2/(b+c)\chi^2 = (b-c)^2/(b+c) where b and c are the discordant pair counts. Use exact test for small samples (b + c < 25). Report the chi-square statistic, p-value, proportion difference with confidence interval, and odds ratio. The test is essential for before-after studies and matched case-control designs with binary outcomes.