UK-based online statistics and data analysis support for USA, UK, and international clients. No exams, no impersonation, no fabricated data.
Chi-Square and Categorical Data Tests

McNemar’s Test: Formula, Interpretation, Calculator, Python, R, SPSS and Excel Guide

Paired binary inference for before-and-after or matched outcomes McNemar’s Test: Formula, Interpretation, Calculator, Python, R, SPSS and Excel Guide McNemar’s Test compares two correlated binary classifications...

Statistics guide Ethical learning support SPSS/R/Python/Excel friendly
McNemar’s Test: Formula, Interpretation, Calculator, Python, R, SPSS and Excel Guide


Paired binary inference for before-and-after or matched outcomes

McNemar’s Test: Formula, Interpretation, Calculator, Python, R, SPSS and Excel Guide

McNemar’s Test compares two correlated binary classifications recorded on the same people or matched pairs. This complete guide explains the null hypothesis, exact binomial method, uncorrected and continuity-corrected formulas, assumptions, calculator logic, effect estimates, APA reporting, Python and R visual evidence, SPSS and Excel workflows, and downloadable reports through a verified analysis of G2 and G3 pass status for 649 students.

Paired 2 × 2 table
649 complete pairs
67 discordant pairs
Exact p = 2.146 × 10−8

McNemar’s Test Model Overview

McNemar’s Test is a nonparametric test for paired nominal data with exactly two categories. It is designed for situations in which every observational unit contributes two linked binary outcomes: before versus after, method A versus method B, left side versus right side, matched case versus matched control, or two diagnostic classifications applied to the same participant.

The test does not ask whether the two variables are independent. It asks whether the two marginal proportions are equal, which is equivalent in a paired 2 × 2 table to asking whether the two types of disagreement occur with equal probability. For that reason, McNemar’s Test is often described as a test of marginal homogeneity or symmetry of discordant pairs.

What Question Does McNemar’s Test Answer?

In the worked analysis, the same 649 students have a G2 grade and a G3 grade. Each grade is converted to pass/fail status using the same threshold: a grade of 10 or higher is coded as pass. McNemar’s Test asks whether changing from G2 fail to G3 pass is as likely as changing from G2 pass to G3 fail.

H0:P(G2 fail, G3 pass) = P(G2 pass, G3 fail)
H1:P(G2 fail, G3 pass) ≠ P(G2 pass, G3 fail)

Why Only the Discordant Pairs Determine the Test

The paired table contains two concordant cells on the diagonal and two discordant cells off the diagonal. Concordant pairs—fail/fail and pass/pass—describe stability or agreement, but they do not indicate a direction of change. Only the off-diagonal counts distinguish improvement from deterioration, so only those counts enter the McNemar statistic and exact binomial probability.

Worked Example at a Glance

The table contains 89 fail/fail students, 56 fail-to-pass students, 11 pass-to-fail students and 493 pass/pass students. The 67 discordant pairs are strongly unbalanced: 83.58% moved from fail to pass and 16.42% moved from pass to fail. The exact two-sided p-value is 2.145796 × 10−8. The continuity-corrected statistic is χ2(1) = 28.8955, with p = 7.638930 × 10−8.

When McNemar’s Test Is Not the Right Method

McNemar’s Test is not appropriate for two independent groups, for outcomes with three or more categories, for three or more repeated binary measurements, or when covariate adjustment is required. Independent groups require procedures such as the Chi-Square Test of Independence, while paired multi-category tables require McNemar–Bowker or Bowker symmetry methods. Three or more related binary measurements require Cochran’s Q Test.

Overview conclusion: the G2 and G3 pass-status margins are not symmetric. Upward change from fail to pass occurred much more frequently than downward change from pass to fail. The result describes a directional paired shift, not merely a high or low level of agreement.
AdvertisementGoogle AdSense top placement reserved here

Quick Answer: McNemar’s Test Result

The exact two-sided McNemar’s Test is the primary analysis because it treats the 67 discordant pairs as a binomial outcome under a 0.50 null probability. The continuity-corrected and uncorrected chi-square forms are reported as standard asymptotic comparisons.

Fail → pass56
Pass → fail11
Exact statistic11
Exact p-value2.146 × 10−8

Test Summary

  • Procedure: two-sided exact McNemar’s Test
  • Paired observations: 649
  • Discordant total: 67
  • Exact statistic: min(56, 11) = 11
  • Decision at α = .05: reject H0

Substantive Meaning

  • 56 students changed from fail to pass.
  • 11 students changed from pass to fail.
  • Net increase: 45 passes.
  • Marginal increase: 45/649 = 6.93 percentage points.
  • Discordant matched odds ratio: 56/11 = 5.09.
Best interpretation: among students whose pass status changed, a fail-to-pass transition was approximately 5.09 times as common as a pass-to-fail transition. The exact p-value shows that a 56-to-11 imbalance is extraordinarily unlikely if the two transition directions are equally probable.
Do not interpret McNemar’s Test as an agreement test: 582 pairs were concordant, but the McNemar p-value is driven only by the 67 discordant pairs. Agreement, stability and marginal change are related descriptions but answer different statistical questions.

Table of Contents

  1. Research question, hypotheses and paired design
  2. When to use McNemar’s Test
  3. McNemar’s Test formula and manual calculation
  4. Variables and data dictionary
  5. Worked paired 2 × 2 table and complete results
  6. Assumptions and data requirements
  7. Exact, corrected, uncorrected and related tests
  8. McNemar’s Test calculator workflow
  9. Six Python chart interpretations
  10. Six R chart interpretations in paired rows
  11. Python, R, SPSS and Excel workflows
  12. Expandable software code
  13. Advanced interpretation and edge cases
  14. APA reporting for McNemar’s Test
  15. Common mistakes and corrections
  16. Analysis and reporting checklist
  17. Reports and worked Excel download
  18. Related Salar Cafe guides
  19. Frequently asked questions
  20. Conclusion

