Many clinical studies measure the same binary outcome twice in the same patients, for example before and after an intervention. In this situation, the two measurements are not independent, and the usual chi-square test is not appropriate. The McNemar test is the correct method to compare two paired proportions. It focuses only on the patients whose status changed between the two measurements. A common mistake is to analyze paired data as if they came from two independent groups, which gives a wrong p-value. This guide explains the McNemar test step by step, using one hypothetical clinical example.
Table of Contents
Free tool: calculate the sample size or power for your study with the StatisMed sample size calculator. It shows the exact R code and ready-to-use wording for your Methods section. Open the calculator →
What Is the McNemar Test?
The McNemar test is a non-parametric test for a 2×2 table of paired binary data. Each pair contributes one observation to the table, not two. The test asks whether the proportion of “yes” responses is the same at the two measurements. Unlike the chi-square test of independence, which compares independent groups (Kim, 2017), the McNemar test is designed for related samples.
The Asymptotic McNemar Test
The classic version uses the chi-square distribution with 1 degree of freedom. The statistic is χ² = (b − c)² ÷ (b + c), where b and c are the two discordant cells. This version works well when the number of discordant pairs is adequate.
The Continuity-Corrected McNemar Test
Edwards’ continuity correction subtracts 1 from the absolute difference: χ² = (|b − c| − 1)² ÷ (b + c). This correction makes the test more conservative. Notably, it is the default in some software, such as R.
The Exact and Mid-P McNemar Tests
When the number of discordant pairs is small, the exact binomial version is often used. However, the exact test is also conservative. Fagerland, Lydersen and Laake compared these versions and recommended the asymptotic test without correction or the mid-p test for most situations (Fagerland et al., 2013).
Importance of the McNemar Test in Medical Research
Correct Analysis of Paired Data
Paired designs are common in medicine, because each patient serves as his or her own control. Therefore, the analysis must respect the pairing. The McNemar test does this for binary outcomes, in the same way that the paired t-test or the Wilcoxon signed-rank test does for continuous outcomes.
Higher Statistical Power
Because the test removes the variation between patients, a paired design often needs fewer participants than a design with two independent groups. Moreover, the concordant pairs do not add noise to the comparison.
A Simple and Transparent Result
The McNemar test is easy to calculate and easy to explain. Its result depends on two numbers only: the patients who improved and the patients who declined. In addition, these two numbers give a direct paired odds ratio.
Applications of the McNemar Test in Clinical Studies
Clinical Trials and Before-After Studies
In single-group trials, the test compares the proportion of patients with an outcome before and after treatment. Examples include smoking status before and after a cessation program, or symptom control before and after a new drug. Our guide to statistics for clinical trials explains how such designs fit into trial analysis.
Matched Case-Control Studies
In a 1:1 matched case-control study, each case is matched with one control on age, sex, or other factors. The McNemar test compares exposure between cases and their matched controls. Furthermore, the ratio of discordant pairs is the matched odds ratio.
Diagnostic Accuracy Studies
When two diagnostic tests are applied to the same patients, the McNemar test compares their sensitivity (among diseased patients) or their specificity (among non-diseased patients). This complements ROC curve analysis for continuous markers.
Assumptions of the McNemar Test
Before running the McNemar test, check that the data meet the following assumptions:
- The outcome is binary (for example, yes/no or positive/negative) at both measurements.
- The data are paired: the same patients are measured twice, or each case is matched with one control.
- The pairs are independent of each other.
- The categories are mutually exclusive, and each pair falls into one cell of the 2×2 table only.
- For the asymptotic test, the number of discordant pairs (b + c) is adequate; many textbooks use 25 or more. With fewer discordant pairs, use the exact or mid-p version.
If the outcome has more than two categories, the McNemar-Bowker test of symmetry is used instead. If there are three or more paired measurements, Cochran’s Q test is the appropriate extension.
How to Perform a McNemar Test: A Clinical Example
Consider a hypothetical study of 120 patients with type 2 diabetes. The researchers recorded whether each patient practiced adequate foot self-care (yes/no) before and 3 months after a nurse-led education program. The question is whether the proportion of patients with adequate foot self-care changed after the program. All the numbers below were calculated with Python.
Step 1: State the Hypotheses
The null hypothesis (H0) states that the proportion of patients with adequate foot self-care is the same before and after the program. In terms of the table, this means that the two discordant cells are equal (b = c). The alternative hypothesis (H1) states that the proportions differ. The significance level is set at 0.05.
Step 2: Build the Paired 2×2 Table
In a paired table, the rows show the status before the program and the columns show the status after the program. Each patient appears in one cell only. Therefore, the table total is 120 patients, not 240 measurements.
| Before the program | After: Yes | After: No | Total |
|---|---|---|---|
| Yes | 40 (a) | 8 (b) | 48 (40.0%) |
| No | 24 (c) | 48 (d) | 72 (60.0%) |
| Total | 64 (53.3%) | 56 (46.7%) | 120 |
Step 3: Identify the Discordant Pairs
Cells a and d are concordant: these 88 patients had the same status at both measurements. In contrast, cells b and c are discordant. Eight patients had adequate self-care before but not after the program (b = 8), and 24 patients had inadequate self-care before but adequate self-care after the program (c = 24). The McNemar test uses only these 32 discordant patients.
Step 4: Check the Number of Discordant Pairs
The number of discordant pairs is b + c = 32. Since this value is above 25, the chi-square approximation is valid. However, the exact and mid-p results are also shown in Step 5 for comparison.
Step 5: Calculate the McNemar Statistic and the P-Value
The McNemar statistic is χ² = (b − c)² ÷ (b + c) = (8 − 24)² ÷ 32 = 256 ÷ 32 = 8.00, with df = 1. The critical value of chi-square at df = 1 and α = 0.05 is 3.84. Because 8.00 is larger than 3.84, the null hypothesis is rejected. The exact p-value is 0.005 (χ² = 8.00, df = 1, p = 0.005). Table 2 shows that all four versions of the McNemar test lead to the same conclusion.
| Version | Formula | Statistic | p-value |
|---|---|---|---|
| Asymptotic (no correction) | (b − c)² ÷ (b + c) | χ² = 8.00 | 0.005 |
| Continuity-corrected | (|b − c| − 1)² ÷ (b + c) | χ² = 7.03 | 0.008 |
| Exact binomial | Binomial (n = 32, p = 0.5) | b = 8 | 0.007 |
| Mid-p | Exact p − P(X = b) | b = 8 | 0.005 |
Step 6: Calculate the Effect Size
A p-value does not show how large the change is. Therefore, report an effect size with its confidence interval. The paired odds ratio equals c ÷ b = 24 ÷ 8 = 3.00 (95% CI, 1.35 to 6.68). In other words, improvement was three times as frequent as decline among the patients who changed. In addition, the paired difference in proportions was 53.3% − 40.0% = 13.3% (95% CI, 4.4% to 22.3%).
Step 7: State the Conclusion
The proportion of patients with adequate foot self-care was significantly higher after the education program than before it. Notably, the conclusion is based on the change within the same patients, not on a comparison between two separate groups.
How to Report McNemar Test Results in a Manuscript
In the Methods section, state the test, the version used, and the software. For example: “The McNemar test was used to compare the proportions of patients with adequate foot self-care before and after the program.” In the Results section, report the significant findings only, as in the model paragraph below.
Foot Self-Care Before and After the Education Program
The proportion of patients with adequate foot self-care increased significantly from 40.0% before the education program to 53.3% after the program (χ² = 8.00, df = 1, p = 0.005). Among the 32 patients whose status changed, 24 improved and 8 declined (OR = 3.00, 95% CI, 1.35 to 6.68, p = 0.005). Moreover, the paired difference in proportions was 13.3% (95% CI, 4.4% to 22.3%, p = 0.005) (Table 1).
Notice that the paragraph gives the numbers without any explanation of why self-care improved. The interpretation and the comparison with previous studies belong in the Discussion section.
Common Mistakes When Using the McNemar Test
Using the Ordinary Chi-Square Test for Paired Data
If the same data are entered as two independent groups of 120, the ordinary chi-square test gives χ² = 4.29, p = 0.038. This value is wrong, because it treats 240 measurements as 240 different patients. With paired data, always use the McNemar test.
Building the Wrong Table
A common error is to tabulate “time” against “outcome”, which produces a table of 240 observations. The correct table cross-tabulates the outcome at the first measurement against the outcome at the second measurement, with one entry per patient or pair.
Ignoring a Small Number of Discordant Pairs
When b + c is small, the chi-square approximation may be inaccurate. In this case, report the exact or mid-p result. This choice is similar to the use of Fisher’s exact test for small independent 2×2 tables.
Reporting the P-Value Without an Effect Size
A significant McNemar test shows that a change occurred, but not its size. Therefore, report the paired difference in proportions or the paired odds ratio, with the 95% confidence interval.
Using the Test When Adjustment Is Needed
The McNemar test does not adjust for other variables. If matched data require adjustment for confounders, conditional logistic regression is the appropriate method (see logistic regression interpretation). In addition, plan an adequate sample size based on the expected proportion of discordant pairs.
Running the McNemar Test in SPSS and R
In SPSS, the McNemar test is available through Analyze → Descriptive Statistics → Crosstabs. Move the “before” variable to Rows and the “after” variable to Columns, then click Statistics and select “McNemar”. For a 2×2 table, SPSS reports the exact binomial p-value (p = 0.007 in this example). The same test is also available through Analyze → Nonparametric Tests → Legacy Dialogs → 2 Related Samples. In R, the analysis is performed with one line of code: mcnemar.test(matrix(c(40, 24, 8, 48), nrow = 2), correct = FALSE). Note that R applies the continuity correction by default (χ² = 7.03, p = 0.008) unless correct = FALSE is specified.
Conclusion
The McNemar test is the standard method to compare two paired proportions in before-after studies, matched case-control studies, and diagnostic comparisons. It uses only the discordant pairs, and it requires a correct paired 2×2 table. Moreover, a complete report includes the test statistic, df, the p-value, the version of the test, and an effect size with its confidence interval. If you are not sure which statistical test to choose, or you need help analyzing your data and writing the Results section, the StatisMed team of biostatisticians provides statistical analysis services for medical studies. You can request a free quote today.
Frequently Asked Questions
1. What is the difference between the McNemar test and the chi-square test?
The chi-square test of independence compares proportions between independent groups. The McNemar test compares two proportions measured on the same patients or on matched pairs. Using the chi-square test for paired data ignores the pairing and gives an incorrect p-value.
2. Should I use the continuity correction with the McNemar test?
The continuity correction makes the test conservative. Fagerland et al. (2013) recommended the asymptotic test without correction, or the mid-p test, for most sample sizes. Whatever version you choose, state it in the Methods section.
3. What test should I use for more than two paired measurements?
For three or more paired measurements of a binary outcome, use Cochran’s Q test. For a paired table with more than two categories, use the McNemar-Bowker test of symmetry.
References
Fagerland, M. W., Lydersen, S., & Laake, P. (2013). The McNemar test for binary matched-pairs data: Mid-p and asymptotic are better than exact conditional. BMC Medical Research Methodology, 13, 91. https://doi.org/10.1186/1471-2288-13-91
Kim, H. Y. (2017). Statistical notes for clinical researchers: Chi-squared test and Fisher’s exact test. Restorative Dentistry & Endodontics, 42(2), 152–155. https://doi.org/10.5395/rde.2017.42.2.152




