Free McNemar's Test Calculator

2×2 Contingency Table

After +After −
Before +
Before −

Results

Enter your 2×2 contingency table values to perform McNemar's test

Paired Proportions and the McNemar Test

When the outcome of interest is binary—such as positive/negative, pass/fail, or yes/no—and the data come from matched pairs, the McNemar test for paired proportions provides an appropriate inferential framework. This non‑parametric procedure evaluates whether the marginal distributions of a 2×2 contingency table differ, thereby detecting the effect of a treatment, intervention, or exposure. Typical applications include comparing medical test results before and after a treatment, examining student performance on a standardized exam before and after a preparatory course, or assessing shifts in voting intentions after a campaign. The matched pairs McNemar test requires only a simple random sample and makes no assumption about the underlying distribution beyond the binary nature of the outcome.

Setting Up the Contingency Table

Data for the test are arranged in a 2×2 table where each subject is classified twice (e.g., pre‑treatment vs. post‑treatment). The cells are conventionally labelled as:

After (event)After (no event)Row total
Before (event)aba + b
Before (no event)cdc + d
Column totala + cb + dN

Here aa counts subjects who were positive on both occasions, dd those who were negative on both, bb those who changed from positive to negative, and cc those who changed from negative to positive. The discordant pairs—bb and cc—carry all the information needed to test for a difference in marginal proportions. The concordant pairs (aa and dd) do not enter the test statistic.

Interpreting the Off‑Diagonal Cells

If the treatment has no effect, the two discordant counts are expected to be approximately equal. A sizable imbalance between bb and cc suggests that the marginal proportions have shifted, which is the signal McNemar’s test detects.

Statement of Hypotheses

Let pa,pb,pc,pdp_a, p_b, p_c, p_d be the theoretical probabilities corresponding to the four cells. The null hypothesis asserts that the row and column marginal probabilities are equal, i.e., the treatment has no effect on the binary outcome. Algebraically this reduces to:

H0:pb=pcH_0: p_b = p_c

The alternative hypothesis is H1:pb≠pcH_1: p_b \neq p_c, meaning the proportions have shifted significantly.

Computing the Test Statistic

The standard contingency table test uses the chi‑squared statistic built from the off‑diagonal frequencies:

χ2=(b−c)2b+c\chi^2 = \frac{(b - c)^2}{b + c}

Under H0H_0, provided b+cb+c is not too small, this statistic follows a chi‑squared distribution with one degree of freedom. A larger value of χ2\chi^2 indicates stronger evidence against the null.

Continuity Corrections

Because the chi‑squared distribution is continuous and the test statistic is derived from discrete counts, continuity corrections are sometimes applied to improve the approximation. The two most common are:

  • Edwards correction: χ2=(∣b−c∣−1)2b+c\chi^2 = \dfrac{(|b - c| - 1)^2}{b + c}
  • Yates correction: χ2=(∣b−c∣−0.5)2b+c\chi^2 = \dfrac{(|b - c| - 0.5)^2}{b + c}

Edwards correction is more widely adopted, and many statistical packages employ it as the default. Being aware of the correction used is important when comparing results across different software.

Decision Rules

The p‑value is obtained as 1−CDF(χ2)1 - \text{CDF}(\chi^2), where CDF is the cumulative distribution function of the chi‑squared distribution with 1 df. If the p‑value is less than the chosen significance level (commonly 0.05), the null hypothesis is rejected. The test can also be conducted using the right‑tailed critical region [χα2,∞)[\chi^2_{\alpha}, \infty).

Exact Test and Mid‑p Procedure

When the number of discordant pairs is small, the chi‑squared approximation may be inaccurate. A widely accepted rule is to apply the McNemar exact test whenever b+c<25b + c < 25. In this case, the test is based on the binomial distribution with success probability p=0.5p = 0.5. The two‑sided exact p‑value sums the probabilities of obtaining a discordant count as extreme as the observed one.

A modern alternative is the mid‑p value, which subtracts half the probability of the observed count from the exact p‑value. The mid‑p approach often yields better control of the type I error rate while maintaining good power. The online McNemar exact test calculator provides both the exact p‑value and the mid‑p value, allowing you to compare the two.

How to Use the Online Calculator

This free tool streamlines the computation of McNemar’s test through a simple interface:

  1. Enter the four cell counts (a, b, c, d) into the corresponding input fields. The calculator instantly renders the 2×2 table with its row and column totals so you can confirm the data entry.
  2. Choose the version of the test you wish to perform from the five available options: standard chi‑squared, with Edwards correction, with Yates correction, exact binomial, or mid‑p binomial. If you are uncertain, the standard chi‑squared version is a good starting point.
  3. The tool returns the p‑value for the selected test. For the chi‑squared based options, the test statistic is also displayed, facilitating verification of hand calculations.

Worked Example

Consider a study in which 220 patients take a medical test before and after a treatment. The resulting 2×2 table is:

After positiveAfter negative
Before positive6070
Before negative5040

Here b=70b = 70 and c=50c = 50. Substituting into the formula:

χ2=(70−50)270+50=400120=3.333.\chi^2 = \frac{(70 - 50)^2}{70 + 50} = \frac{400}{120} = 3.333.

The cumulative probability of χ2=3.333\chi^2 = 3.333 from the chi‑squared distribution with 1 df is approximately 0.932, giving a p‑value of 1−0.932=0.0681 - 0.932 = 0.068. At the conventional 0.05 significance level, this p‑value is not small enough to reject the null hypothesis. Therefore, the data do not provide sufficient evidence to conclude that the treatment changed the proportion of positive results.

This example illustrates that even when the difference appears non‑negligible in the raw counts, the formal hypothesis test may not reach statistical significance. The online calculator automates these steps, enabling rapid evaluation of any 2×2 paired‑proportion dataset.

FAQ

1. When should the exact binomial test be used instead of the standard chi-squared version?

The exact test is recommended when the sum of the discordant cells (b + c) is less than 25. The chi-squared approximation becomes unreliable for such small samples.

2. What do the off-diagonal cells b and c represent in the 2×2 table?

Cell b counts subjects who changed from positive to negative (or from ‘success’ to ‘failure’), while cell c counts those who changed from negative to positive. These two discordant frequencies are all that is needed to compute McNemar’s test statistic.

3. How is the continuity correction applied in McNemar’s test?

Two common corrections exist: Edwards correction subtracts 1 from the absolute difference before squaring, giving χ² = (|b-c| - 1)²/(b+c); Yates correction subtracts 0.5, giving χ² = (|b-c| - 0.5)²/(b+c).

4. What does the null hypothesis of McNemar’s test mean in simple terms?

The null hypothesis states that the treatment or exposure has no effect on the marginal proportions of the binary outcome. More formally, it means the probability of changing from positive to negative equals the probability of changing from negative to positive (p_b = p_c).

How to Use

  1. Enter the four values a, b, c, d of your 2×2 contingency table into the grid below.
  2. Select which version of McNemar's test to perform - Standard, Edwards correction, Yates correction, Exact binomial test, or Mid-p binomial test.
  3. Read the p-value, test statistic (if applicable), and significance verdict instantly.