Research Question, Hypotheses and Paired Data Design

First paired measureG2 pass status: 0 = G2 < 10; 1 = G2 ≥ 10.
Second paired measureG3 pass status: 0 = G3 < 10; 1 = G3 ≥ 10.
Inferential targetEquality of the two discordant transition probabilities.

Research Question

Does the probability of changing from G2 fail to G3 pass equal the probability of changing from G2 pass to G3 fail for the same students?

Null and Alternative Hypotheses

HypothesisStatistical statementMeaning
Null hypothesisH0: p01 = p10The two discordant transition probabilities are equal.
Two-sided alternativeH1: p01 ≠ p10Directional paired change is asymmetric.
Possible directional alternativeH1: p01 > p10Fail-to-pass transitions are more common; use only when prespecified.

Why the Observations Are Paired

G2 and G3 belong to the same student. The two binary classifications are therefore correlated. An independent-proportions test would ignore the link and treat 649 first measurements and 649 second measurements as though they came from unrelated people. McNemar’s Test preserves the pair identifier and uses the transition table.

Methods Statement

Reusable design statement: “McNemar’s Test was used to compare paired binary G2 and G3 pass classifications for the same 649 students. Inference was based on the two off-diagonal discordant transition counts.”

Before running the test, define the two measurement occasions, the coding of the binary event, the direction of the rows and columns, and whether the alternative is two-sided or directional. Review Null and Alternative Hypotheses and Type I and Type II Error when planning the decision rule.

When to Use McNemar’s Test

Use McNemar’s Test When

  • The outcome has exactly two categories.
  • The same participants are classified twice.
  • Pairs are created through explicit matching.
  • The question concerns marginal change or directional discordance.
  • Each complete pair contributes one first and one second classification.
  • Pairs are independent of other pairs.
  • A before/after, diagnostic-method or matched-case design is used.
  • The analysis does not require covariate adjustment.

Choose Another Method When

  • The two groups are independent rather than paired.
  • The outcome has more than two categories.
  • There are three or more repeated binary measurements.
  • The response is continuous, count or ordinal rather than binary.
  • Pairs are nested inside schools, clinics or households.
  • Covariates, interactions or subject effects must be modeled.
  • The main question is inter-rater agreement rather than marginal change.
  • The data contain unpaired observations that cannot be reconciled.

Simple Test-Selection Logic

Question 1Are observations paired?

If no, use an independent-sample categorical procedure.

Question 2Is the outcome binary?

If yes, McNemar’s Test may be appropriate.

Question 3Two or more occasions?

Use McNemar for two and Cochran’s Q for three or more.

Typical Applications

Before and after

Smoking status, treatment response, policy support or a yes/no symptom recorded before and after an intervention.

Two diagnostic methods

Positive/negative classifications from two tests applied to the same participants.

Matched pairs

Cases matched to controls, twins, paired body sites or deliberately matched experimental units.

McNemar’s Test Versus Independent-Proportion Procedures

A two-proportion z test, Fisher’s Exact Test and an ordinary Chi-Square Test of Independence assume independent groups. They are not substitutes for McNemar’s Test when both classifications belong to the same person or matched pair.

McNemar’s Test Versus Bowker’s Test

McNemar’s Test is the 2 × 2 form of a broader symmetry-testing idea. For a paired square table with three or more categories, McNemar–Bowker or Bowker’s Test of Symmetry compares all corresponding off-diagonal pairs.

McNemar’s Test Formula and Manual Calculation

Write the first binary classification in rows and the second classification in columns. Label the discordant off-diagonal counts b and c. The diagonal counts a and d are retained for descriptive reporting but do not enter the basic McNemar formulas.

First measurementSecond = 0Second = 1Row total
First = 0a = concordant 0/0b = discordant 0→1a + b
First = 1c = discordant 1→0d = concordant 1/1c + d
Column totala + cb + dN

Step 1: Identify the Discordant Counts

b = 56 = G2 fail → G3 pass
c = 11 = G2 pass → G3 fail
b + c = 67 discordant pairs

Step 2: Exact Binomial McNemar’s Test

Under H0, each discordant pair has probability .50 of appearing in either direction. Conditional on the observed discordant total, the smaller off-diagonal count follows a binomial distribution.

X = min(b,c) = 11,X ~ Binomial(67, 0.50)
pexact, two-sided = 2 × P(X ≤ 11) = 2.145796 × 10−8

The exact p-value can also be described as the probability, under a fair 50/50 discordant split, of observing an imbalance at least as extreme as 56 versus 11 in either direction.

Step 3: Uncorrected Asymptotic Statistic

χ2 = (b − c)2b + c
χ2 = (56 − 11)2/67 = 30.2238806

With one degree of freedom, the uncorrected asymptotic p-value is 3.849404 × 10−8.

Step 4: Continuity-Corrected Statistic

χ2cc = (|b − c| − 1)2b + c
χ2cc = (45 − 1)2/67 = 28.8955224

The continuity-corrected p-value is 7.638930 × 10−8. It is larger than the uncorrected p-value because the correction reduces the statistic, but both forms reach the same substantive conclusion.

Step 5: Discordant Matched Odds Ratio

ORmatched = b/c = 56/11 = 5.090909

The approximate log-scale 95% confidence interval is 2.6673 to 9.7168. An exact conditional interval obtained by inverting the discordant binomial proportion is approximately 2.6390 to 10.7768. Always name the interval method because exact and asymptotic endpoints differ.

Step 6: Marginal Proportions and Paired Difference

G2 pass proportion = (c + d)/N = 504/649 = 0.776579
G3 pass proportion = (b + d)/N = 549/649 = 0.845917
Paired difference = (b − c)/N = 45/649 = 0.069337

The pass proportion increased by 6.93 percentage points. A normal-approximation 95% confidence interval for the paired marginal difference is approximately 4.52 to 9.35 percentage points. This magnitude estimate complements the hypothesis test.

