McNemar's Test Calculator — Paired Proportions, Chi-Square & Exact P-value

McNemar's Test Calculator

Test whether paired yes/no results changed, such as the same people before and after a treatment. Enter the four cells of the 2×2 table and pick a chi-square or exact version of the test.

Only the discordant pairs, b and c, decide the result

H₀: pb = pc (the positive rate did not change)   H₁: pb ≠ pc

Paired 2×2 table (counts of pairs)

After: positive
After: negative
Before: positive
Before: negative

Each count is a matched pair: the same subject measured twice, or a matched case and control. Cells a and d (the concordant pairs) do not change the p-value, but they give the table totals and the size of the change.

How to Use This Calculator

  1. Arrange your paired data in a 2×2 table. Rows are the first measurement (before), columns are the second (after), and each subject falls in exactly one cell.
  2. Enter the counts. a is positive both times, d is negative both times, b is positive before and negative after, and c is negative before and positive after.
  3. Pick the test version. The standard chi-square is fine for 25 or more discordant pairs (b + c). With fewer, use the exact binomial or mid-p version.
  4. Choose the significance level and press Run McNemar's Test.
  5. If the p-value is below α, the share of positives differs between the two measurements. The chart and note show which direction the change went.

What Is McNemar's Test?

A McNemar's test calculator determines whether two related groups have significantly different proportions for a binary outcome. It analyzes paired categorical data using a 2×2 contingency table and focuses on discordant pairs. Enter the two discordant cell counts to calculate a test statistic and p-value, then assess statistical significance, commonly at α = 0.05.

Typical paired data come from the same patients tested before and after a treatment, or from two diagnostic tests run on the same people. Pairs that gave the same result both times tell you nothing about a change. The discordant pairs are those that switched from positive to negative (b) and those that switched from negative to positive (c). If the treatment has no effect, switches in either direction should be equally likely, so b and c should be close to equal.

Paired

The same subjects, or matched pairs, measured twice.

Binary

Each measurement is yes or no, positive or negative.

b vs c

The test compares the two kinds of switch.

Definition reference: Wikipedia — McNemar's test.

McNemar's Test Formulas

Standard

χ² = (b − c)² ÷ (b + c)

Compared with the chi-square distribution with 1 degree of freedom.

Edwards correction

χ² = (|b − c| − 1)² ÷ (b + c)

Continuity correction. The most common one.

Yates correction

χ² = (|b − c| − ½)² ÷ (b + c)

A milder continuity correction.

Exact binomial p-value

p = 2 × P(X ≤ min(b, c)), X ~ Binomial(n = b + c, ½)

Capped at 1. The exact version is conservative.

Mid-p value

pmid = pexact − P(X = min(b, c))

Takes off half the probability of the observed outcome from each tail.

Change in the positive rate

p̂before − p̂after = (b − c) ÷ n, SE = √(b + c − (b − c)²/n) ÷ n

n = a + b + c + d is the number of pairs. The standard error gives the Wald confidence interval for the paired difference.

Test statistic and null hypothesis: Penn State STAT 504 — Dependent samples and marginal homogeneity.

Worked Example 1: A Large Sample

A group of 220 people take a screening test before and after a program. 60 are positive both times, 70 change from positive to negative, 50 change from negative to positive, and 40 are negative both times. Test at α = 0.05.

  • Standard: χ² = (70 − 50)² ÷ 120 = 3.3333, so p = 0.0679.
  • Edwards: χ² = (20 − 1)² ÷ 120 = 3.0083, p = 0.0828. Yates: χ² = 19.5² ÷ 120 = 3.1688, p = 0.0751.
  • Exact: p = 0.0824. Mid-p: p = 0.0686.
  • Every version gives p > 0.05, so you fail to reject H₀: the data do not show a change in the positive rate.

Worked Example 2: A Small Sample Where the Versions Disagree

Only 11 pairs changed: b = 9 and c = 2.

  • Standard: χ² = 49 ÷ 11 = 4.4545, p = 0.0348, which would reject H₀.
  • Yates: p = 0.0500, right at the line. Edwards: p = 0.0704. Exact: p = 0.0654. Mid-p: p = 0.0386.
  • With 11 discordant pairs the chi-square approximation is unreliable, so use the exact or mid-p version and report it. A single borderline result like this should be treated with caution.

Worked Example 3: Cells a and d Do Not Matter

Keep b = 70 and c = 50, and change a and d to any values, say 6 and 4, or 6,000 and 4,000. The statistic and p-value stay at 3.3333 and 0.0679. The concordant pairs only change the table totals and the size of the shift as a share of all pairs.

Which Version Should I Use?

