McNemar test calculator

Enter the four counts of a paired 2x2 table. The McNemar test compares two yes/no results that come from the same subjects or from matched pairs. You get four two-sided p values side by side.

Calculator

Paired 2x2 table

A and B are the two results of each pair, for example before and after. Count each pair one time. Enter whole numbers from 0 to 1,000,000,000.

What the test uses

A paired design gives two yes/no results for each pair. The pairs fall into four cells: both yes (a), only A yes (b), only B yes (c) and both no (d). The cells b and c hold the discordant pairs, where the two results disagree.

The test asks whether the probability of yes is the same for A and for B. Only the discordant pairs enter the calculation. If the null hypothesis is true and the number of discordant pairs is given, the count b follows a binomial distribution with b + c trials and probability 1/2 (Fagerland, Lydersen and Laake 2013).

The cells a and d do not change a p value on this page. The page uses them only for the total and for the two shares of yes. If you know only b and c, enter 0 for a and d.

Counts from separate groups that are not paired need a different test. Use the chi-square test calculator or the Fisher-Freeman-Halton calculator for such a table. For a paired difference of two means, use the paired mode of the t-test calculator.

The four p values

The formulas are equations (1) to (6) of Fagerland, Lydersen and Laake 2013, with b for the paper's n12 and c for n21. In each formula X is a binomial count with b + c trials and probability 1/2.

Asymptotic

Chi-square = (b − c)² / (b + c), with 1 degree of freedom. The p value is the upper tail of the chi-square distribution. The page calculates it as erfc(sqrt(chi-square / 2)).

Asymptotic with continuity correction

Chi-square = (|b − c| − 1)² / (b + c), with 1 degree of freedom. The paper attributes this version to Edwards. When b = c the formula gives 1 / (b + c), which is not 0, so this p value is below 1 for such a table.

Exact conditional

The one-sided p value is P(X ≤ min(b, c)). The two-sided p value is 2 × P(X ≤ min(b, c)), and not more than 1. When b = c the p value is 1.

Mid-p

Mid-p = exact two-sided p value − P(X = b), which is equation (5). When b = c the paper replaces it with equation (6): mid-p = 1 − 0.5 × P(X = b).

A table with no discordant pair

When b + c = 0 the two chi-square formulas divide by 0. The paper states that the two asymptotic tests have no defined value for such a table. The page shows a message and no p value.

What the paper concludes

This page gives no advice of its own on which p value to report. The sentences below are quotations from the abstract, the discussion and the conclusions of Fagerland, Lydersen and Laake 2013. The paper compared the type I error rates and the power of the tests.

The paper also evaluates an exact unconditional test. This page does not calculate that test.

Reference examples

The table below has three published examples. For the two tables of the paper, the row "Paper, Table 6" is copied from the paper, and the row "This page" is the result of the page script, rounded to 4 decimals. The R documentation gives the counts of its example and prints no result number, so that row is marked as calculated here.

Published tableRowAsymptoticWith continuity correctionExact conditionalMid-p
Fagerland et al. 2013, Table 1. a = 1, b = 1, c = 7, d = 12
Paper, Table 60.03390.07710.07030.0391
This page0.03390.07710.07030.0391
Fagerland et al. 2013, Table 2. a = 59, b = 6, c = 16, d = 80
Paper, Table 60.03300.05500.05250.0347
This page0.03300.05500.05250.0347
R documentation of mcnemar.test, example from Agresti (1990), p. 350. a = 794, b = 150, c = 86, d = 570
R documentationThe R page prints no p value.
This page, calculated here3.099e-54.115e-53.716e-52.893e-5

Table 1 of the paper is airway hyper-responsiveness in 21 children before and after stem cell transplantation, from a study by Bentur et al. Table 2 is complete response in 161 myeloma patients before and after consolidation therapy, from a study by Cavo et al. In the two tables A is the result before and B is the result after.

The R example is approval of the President's performance in office in two surveys, one month apart, for a random sample of 1600 voting-age Americans. R fills a matrix by columns, so the call matrix(c(794, 86, 150, 570), nrow = 2) puts 150 voters in the cell "approve in the first survey, disapprove in the second" and 86 voters in the opposite cell. Here A is the first survey and B is the second. The chi-square statistics for this table, calculated here, are 17.3559 without the correction and 16.8178 with it. The R page has this comment on the result: "significant change (in fact, drop) in approval ratings".

The calculator shows a p value of 0.1 or more with four decimals, and a smaller p value with four significant digits. It shows a p value that is smaller than 1e-300 as "below 1e-300".

The same tests in R, statsmodels and SciPy

In R, mcnemar.test(x, y = NULL, correct = TRUE) applies the continuity correction by default. The documentation describes correct as "a logical indicating whether to apply continuity correction when computing the test statistic". Set correct = FALSE for the test without the correction (R manual).

The R function applies the correction only when b and c are different. The condition in its source code is any(x - t(x) != 0) (R source code, mcnemar.test.R). For a table with b = c and b + c above 0, the statistic in R is then 0 and the p value in R is 1. On this page the corrected statistic for such a table is 1 / (b + c), as the formula above gives.

In statsmodels, mcnemar(table, exact=True, correction=True) uses the binomial distribution when exact is True. With exact=False it uses the chi-square distribution, and correction switches the continuity correction on or off. The documented parameters are table, exact and correction. The documentation lists no mid-p option (statsmodels).

In SciPy, binomtest(k, n, p=0.5, alternative='two-sided') is a test that the probability of success is p (SciPy). For the exact conditional test, k is min(b, c) and n is b + c.

Where these numbers come from

Each p value in the calculator is the output of the page script for the counts that you enter. The script is in the source of this page.

The published values in the reference table are copied from Table 6 of the paper. Each value that a source does not print is marked as calculated here.

On 2026-10-10 the four p values of the page script were compared with SciPy 1.13.1 and statsmodels 0.14.6 for 40 tables: the three reference tables, 21 more tables with fixed counts (five of them with b = c) and 16 tables with random counts. The asymptotic, corrected and exact values were compared with the statsmodels function mcnemar and with the chi-square and binomial functions of SciPy. The mid-p values were compared with a calculation from the binomial functions of SciPy, because the statsmodels function has no documented mid-p option. For each of the 160 p values the relative difference was below 1e-12.

Sources, all read on 2026-10-10:

The code of the site is open source at github.com/theluckystrike/abwex.com under the MIT license.

Assumptions and limits

Disclaimers

By Michael Lip, builder and maintainer of ABWex, open source at github.com/theluckystrike/abwex.com. Profile.

ABWex is a free A/B test statistics calculator from Zovo Tools. The calculation runs in your browser in JavaScript. The page does not send the counts that you enter to a server. Published 2026-10-10.

Explore ABWex

By the same builder: GitHub, theluckystrike BeLikeNative, Grammar AI EarlyThunder, Dev Blog Bug Bounty Reality Zovo, AI Dev Tools