Calculation conclusion: the exact, uncorrected and continuity-corrected versions all show strong evidence against equal discordant transition probabilities. The direction is positive because fail-to-pass changes greatly outnumber pass-to-fail changes.

Variables and Data Dictionary

VariableRoleCodingNMeaning in the analysis
G2Original first gradeGrade from 0 to 19649Source variable for the first binary status.
G3Original second gradeGrade from 0 to 19649Source variable for the second binary status.
G2 passFirst paired binary classification0 if G2 < 10; 1 if G2 ≥ 10649Row variable in the paired table.
G3 passSecond paired binary classification0 if G3 < 10; 1 if G3 ≥ 10649Column variable in the paired table.
Pair identifierLinking fieldOne unique record per student649Ensures the two classifications remain paired.

Observed Paired 2 × 2 Table

G2 pass statusG3 fail (0)G3 pass (1)Row total
G2 fail (0)8956145
G2 pass (1)11493504
Column total100549649

Transition Categories

TransitionCountShare of all pairsRole
Fail → fail8913.71%Concordant; descriptive only.
Fail → pass568.63%Discordant count b.
Pass → fail111.69%Discordant count c.
Pass → pass49375.96%Concordant; descriptive only.
Coding safeguard: reversing the time order swaps b and c. The two-sided p-value remains unchanged, but the sign of the paired difference and the direction of the matched odds ratio reverse. State the row and column order in every formal report.

Worked Paired 2 × 2 Table and Complete Results

Concordant pairs582
Discordant pairs67
Upward share83.58%
Exact p2.146e−8
Corrected χ²28.8955
Matched OR5.0909

Primary Inferential Results

MethodStatisticReference distributionP-valueDecision at α = .05
Exact McNemar’s Testmin(b,c) = 11Binomial(67, .50)2.145796 × 10−8Reject H0
Continuity-corrected McNemarχ2 = 28.895522χ2(1)7.638930 × 10−8Reject H0
Uncorrected McNemarχ2 = 30.223881χ2(1)3.849404 × 10−8Reject H0

Magnitude and Descriptive Results

MeasureEstimate95% intervalInterpretation
G2 pass proportion0.776579504 of 649 students passed at G2.
G3 pass proportion0.845917549 of 649 students passed at G3.
Paired marginal difference, G3 − G20.069337Approx. [0.04520, 0.09347]Pass status increased by 6.93 percentage points.
Discordant matched odds ratio, b/c5.090909Approx. [2.6673, 9.7168]Fail-to-pass changes were about five times as common.
Discordant upward probability56/67 = 0.835821Exact [0.72520, 0.91509]Among changers, 83.58% moved upward.
Concordance proportion582/649 = 0.896764Most classifications were unchanged.

Statistical Interpretation

The exact two-sided p-value is much smaller than .05, .01 and .001. The null hypothesis of equal discordant transition probabilities is rejected. The evidence is not merely a threshold crossing; the observed discordant split is 56 versus 11, far from the 33.5 versus 33.5 balance expected under H0.

Practical Interpretation

The G3 pass rate is 6.93 percentage points higher than the G2 pass rate. Among the 67 students whose status changed, a fail-to-pass transition was approximately 5.09 times as frequent as a pass-to-fail transition. This expresses both the overall margin change and the direction within discordant pairs.

Agreement Versus Change

Overall concordance is high at 89.68%, largely because 493 students passed at both occasions. High agreement does not contradict the significant McNemar result. Agreement summarizes how many pairs match; McNemar’s Test examines whether the mismatches are directionally balanced. For a direct agreement analysis, use Cohen’s Kappa alongside the transition table rather than replacing McNemar’s Test.

Result summary: pass status improved more often than it deteriorated. The exact McNemar result was highly significant, the continuity-corrected statistic was χ2(1) = 28.90, and the net increase was 45 passes or 6.93 percentage points.
AdvertisementGoogle AdSense placement reserved after the Results section

McNemar’s Test Assumptions and Data Requirements

McNemar’s Test has fewer distributional assumptions than a parametric paired test, but it still depends on the design, coding and independence structure. The test should not be described as assumption-free.

Assumption or requirementWhat it meansWorked example status
Paired observationsEach row contains two linked classifications from the same participant or matched pair.Met: G2 and G3 belong to the same student.
Binary outcome at both occasionsEach classification has exactly two mutually exclusive categories.Met: fail versus pass using threshold 10.
Same category definitionThe meaning of 0 and 1 is consistent across the two measurements.Met: the same pass threshold is used.
Independence between pairsOne participant’s pair should not determine another participant’s pair.Assumed for the 649 students.
Complete pairingThe 2 × 2 table should be based on pairs with both classifications observed.Met in the worked workbook: N = 649 complete pairs.
Prespecified alternativeTwo-sided or directional testing should be chosen before examining the split.Two-sided is used as the primary analysis.
Adequate discordant count for approximationThe chi-square version needs enough discordant pairs; exact inference avoids this approximation.67 discordant pairs support both exact and asymptotic comparisons.

What Does Not Need to Be Assumed?

McNemar’s Test does not require normally distributed measurements, equal variances, a continuous outcome, or equal numbers in the two binary categories. It does require valid pairing and binary coding.

Why the Number of Discordant Pairs Matters

The effective information for the test is b + c, not the full N. A study may contain thousands of concordant pairs but very few discordant pairs. In that situation, the exact binomial version is more defensible than relying on the chi-square approximation.

Missing Data

A participant missing G2 or G3 cannot be placed in the paired transition table. Excluding incomplete pairs is complete-pair analysis and can be biased if missingness is related to outcome change. Report how many pairs were excluded and consider a model-based strategy when missingness is substantial.

Restriction: do not create pseudo-pairs by matching aggregate counts after the individual link has been lost. McNemar’s Test requires the actual pair-level transition structure.

Exact, Corrected, Uncorrected and Related-Test Comparisons

Exact McNemar

Uses Binomial(b+c, .50) for the discordant split.

Corrected McNemar

