Saved

Press the star next to a tool's name to save it.

All my tools

McNemar's Test Calculator

Use this McNemar's test calculator for paired yes-or-no data: chi-squared, continuity-corrected, exact binomial and mid-P p-values from the discordant pairs.

Restored your last values ·

Enter the paired 2 × 2 table. a is both positive, b is positive then negative, c is negative then positive and d is both negative. Only b and c, the pairs that changed, decide the result.

Everything is worked out in your browser. Nothing you type is sent anywhere.

–

–

Enter the four paired counts, then press Calculate.

See full result

A McNemar's test calculator compares two yes-or-no results measured on the same subjects, for example a test before and after a treatment, or two diagnostic tests on the same people. Enter the four paired counts and it gives the chi-squared statistic, a continuity-corrected value, the exact p-value and the mid-P value.

How to use the McNemar's test calculator

  1. Enter a, the pairs positive on both measurements, and d, the pairs negative on both.
  2. Enter b, positive on the first measurement and negative on the second, and c, negative on the first and positive on the second.
  3. Press Calculate and read the p-value recommended for your number of discordant pairs.

What the test checks

The Wikipedia article on McNemar's test applies it to a 2 × 2 table of paired dichotomous data.[1] Its null hypothesis is marginal homogeneity: the probability of a positive on the first measurement equals the probability of a positive on the second, which comes down to b and c being equally likely.[1] Only the discordant pairs, b and c, carry information. The pairs that were the same both times, a and d, do not change the answer, though the calculator uses them to report the total number of pairs.

The formulas

The page gives the statistic as chi-squared = (b − c)² ÷ (b + c), which follows a chi-squared distribution with 1 degree of freedom when there are enough discordant pairs.[1] The continuity-corrected version by Edwards is (|b − c| − 1)² ÷ (b + c).[1] The exact version uses a binomial distribution with n = b + c and probability 0.5: for b greater than or equal to c, the two-sided p-value is twice the sum of C(n, i) × 0.5 to the power n from i = b to n.[1] The mid-P version is twice the exact one-sided probability minus half the probability of exactly b.[1]

Worked example one

The page's first example is a table of 314 pairs with a = 101, b = 121, c = 59 and d = 33. The statistic is (121 − 59)² ÷ (121 + 59) = 3,844 ÷ 180 = 21.36, and the page reports p below 0.001.[1] The page rounds this to 21.35, while the exact division gives 21.36, which is the figure the calculator shows. The strong imbalance between 121 and 59 shows that the change was mostly in one direction.

Worked example two

The second example has 161 pairs with a = 59, b = 6, c = 16 and d = 80. The page gives an exact binomial p-value of 0.053, a continuity-corrected chi-squared of 3.68 with p = 0.055, an asymptotic chi-squared of 4.55 with p = 0.033, and a mid-P value of 0.035.[1] Enter those four numbers and the calculator reproduces them. The example shows why the choice of method matters: the asymptotic test says p is below 0.05 while the exact and corrected tests say it is just above.

Which p-value to read

The page says that if b or c is small, with b + c below 25, the chi-squared statistic is not well approximated by the chi-squared distribution.[1] It calls the exact test the traditional advice for fewer than 25 discordant pairs, but says simulations show the exact and continuity-corrected tests are overly conservative and recommends the mid-P test.[1] The calculator follows the same threshold: with fewer than 25 discordant pairs it tells you to read the exact or mid-P value, and with 25 or more the chi-squared value is a reasonable approximation. The page's own Python code uses the mid-P test for fewer than 25 discordant pairs and the asymptotic test otherwise.[1]

The ratio of discordant pairs

The calculator also shows b ÷ c. For the first example, 121 ÷ 59 is about 2.05, so changes from positive to negative were about twice as common as changes the other way. This ratio is our own addition for interpretation; the page does not use it as part of the test. If c is 0, the ratio is not defined and the calculator says so.

When not to use it

McNemar's test needs matched pairs. If you have two separate groups of people, such as a treatment group and a control group, the pairs do not exist and you should use a test for independent groups, such as Fisher's exact test or chi-squared. The test also handles only two outcomes per measurement. For three or more categories a different test is needed.

A simple way to think about it

Imagine each pair that changed is a coin toss. If the two measurements really have the same positive rate, a pair that changed is equally likely to have changed in either direction, so the 22 changed pairs of the second example would split near 11 and 11. They split 6 and 16, which is unusual enough to give a p-value near 0.05. This is our own illustration of the exact test, which is exactly a binomial test with probability one half on the changed pairs.

Reporting the result

State which version you used, the number of discordant pairs and the p-value, for example: exact test, 22 discordant pairs, p = 0.053. Give b and c as well, because they show the direction of the change. If the calculator advises the mid-P value, report that and say so, since different methods can fall on either side of 0.05.

Common mistakes

  • Putting b and c the wrong way round. b is positive then negative; c is negative then positive. The p-value does not change if you swap them, but the interpretation does.
  • Counting people instead of pairs. Each subject gives one pair.
  • Using it on independent groups. The test is only for paired data.

What next

Use this often? Add McNemar's Te to your Home screen.

Frequently asked questions

What is a McNemar's test calculator?

A tool that tests whether the proportion of positives differs between two paired measurements, using only the discordant pairs b and c.

What is the McNemar's test formula?

Chi-squared = (b − c)² ÷ (b + c) with 1 degree of freedom. The continuity-corrected form is (|b − c| − 1)² ÷ (b + c).

When should I use the exact or mid-P test?

When there are fewer than 25 discordant pairs, because the chi-squared approximation is weak. The mid-P test is recommended over the exact test, which is conservative.

Which cells of the table matter?

Only b and c, the pairs where the result changed. The cells a and d, where it stayed the same, do not affect the statistic.

Can I use McNemar's test on two separate groups?

No. It needs the same subjects measured twice, or matched pairs. For separate groups use Fisher's exact test or chi-squared.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Math Tools