How to use the mcnemar test calculator
- Enter the four counts of your paired table. Both positive and both negative are pairs that gave the same result twice.
- Enter first positive, second negative and first negative, second positive. These two counts of changed pairs are the only ones the test uses.
- Read the exact p value first, then the mid-p value and the chi-square versions in the table.
- Use the odds ratio b / c and the agreement figures to describe the size and direction of the change.
Formula
b = first positive, second negative; c = first negative, second positive; m = b + c
Exact p = 2 x P(X <= min(b, c)) for X ~ Binomial(m, 1/2), capped at 1
Mid-p = 2 x [P(X <= min) - 0.5 x P(X = min)]
Chi-square = (|b - c| - 1)^2 / m with 1 degree of freedom
Kappa = (observed agreement - chance agreement) / (1 - chance agreement)
The continuity correction subtracts 1 from |b - c|. Without it the statistic is (b - c)^2 / m. The odds ratio of the changed pairs is simply b / c.
The same 100 people tested twice
Counts: 59 positive both times, 10 positive then negative, 3 negative then positive, 28 negative both times. Only the 13 changed pairs count, and 10 against 3 is the split to test.
If changes were equally likely either way, the chance of 3 or fewer on one side is 0.0461, so the exact two-sided p is 0.0923 and the mid-p is 0.0574. The corrected chi-square is (|10 - 3| - 1)^2 / 13 = 2.7692 with p = 0.0961. The odds ratio is 10 / 3 = 3.3333, agreement is 87.0% and kappa is 0.7139.
What the test answers
McNemar's test is for paired yes or no results: the same people before and after a program, one sample tested by two methods, or matched cases and controls. It asks whether pairs change in one direction more often than the other. Pairs that gave the same answer twice carry no information about that, so they are left out of the test.
This is different from the chi-square test of independence, which treats the two groups as unrelated. Using an ordinary chi-square on paired data throws away the pairing and can give a misleading p value.
Which p value to use
The exact binomial p value is correct for any number of changed pairs and is the safest choice, especially below about 25 changed pairs. The chi-square versions are approximations that work better as the count grows. The mid-p value is less conservative than the exact one and is shown for comparison.
Agreement and kappa describe how often the two measurements match, which is a separate question from whether one direction of change dominates. See the Cohen's kappa calculator for more on agreement, and the Fisher exact test for two separate groups with small counts.
Assumptions and limits
- Each pair is independent of the other pairs, and each person or item appears once.
- Both measurements are yes or no. Results with three or more categories need a different test.
- The odds ratio b / c cannot be formed when either changed count is 0.
- A small p value says the two directions of change are unequal. It does not say why.
Frequently asked questions
Why are the pairs that did not change ignored?
If a person was positive twice or negative twice, there is no evidence either way about a shift. Only a change can show a shift, so the test compares how many changed one way against the other way.
What if I have only a few changed pairs?
Use the exact p value. With fewer than about 25 changed pairs the chi-square approximation can be off, while the exact binomial calculation stays right at any size.
Is the mid-p value better than the exact value?
It is less cautious because it counts only half of the observed outcome. That makes it closer to the nominal error rate on average, but it can fall below the level when the exact value does not. Report which one you used.
Can I use this for more than two measurements?
No. For the same people measured three or more times on a yes or no outcome, Cochran's Q test is the usual extension, and it is not part of this page.