Uses a one-unit continuity correction in the chi-square statistic.

Uncorrected McNemar

Uses the asymptotic chi-square formula without continuity correction.

Mid-p variant

Reduces exact-test conservatism but is not the ordinary exact p-value.

Numerical Comparison

MethodStatistic or tailP-valueWhen emphasized
Exact two-sided McNemar11 in the smaller discordant direction2.1458 × 10−8Primary finite-sample result.
Continuity-corrected chi-square28.89557.6389 × 10−8Common conservative asymptotic form.
Uncorrected chi-square30.22393.8494 × 10−8Large-discordance approximation.

McNemar’s Test Versus Chi-Square Independence

The ordinary chi-square test of independence evaluates association between two categorical variables measured on independent observations. McNemar’s Test evaluates marginal change within pairs. Applying an independence test to the current transition table ignores the repeated-measure link and answers a different question.

McNemar’s Test Versus Fisher’s Exact Test

Fisher’s Exact Test is an exact procedure for an independent 2 × 2 table with conditioned margins. It does not preserve the paired transition structure. The exact McNemar procedure is also based on an exact distribution, but it conditions on the total number of discordant pairs and evaluates their directional split.

McNemar’s Test Versus Paired t Test or Wilcoxon Signed-Rank Test

A paired t test compares the mean of a quantitative paired difference; the Wilcoxon signed-rank test evaluates a paired ordinal or continuous shift. McNemar’s Test is the corresponding binary paired procedure. Converting a rich quantitative variable to pass/fail may answer a useful threshold question but loses information about the size of grade changes.

McNemar’s Test Versus Agreement Measures

Cohen’s Kappa estimates agreement beyond chance. McNemar’s Test evaluates marginal asymmetry. A table can show high kappa and a significant McNemar result, or low kappa and a nonsignificant McNemar result, because the statistics target different properties.

McNemar’s Test Versus Cochran’s Q

McNemar’s Test compares two related binary conditions. Cochran’s Q Test extends the same repeated-binary logic to three or more conditions or time points. A significant Cochran’s Q result is often followed by pairwise McNemar comparisons with multiplicity adjustment.

McNemar’s Test Versus Bowker Symmetry

McNemar’s Test is appropriate when each paired classification has two categories. Bowker’s symmetry test handles paired square tables with three or more categories by comparing each off-diagonal cell with its reflected counterpart.

Selection rule: choose the procedure from the sampling design and outcome scale before looking at p-values. Do not run several tests and report only the smallest result.

McNemar’s Test Calculator: Step-by-Step Workflow

A reliable McNemar’s Test calculator must accept a paired 2 × 2 transition table and identify the two discordant cells. A calculator that treats all four cells as independent frequencies is not performing the paired test.

Calculator Inputs for the Worked Example

InputValueMeaning
First fail, second fail89Concordant negative pairs.
First fail, second pass56Discordant upward transitions, b.
First pass, second fail11Discordant downward transitions, c.
First pass, second pass493Concordant positive pairs.
AlternativeTwo-sidedEither transition direction can be more common.
Primary methodExact binomialFinite-sample two-sided p-value.
Alpha0.05Prespecified decision threshold.

Calculator Step 1: Confirm the Table Orientation

Rows represent G2 and columns represent G3. Reversing the two occasions leaves the exact two-sided p-value unchanged but reverses the direction of the matched odds ratio and the wording of improvement versus deterioration.

Calculator Step 2: Confirm the Discordant Cells

The calculator should identify 56 and 11 as b and c. The diagonal counts 89 and 493 must not enter the test statistic. They remain important for overall sample description and agreement reporting.

Calculator Step 3: Choose Exact or Asymptotic Inference

Select the exact binomial result when the discordant total is small, when an exact finite-sample result is desired, or when the analysis plan specifies it. With 67 discordant pairs, both exact and chi-square versions are stable and provide useful cross-checks.

Calculator Step 4: Verify the Formulas

b + c67
min(b,c)11
Exact p2.1458e−8
Corrected χ²28.8955
Uncorrected χ²30.2239
b/c5.0909

Calculator Step 5: Report Proportions and Direction

The G2 pass proportion is 77.66%, the G3 pass proportion is 84.59%, and the paired increase is 6.93 percentage points. Report these quantities with the transition counts and p-value. “Significant” alone does not tell the reader what changed.

How to Find the Proportion from McNemar’s Test

McNemar’s Test itself is based on discordant counts, but several proportions are useful: the first marginal proportion, the second marginal proportion, the proportion of all pairs that are discordant, and the proportion of discordant pairs moving in the focal direction. For this example, 56/67 = 83.58% of changers moved from fail to pass.

Expected calculator target: b = 56, c = 11, exact p = 2.145796 × 10−8, corrected χ2 = 28.895522 and corrected p = 7.638930 × 10−8.

Six Python McNemar’s Test Chart Interpretations

The Python workflow contains six dedicated figures: the paired transition table, discordant counts, null distribution, two-sided rejection region, method comparison and result summary. Each Python asset supplied for this post is displayed in this section.

Python verification: the six figures use the observed paired table [[89, 56], [11, 493]], the 67 discordant pairs, exact two-sided p = 2.145796 × 10−8 and continuity-corrected χ2(1) = 28.895522.

Chart 1: Paired G2-by-G3 Transition Table Python

McNemar's Test paired 2 by 2 table for G2 and G3 pass status
Observed paired counts: 89 fail/fail, 56 fail-to-pass, 11 pass-to-fail and 493 pass/pass.
Pattern

The diagonal contains 582 concordant pairs, while the off-diagonal contains 67 discordant pairs.

Key values

Fail/fail = 89, fail/pass = 56, pass/fail = 11, pass/pass = 493.

Interpretation

Most students remain in the same status, but the relatively few changes are strongly directional.

Why it matters

The table preserves pairing and prevents an incorrect independent-samples analysis.

Next step: isolate the 56 and 11 discordant cells.

Chart 2: Discordant Transition Counts Python