The versions differ in how they handle the fact that counts are discrete.

VersionBest whenBehavior
Standard χ²b + c is 25 or moreSimple. Can be a little liberal with few pairs.
EdwardsModerate b + c, and you want a cautious resultLarger p-values. Tends to be conservative.
YatesAs Edwards, with a lighter correctionBetween standard and Edwards.
Exact binomialb + c is below 25Valid for any size, but conservative. With b + c < 6 it can never reach 0.05.
Mid-pSmall b + c, when the exact test is too strictLess conservative than exact, with a false-positive rate closer to α.

Exact test background: Wikipedia — Binomial test.

Paired or Independent Data?

McNemar's test is only for matched data. Using the wrong test changes the answer.

Your dataExampleTest
Same subjects measured twice, yes/noPass or fail before and after trainingMcNemar's test
Two independent groups, yes/noTreatment group vs. control groupTwo-proportion z-test, chi-square test of independence, or Fisher's exact test
Same subjects, three or more time points, yes/noResponse at weeks 1, 4, and 8Cochran's Q test
Paired measurements on a continuous scaleBlood pressure before and afterPaired t-test

McNemar's test also works for two diagnostic tests run on the same people. There, b and c count the people on whom the two tests disagree.

Frequently Asked Questions

What is McNemar's test?

McNemar's test is a test for paired data with a binary outcome. It works on a 2x2 table of matched pairs, a contingency table of categorical data, and checks whether the two margins are equal, which means whether the marginal proportion of positive responses is the same in the two measurements. It is often used in a before-and-after study, with a pretest and a posttest on the same participants, to see whether a treatment changes the outcome of a yes/no test. A McNemar's test calculator like this one does the arithmetic for you.

How do I calculate McNemar's test?

Take the two discordant counts, b and c, which give the frequency of pairs whose response changed in each direction, and compute the chi-square statistic χ² = (b − c)² ÷ (b + c). Compare it with the chi-square distribution with 1 degree of freedom to get the p-value, and reject the null hypothesis H₀ if p is below the significance level α. For the 70 and 50 in the example, χ² = 400 ÷ 120 = 3.33 and p = 0.068, so the result does not reach statistical significance at 0.05.

When should I use the exact test?

Use the exact test, which is a binomial test on b and c, or its mid-p version, when the number of discordant pairs b + c is small. The usual rule of thumb is fewer than 25. With so few pairs the chi-square approximation is unreliable, while the exact p-value is valid at any sample size. Under the null hypothesis each discordant pair is equally likely to fall in b or in c, so b follows a binomial distribution and the test adds up its tail probabilities directly.

Why does the calculator ask for a and d if they are not used?

The test statistic only uses b and c, so a and d never change the p-value. They are the concordant pairs, where the two classifications are in agreement, while b and c are the pairs in disagreement. Cells a and d are still part of the table: they give the total number of participants, and they let you report the change in the positive rate, which depends on the full sample. Filling in the whole 2x2 table also lets you check that the counts add up to the pairs you started with.

What is the difference between the Edwards and Yates corrections?

Both apply a continuity correction to the chi-square statistic, which makes the p-value less liberal for small counts. Edwards subtracts 1 from |b − c|, and Yates subtracts ½. Edwards is the one most software applies, so check which version your program uses before comparing results.

What is the null hypothesis in McNemar's test?

The null hypothesis is marginal homogeneity: the proportion of positives is the same in both measurements, so changes in either direction are equally likely (pb = pc). The alternative hypothesis is that the two proportions differ. Rejecting the null hypothesis means the proportion shifted, in the direction with more switches. In a design where one member of each pair receives the treatment and the other acts as the control, it says the treatment makes no difference to the response.

Can I use McNemar's test with more than two categories or time points?

Not directly. For a paired table with more than two categories, use the McNemar–Bowker test of symmetry. For a yes/no outcome measured at three or more times on the same subjects, use Cochran's Q test. If your treatment and control groups are separate people rather than matched pairs, use an ordinary chi-square test on the contingency table instead.

Is McNemar's test one-sided or two-sided?

The version here is two-sided: it detects a change in either direction. The chi-square form is inherently two-sided. For a one-sided question, check that b and c lean the way you expect and halve the exact p-value, but only if you chose that direction before seeing the data.

Other Useful Calculators

Disclaimer: This calculator is for educational and informational use. McNemar's test assumes each pair is independent of the others and that the two measurements in a pair are matched. The chi-square versions are approximations that work best with 25 or more discordant pairs. A significant result shows that the share of positives changed, not why it changed. For clinical, regulatory, or other consequential research, consult a qualified statistician.

Last updated: October 10, 2026