McNemar Test Calculator for Paired Binary Outcomes

Enter four matched before-and-after counts. Read which way the pairs changed, compare exact conditional and mid-p values at a chosen cutoff, and audit the binomial null distribution.

Matched binary outcomes

Test whether matched Yes and No outcomes changed

Before and after, by matched pair

Enter one count for each outcome transition. Compare the same units at both times or matched units under two conditions.

Stayed No

Gained a Yes

Lost a Yes

Stayed Yes

Enter a probability such as 0.05.

Only mid-p meets the cutoff.

Change in the share of Yes outcomes

Before Yes
55%
After Yes
61%

+6 percentage points

7 gained Yes and 1 lost Yes out of 100 matched pairs.

Compare the two-sided p-values

Exact conditional p
0.0703125
Above cutoff
Mid-p
0.0390625
At or below cutoff

Mid-p counts half the probability of outcomes tied with the observed imbalance. Its false-positive rate can exceed the cutoff.

Null distribution of No-to-Yes switches

Each changed pair is equally likely to switch in either direction under the null.

Conditional binomial null distribution with a highlighted tailExact tail probability 0.0703125. The vertical marker is the observed 7 gains.0Gains8
Remaining mass Mass counted in p Observed gains
View exact fractions
Exact conditional p
9/128
Mid-p
5/128
Percentage-point change
6

Export the matched-pair audit

Save transition counts, exact fractions, and null distribution weights.

View CSV text

How to use this calculator

  1. Enter the counts for No to No, No to Yes, Yes to No, and Yes to Yes. Count each matched pair once.
  2. Enter the desired significance cutoff as a probability, such as 0.05.
  3. Compare the change in Yes share and the exact conditional and mid-p values. Toggle the chart to see the weight each method gives the tied outcomes.
  4. Open the exact fractions or download the count and null-distribution audit.

The Formula

The mathematical logic powering this calculation is:

Count matched pairs in four cells. With g switches from No to Yes, ℓ switches from Yes to No and s pairs that are Yes both times, before Yes percent = 100(s + ℓ)/N and after Yes percent = 100(s + g)/N. The net percentage-point change is 100(g − ℓ)/N.

The McNemar null states that the two switch directions have equal probabilities, so the two marginal Yes probabilities are equal. Conditional on the observed D = g + ℓ changed pairs, the number of gains K follows a Binomial(D, 1/2) under the null. This model assumes independent matched pairs with the same two possible outcome categories.

Calculate the observed imbalance |g − ℓ|. The two-sided exact conditional p-value sums the probabilities of all gains k whose imbalance |2k − D| is at least as large. The two-sided mid-p assigns only half weight to outcomes tied with the observed imbalance. When g = ℓ and D > 0, exact p = 1 and mid-p = 1 minus half the central probability. The calculator keeps exact binomial counts and fractions even for rare tails. It compares values to the entered cutoff before rounding. Mid-p is less conservative and its type I error rate can exceed the nominal cutoff.

Use whole counts from 0 to 100,000 per cell, at least one matched pair overall, and up to 2,048 changed pairs. If nobody changes, the worksheet reports marginal percentages and marks both tests unavailable. The observed percentage-point difference describes the entered pairs and does not establish causation.

Worked Example

If you input:

  • No to No: 38
  • No to Yes: 7
  • Yes to No: 1
  • Yes to Yes: 54
  • Cutoff: 0.05

Result:

Yes increases from 55% to 61%. Exact conditional p is 9/128, or 0.0703125. Mid-p is 5/128, or 0.0390625, so only mid-p is at or below 0.05.

Frequently Asked Questions

Why do pairs that stay the same appear in the worksheet?

They count toward before and after percentages and the net percentage-point change. McNemar’s conditional test gets its information about direction from the pairs that switch.

When should I use this instead of Fisher’s exact test?

McNemar’s test matches this design when two outcomes come from the same unit or from paired units. Fisher’s exact test for independent groups uses a different reference distribution.

Why are the two p-values different?

The exact conditional test counts all assignments tied with the observed imbalance. Mid-p counts half their probability, which can change the result near a cutoff.

Can I infer cause or use unrelated samples?

Use this calculation for independent matched pairs. Design and measurement determine what explains any change. Use a method for independent samples when there is no pairing.

Similar Calculators