McNemar's Test discordant fail-to-pass and pass-to-fail counts
Direct comparison of the two transition directions that determine McNemar’s Test.
Pattern

Fail-to-pass transitions greatly exceed pass-to-fail transitions.

Key values

b = 56, c = 11, b + c = 67, b/c = 5.09.

Interpretation

Among changers, 83.58% move upward and 16.42% move downward.

Why it matters

The null hypothesis expects the discordant total to split equally between the two directions.

Next step: compare the observed smaller count with Binomial(67, .50).

Chart 3: Exact Null Distribution Python

McNemar's Test Python exact null binomial distribution for 67 discordant pairs
Binomial null distribution centered near 33 or 34 discordant pairs in each direction.
Pattern

The observed smaller count of 11 lies far into the lower tail of the null distribution.

Key values

X ~ Binomial(67, .50); observed X = 11.

Interpretation

A balanced discordant split would normally produce counts near the center, not 11 versus 56.

Why it matters

The exact reference distribution requires no large-sample chi-square approximation.

Next step: include equally extreme outcomes in both tails for a two-sided test.

Chart 4: Two-Sided Exact Rejection Region Python

McNemar's Test Python two-sided exact rejection region
Both tails are included because either discordant direction could be more common.
Pattern

The observed lower-tail count is mirrored by an equally extreme upper-tail region.

Key values

Two-sided p = 2 × P(X ≤ 11) = 2.145796 × 10−8.

Interpretation

The two-sided alternative protects against selecting the direction only after seeing the data.

Why it matters

One-sided and two-sided p-values answer different prespecified hypotheses.

Next step: compare exact and chi-square versions for numerical robustness.

Chart 5: Exact and Chi-Square Method Comparison Python

McNemar's Test Python exact corrected and uncorrected method comparison
Exact, continuity-corrected and uncorrected p-values are compared on the same scale.
Pattern

All accepted McNemar variants return extremely small p-values.

Key values

Exact = 2.15e−8; corrected = 7.64e−8; uncorrected = 3.85e−8.

Interpretation

The continuity correction is more conservative, but it does not change the decision.

Why it matters

Method choice is transparent and the conclusion is robust rather than dependent on one implementation.

Next step: report the chosen primary version by name.

Chart 6: McNemar’s Test Result Summary Python

McNemar's Test result summary with counts p value and chi-square statistic
Integrated summary of direction, magnitude, exact inference and corrected chi-square output.
Pattern

The final panel combines the 56-to-11 split with the exact and asymptotic results.

Key values

Net increase = 45; paired margin change = +6.93 percentage points.

Interpretation

The inferential rejection corresponds to a visible and interpretable direction of change.

Why it matters

The panel discourages reporting a p-value without counts and effect estimates.

Next step: validate the exact null and concordance structure in R.
AdvertisementGoogle AdSense placement reserved after the Python charts

R McNemar’s Test Results: All Six R Charts

This section follows the uploaded sample post format and displays every R chart as a separate figure. None is shared with, merged into, or omitted because of the Python section.

R asset check: 6 of 6 R chart files are included below: R Chart 1 paired table; R Chart 2 discordant counts; R Chart 3 exact null; R Chart 4 concordant/discordant; R Chart 5 exact/asymptotic; R Chart 6 result summary.
R Charts 1–2: Paired table and discordant counts

R Chart 1: Paired Table

R Chart 1 paired 2 by 2 table for McNemar's Test
R paired table showing fail/fail = 89, fail/pass = 56, pass/fail = 11 and pass/pass = 493.

R Chart 2: Discordant Counts

R Chart 2 discordant counts for McNemar's Test
R comparison of the 56 fail-to-pass and 11 pass-to-fail discordant pairs.
R chart 1 interpretation

The complete paired table contains 649 matched records. The concordant cells total 582 and the discordant cells total 67.

R chart 2 interpretation

McNemar’s Test uses the directional imbalance between 56 and 11. The discordant-pair odds ratio is 56/11 = 5.0909.

R Charts 3–4: Exact null and concordant/discordant structure

R Chart 3: Exact Null Distribution

R Chart 3 exact null distribution for McNemar's Test
R exact-binomial null distribution for the 67 discordant pairs.

R Chart 4: Concordant and Discordant Pairs

R Chart 4 concordant and discordant counts for McNemar's Test
R comparison of 582 concordant and 67 discordant pairs.
R chart 3 interpretation

Under marginal homogeneity, the two directions are equally likely among discordant pairs. The exact two-sided p-value is 2.145796 × 10−8.

R chart 4 interpretation

Concordant pairs describe stability, while the asymmetry within the 67 discordant pairs determines the McNemar result.

R Charts 5–6: Method comparison and result summary

R Chart 5: Exact and Asymptotic Results

R Chart 5 exact and asymptotic McNemar comparison
R comparison of exact, continuity-corrected and uncorrected McNemar results.

R Chart 6: Result Summary

R Chart 6 McNemar's Test result summary
R summary of direction, magnitude and inferential evidence.
R chart 5 interpretation

All reported procedures reject marginal homogeneity. The continuity-corrected statistic is χ²(1) = 28.8955, with p < .001.

R chart 6 interpretation

The post-period pass rate is higher by 6.93 percentage points, with substantially more fail-to-pass than pass-to-fail transitions.

McNemar’s Test in Python, R, SPSS and Excel

McNemar’s Test in Python

Python can build the paired crosstab, run an exact McNemar procedure and calculate comparison statistics. Keep one row per participant so pairing is never lost.

  • Create binary G2 and G3 pass variables.
  • Build the transition table in the intended row/column order.
  • Run the exact version as the primary analysis.
  • Run corrected and uncorrected versions for comparison.
  • Calculate marginal proportions, paired difference and b/c.

Worked target: table [[89, 56], [11, 493]], exact statistic 11 and p = 2.145796 × 10−8.

McNemar’s Test in R

Base R provides mcnemar.test() for the chi-square form. The exact p-value can be obtained directly from the discordant counts with binom.test().

  • Build a 2 × 2 table with identical category order.
  • Use correct = TRUE for continuity correction.
  • Use correct = FALSE for the uncorrected statistic.
  • Use binom.test(b, b+c, p=.5) for exact inference.
  • Report row and column direction.

McNemar’s Test in SPSS

SPSS can run McNemar’s Test for paired dichotomous variables through the legacy nonparametric tests workflow or equivalent syntax. The data should remain in wide paired form: one row per participant and one binary variable for each occasion.

  • Verify that both variables use the same 0/1 coding.
  • Request frequencies or a crosstab to verify the four cells.
  • Run McNemar on the paired variable list.
  • Check whether the output reports exact or asymptotic significance.
  • Export the output and report transition counts separately.

McNemar’s Test in Excel

Excel can reproduce the full paired table, exact p-value, corrected and uncorrected statistics, margins and effect estimates with transparent formulas.

  • Use COUNTIFS to calculate the four transitions.
  • Use BINOM.DIST for the exact two-sided tail.
  • Use CHISQ.DIST.RT for the asymptotic p-values.
  • Calculate b/c and (b−c)/N.
  • Audit formulas against Python, R or SPSS.

Software Agreement in the Worked Analysis

OutputPythonRSPSSExcel
Paired table89, 56, 11, 493SameSame after coding checkSame via COUNTIFS
Exact p-value2.145796e−82.145796e−8Verify requested exact output2.145796e−8
Corrected χ²28.89552228.895522Expected standard output28.895522
Direction56 > 1156 > 11Same after table orientation56 > 11

Expandable McNemar’s Test Code

The code is collapsed by default so the public article remains readable. Expand only the software block you need.

Python code for exact, corrected and uncorrected McNemar’s Test
import numpy as np
from scipy.stats import binomtest, chi2
from statsmodels.stats.contingency_tables import mcnemar

# Rows: G2 fail, G2 pass
# Columns: G3 fail, G3 pass
table = np.array([[89, 56],
                  [11, 493]])

b = int(table[0, 1])
c = int(table[1, 0])
n = int(table.sum())

exact = mcnemar(table, exact=True)
corrected = mcnemar(table, exact=False, correction=True)
uncorrected = mcnemar(table, exact=False, correction=False)

# Independent verification of the exact two-sided tail
exact_check = binomtest(b, b + c, p=0.5, alternative="two-sided")

p_g2 = (table[1, 0] + table[1, 1]) / n
p_g3 = (table[0, 1] + table[1, 1]) / n
paired_difference = (b - c) / n
matched_or = b / c

print(table)
print(exact.statistic, exact.pvalue)
print(corrected.statistic, corrected.pvalue)
print(uncorrected.statistic, uncorrected.pvalue)
print(exact_check.pvalue)
print(p_g2, p_g3, paired_difference, matched_or)
R code for exact and chi-square McNemar’s Test
tab <- matrix(
  c(89, 56,
    11, 493),
  nrow = 2,
  byrow = TRUE,
  dimnames = list(
    G2 = c("Fail", "Pass"),
    G3 = c("Fail", "Pass")
  )
)

b <- tab["Fail", "Pass"]
c <- tab["Pass", "Fail"]
N <- sum(tab)

exact_result <- binom.test(
  x = b,
  n = b + c,
  p = 0.5,
  alternative = "two.sided"
)

corrected_result <- mcnemar.test(tab, correct = TRUE)
uncorrected_result <- mcnemar.test(tab, correct = FALSE)

p_g2 <- sum(tab["Pass", ]) / N
p_g3 <- sum(tab[, "Pass"]) / N
paired_difference <- (b - c) / N
matched_or <- b / c

tab
exact_result
corrected_result
uncorrected_result
c(p_g2 = p_g2,
  p_g3 = p_g3,
  paired_difference = paired_difference,
  matched_or = matched_or)
SPSS syntax outline
* G2_pass and G3_pass must be coded 0/1 for the same cases.
FREQUENCIES VARIABLES=G2_pass G3_pass.
CROSSTABS
  /TABLES=G2_pass BY G3_pass
  /CELLS=COUNT ROW COLUMN TOTAL.

NPAR TESTS
  /MCNEMAR=G2_pass WITH G3_pass (PAIRED)
  /MISSING ANALYSIS.
Excel formula layout
Assume G2 pass is in column B and G3 pass is in column D.

B5  =COUNTIFS(Data_Input!B:B,0,Data_Input!D:D,0)   // a = 89
B6  =COUNTIFS(Data_Input!B:B,0,Data_Input!D:D,1)   // b = 56
B7  =COUNTIFS(Data_Input!B:B,1,Data_Input!D:D,0)   // c = 11
B8  =COUNTIFS(Data_Input!B:B,1,Data_Input!D:D,1)   // d = 493

B10 =B6+B7                                           // discordant total
B11 =MIN(B6,B7)                                      // exact statistic
B12 =MIN(1,2*BINOM.DIST(B11,B10,0.5,TRUE))           // exact p
B13 =(B6-B7)^2/B10                                   // uncorrected chi-square
B14 =CHISQ.DIST.RT(B13,1)                            // uncorrected p
B15 =(ABS(B6-B7)-1)^2/B10                            // corrected chi-square
B16 =CHISQ.DIST.RT(B15,1)                            // corrected p
B17 =B6/B7                                           // matched odds ratio
B18 =(B6-B7)/SUM(B5:B8)                              // paired margin difference
Software note: exact p-value conventions can differ for some discrete tests. State the software, function and options, especially when results are near the chosen alpha level. In this worked example, all accepted versions are far below .001.

Advanced McNemar’s Test Topics

Exact Versus Asymptotic Inference

The exact version uses the conditional binomial distribution of one discordant direction given b + c. The asymptotic version replaces that finite distribution with a χ2(1) approximation. A common rule of thumb recommends exact inference when b + c is small, but the exact test remains valid for larger totals. The main trade-off is discreteness and potential conservatism.

Continuity Correction

The correction subtracts one from |b−c| before squaring. It usually increases the p-value relative to the uncorrected statistic. Software defaults differ, so a report should say “continuity corrected” when that form is used.

Mid-p McNemar Variant

A mid-p calculation subtracts half the probability of the observed outcome from the ordinary exact tail. It often has better average power but is not a fully conservative exact test. Do not label a mid-p result as the ordinary exact McNemar p-value.

One-Sided McNemar’s Test

A directional alternative can test whether b is greater than c or vice versa. The direction must be specified before examining the transition counts. Choosing one-sided inference after seeing that 56 exceeds 11 inflates the Type I error rate.

Zero Discordant Counts

If b + c = 0, all pairs are concordant and the data contain no information about directional change. The exact p-value is 1 by convention, and b/c is undefined. If one discordant cell is zero and the other is positive, the exact test remains possible but the raw matched odds ratio is infinite or zero; report an exact interval or a carefully justified continuity adjustment.

Matched Odds Ratio

The ratio b/c is the natural odds ratio for the direction of discordance. It is not the same as an ordinary cross-sectional odds ratio calculated from row and column totals. For the current table, 56/11 = 5.09.

Confidence Interval for the Paired Difference

McNemar’s Test supplies a hypothesis test, not automatically a confidence interval for the marginal difference. Several paired-binomial interval methods exist. Name the method and keep its assumptions separate from the exact p-value. Here, the paired difference is +0.0693 with an approximate interval of +0.0452 to +0.0935.

Thresholding a Quantitative Outcome

G2 and G3 are quantitative grades, but this analysis converts them to pass/fail. The binary question is useful when the threshold has substantive meaning. It should not replace an analysis of the original grade change when the amount of change also matters.

Clustered or Repeated Pairs

McNemar’s Test assumes independence between pairs. Repeated observations within schools, families, clinics or subjects can require conditional logistic regression, generalized estimating equations or mixed-effects logistic models.

Covariate Adjustment

McNemar’s Test is unadjusted. When the goal is to estimate a paired effect while controlling for additional variables, use a model designed for correlated binary outcomes rather than stratifying repeatedly and creating many small tests.

Power and Sample Size

Power depends primarily on the expected discordant proportion and how unequal the two discordant directions are. A large total N does not guarantee power if nearly every pair is concordant. Planning should specify expected p01, p10, alpha, power and anticipated incomplete-pair rate.

Multiple Pairwise McNemar Tests

After a significant Cochran’s Q test, pairwise McNemar comparisons can identify which conditions differ. Adjust the family of p-values with a prespecified multiplicity method such as Holm’s procedure rather than interpreting every comparison at an unadjusted .05 level.

APA Reporting for McNemar’s Test

A complete report identifies the paired design, binary coding, discordant counts, version of the test, statistic when applicable, p-value, direction and a magnitude estimate. Avoid reporting only “McNemar’s Test was significant.”

Worked Exact APA Statement

An exact two-sided McNemar’s Test compared paired G2 and G3 pass status among 649 students. Fifty-six students changed from fail to pass, whereas 11 changed from pass to fail. The discordant transition probabilities differed significantly, exact p = 2.15 × 10−8. The G3 pass proportion was 6.93 percentage points higher than the G2 pass proportion, and the discordant matched odds ratio was 5.09.

Continuity-Corrected APA Statement

A continuity-corrected McNemar’s Test indicated that G2 and G3 pass-status margins differed significantly, χ2(1, N = 649) = 28.90, p < .001. More students changed from fail to pass (56) than from pass to fail (11), corresponding to a net increase of 45 passes.

Reusable Reporting Templates

Replace every highlighted field with values from the current paired table. Keep the measurement order and transition direction explicit.

Exact significant result

Significant

Design

An exact two-sided McNemar’s Test compared first binary measure with second binary measure for N complete pairs.

Discordance

b count pairs changed from 0 to 1, whereas c count changed from 1 to 0.

Inference

The discordant transition probabilities differed significantly, exact p = p-value.

Magnitude

The paired marginal difference was difference, and the matched odds ratio was b/c.

Use the exact label only when the exact binomial version was actually run.

Nonsignificant result

Not significant

Design

McNemar’s Test compared first binary measure and second binary measure for N pairs.

Counts

The discordant counts were b and c.

Inference

The data did not provide sufficient evidence of unequal transition probabilities, test/statistic, p = p-value.

Caution

The confidence interval and observed direction should be reported; failure to reject does not prove identical margins.

Prespecified directional result

One-sided

Hypothesis

A one-sided exact McNemar’s Test evaluated whether 0→1 transitions were more frequent than 1→0 transitions.

Counts

The observed discordant counts were b and c.

Inference

The prespecified directional hypothesis was supported/not supported, one-sided exact p = p-value.

Do not convert a two-sided result to one-sided after inspecting the direction.

What to Include in a Methods Section

Pass status was coded as 1 for grades of 10 or higher and 0 otherwise. G2 and G3 status were paired within student. McNemar’s Test evaluated equality of the two discordant transition probabilities. The exact two-sided binomial result was primary, and the continuity-corrected chi-square result was used as a sensitivity check.

P-Value Formatting

For ordinary APA reporting, a result this small can be written as p < .001. Because the exact numerical output is useful in a technical worked example, the guide also reports 2.15 × 10−8. Do not write p = .000.

Common McNemar’s Test Mistakes and How to Correct Them

MistakeWhy it is wrongCorrection
Using an ordinary chi-square independence testIt ignores within-pair correlation.Use the paired transition table and McNemar’s Test.
Including diagonal counts in the statisticOnly b and c provide directional information.Use b + c in the denominator and b − c in the numerator.
Calling the test an agreement testMarginal symmetry is not the same as agreement.Report kappa separately when agreement is the target.
Using McNemar for three or more categoriesThe 2 × 2 formula does not cover larger square tables.Use Bowker’s symmetry test.
Using McNemar for three or more occasionsThe method compares only two related binary measures.Use Cochran’s Q, followed by adjusted pairwise tests if needed.
Reporting only a p-valueDirection and practical magnitude remain hidden.Report b, c, marginal proportions, difference and matched OR.
Ignoring table orientationThe sign and odds-ratio direction can reverse.State which variable is in rows and which is in columns.
Choosing one-sided after viewing countsThis inflates false-positive risk.Prespecify direction or retain the two-sided test.
Using the chi-square form with very few discordant pairsThe asymptotic approximation can be poor.Use the exact binomial version.
Dropping incomplete pairs without reporting themMissingness can alter the transition pattern.Report exclusions and consider sensitivity analysis.
Interpreting significance causallyThe test establishes asymmetry, not why it occurred.Use design and subject knowledge for causal claims.

McNemar’s Test Analysis and Reporting Checklist

Design

  • Same participants or valid matched pairs.
  • Exactly two binary classifications.
  • Pairs independent of other pairs.
  • Measurement order defined.

Data

  • Same category coding at both occasions.
  • Complete-pair count reported.
  • Four transition cells verified.
  • Missing pairs documented.

Inference

  • b and c identified correctly.
  • Two-sided or directional alternative prespecified.
  • Exact or asymptotic version named.
  • Software options verified.

Reporting

  • Both discordant counts reported.
  • Marginal proportions and difference reported.
  • Matched odds ratio or directional share reported.
  • Agreement and change kept conceptually separate.

McNemar’s Test Reports and Worked Excel Download

Use the files below to review the verified calculations, software output and formula-driven workbook.

Workbook audit: the uploaded workbook reproduces b = 56, c = 11, exact p = 2.145796 × 10−8, corrected χ2 = 28.895522 and corrected p = 7.638930 × 10−8.

Frequently Asked Questions About McNemar’s Test

What is McNemar’s Test used for?

McNemar’s Test is used to compare two paired binary classifications and determine whether the two discordant transition probabilities are equal.

What is the null hypothesis for McNemar’s Test?

The null hypothesis states that the probability of changing from category 0 to category 1 equals the probability of changing from category 1 to category 0.

Which cells are used in McNemar’s Test?

Only the two off-diagonal discordant cells b and c determine the test statistic and p-value. The diagonal cells describe concordance.

How do I find the McNemar test statistic?

For the uncorrected form, calculate (b−c)2/(b+c). For the continuity-corrected form, calculate (|b−c|−1)2/(b+c). For the exact form, the statistic is often reported as min(b,c).

How do I find proportions from a McNemar table?

The first and second marginal proportions are calculated from their row and column totals divided by N. The directional discordant proportion is b/(b+c), and the paired marginal difference is (b−c)/N.

When should the exact McNemar test be used?

The exact version is especially useful when b+c is small or when finite-sample exact inference is required. It is also valid for larger discordant totals.

What is the difference between McNemar’s Test and chi-square?

McNemar’s Test is for paired binary data. The ordinary chi-square test of independence assumes independent observations and does not account for pairing.

What is the difference between McNemar’s Test and Fisher’s Exact Test?

Fisher’s Exact Test analyzes independent 2 × 2 tables. Exact McNemar inference analyzes the two directions of discordance within pairs.

What is the difference between McNemar’s Test and Bowker’s Test?

McNemar’s Test is for paired 2 × 2 tables. Bowker’s Test extends symmetry testing to paired square tables with three or more categories.

What is the difference between McNemar’s Test and Cochran’s Q?

McNemar’s Test compares two related binary measurements. Cochran’s Q compares three or more related binary measurements.

Does a significant McNemar result mean poor agreement?

No. A table can have high agreement and still show significant marginal asymmetry when the disagreements mainly point in one direction.

Can McNemar’s Test be one-sided?

Yes, when a directional hypothesis is specified before examining the data. Post-hoc conversion from two-sided to one-sided is not appropriate.

What if b or c is zero?

The exact test can still be calculated when one discordant cell is zero, but the raw b/c odds ratio becomes zero or infinite. Use an exact interval and report counts clearly.

How is the current result interpreted?

Fail-to-pass transitions occurred much more frequently than pass-to-fail transitions. The exact p-value is approximately 2.15 × 10−8, the pass margin increased by 6.93 percentage points, and the matched odds ratio is 5.09.

McNemar’s Test Conclusion

McNemar’s Test is the correct procedure when the same participants or matched pairs contribute two binary classifications and the research question concerns directional marginal change. It preserves the pairing and bases inference on the two off-diagonal discordant counts.

In the worked G2-to-G3 example, 56 students changed from fail to pass and 11 changed from pass to fail. The exact two-sided p-value was 2.145796 × 10−8. The continuity-corrected statistic was χ2(1) = 28.895522, p = 7.638930 × 10−8, and the uncorrected statistic was χ2(1) = 30.223881, p = 3.849404 × 10−8.

The substantive conclusion is clear: pass status improved more often than it deteriorated. The pass margin increased by 6.93 percentage points, and the discordant matched odds ratio was 5.09. A complete report therefore includes the four transition counts, both marginal proportions, the exact-test specification, direction, effect estimates and a careful noncausal interpretation.

Final reporting line: an exact two-sided McNemar’s Test showed a strong directional difference in paired G2 and G3 pass status, exact p = 2.15 × 10−8; 56 students moved from fail to pass and 11 moved from pass to fail, producing a +6.93-percentage-point marginal change and a matched odds ratio of 5.09.
AdvertisementGoogle AdSense bottom placement reserved here

Back to top

Need help applying this to your own data?

Salar Cafe can help interpret output, clean datasets, review assumptions, build dashboards and explain statistical results ethically.

Need help interpreting your data analysis results?

Contact Salar Cafe
Engr. Muhammad Yar Saqib author profile photo

Engr. Muhammad Yar Saqib

WhatsApp Get Data Analysis Help