Paired binary data — before/after and matched pairs

McNemar Test Calculator

This McNemar test calculator analyses paired binary data — the same subjects measured twice, before and after a treatment, or as matched pairs — and returns both chi-square forms, the exact binomial p-value, the paired odds ratio and a plain verdict on which p-value your data earn. Enter the full paired table, or just the two discordant counts b and c if those are all you have.

Table 1. The paired table. Rows are the first measurement, columns the second; the highlighted cells b and c are the pairs that changed — the only counts the test uses.

The full paired table

Total
65
35
Total 48 52 100

The muted cells a and d are the concordant pairs — the outcome was the same both times, so they carry no information about change and drop out of the test. They still matter for the proportions and the net change below.

Quick entry — just the discordant counts b and c

Editing b or c here updates the table above, and editing the table updates these boxes — they are the same two counts. Every p-value on this page is computed from b and c alone; the concordant counts a and d are needed only for the proportions and the net change.

Result — McNemar's test

—

Chi-square form (1 degree of freedom)

Chi-square, uncorrected
—
Chi-square, continuity-corrected
—
Continuity correction — which χ² is primary?
Continuity correction — which χ² is primary?

Exact form and effect size

Exact binomial p-value
—
b / c — how much more often pairs changed one way than the other; interval by the log method
—
Net change
—

For your report

The sentence follows the form you should report — the exact form when b + c < 25, the chi-square form otherwise. See the reporting section below for the full checklist.

Every figure is computed in your browser from the counts you enter — nothing is uploaded.

Your result explained — which p-value to report, and why

The result panel prints three p-values for the same table, and they are not interchangeable. The chi-square form approximates the distribution of the change counts with a chi-square distribution on 1 degree of freedom; it comes in two variants, uncorrected and with the Edwards continuity correction, and both are always shown. The exact form is not an approximation at all: it is a binomial calculation on the discordant pairs, asking how likely a split at least this uneven would be if changed pairs were equally likely to move in either direction.

The headline figure is the one the verdict recommends for your discordant total, b + c. When fewer than 25 pairs changed, the chi-square approximation can sit noticeably away from the exact binomial probability, so the exact p is the one to report. At 25 or more discordant pairs the approximation has tightened around the exact value, and either figure tells the same story — the panel still shows the exact p so you can see how close they are. Treat the 25 threshold as what it is: a long-standing convention for when the approximation becomes dependable, not a law with a cliff edge at 24 versus 25.

Beside the p-values sit the two effect sizes. The paired odds ratio, b divided by c, says how many times more often pairs changed in one direction than the other, with a confidence interval by the log method. The net change puts the same result on the scale readers feel: the proportion answering Yes at the first measurement, the proportion at the second, and the difference in percentage points. A tiny p-value with a net change of a fraction of a point is a precise result about a small effect — report both numbers, not the p alone.

What is McNemar's test?

McNemar's test compares two paired proportions when the same subjects are measured twice on a binary outcome — before and after a treatment, at two time points, or as matched pairs. It tests marginal homogeneity: whether the proportion with the outcome at the first measurement equals the proportion at the second. Quinn McNemar introduced the test in 1947, and it remains the standard answer whenever a 2×2 table's rows and columns are two readings of the same people rather than two independent groups.

The null hypothesis is narrow and worth stating exactly: among the pairs that changed, movement in one direction is as likely as movement in the other. If the treatment does nothing, roughly as many subjects should switch from Yes to No as from No to Yes, and any imbalance is sampling noise. A small p-value says the imbalance is larger than that noise plausibly explains — the marginal proportions differ.

The paired table — concordant vs discordant pairs

Lay the data out as a paired table: rows are the first measurement (Yes or No), columns the second. Cell a counts subjects who were Yes both times and cell d those who were No both times — the concordant pairs, whose outcome never changed. Cell b counts Yes-then-No and cell c counts No-then-Yes — the discordant pairs, the subjects who changed. The two marginal proportions the test compares are built from these cells: the Yes proportion before is (a + b) over N, and after it is (a + c) over N, so their difference is (b − c) over N — a and d cancel before the test even begins.

Why only the discordant pairs count

A subject who was Yes both times is evidence that the outcome occurs, but no evidence at all about change — the same is true of a subject who was No both times. Everything the data say about whether the proportions moved lives in the balance between b and c. That is why McNemar's test is, at heart, a sign test on the changed pairs: it discards the concordant pairs not by oversight but because they cannot distinguish the null hypothesis from its alternative. The practical consequence is that the effective sample size of the test is b + c, not N — a study of 500 subjects in which only 12 changed is, for this test, a study of 12.

The two forms of the test

McNemar's test is computed in two forms that answer the same question. The chi-square form is the older, approximate route; the exact form works directly with the binomial distribution of the discordant pairs. On large discordant totals they agree to several decimal places; on small ones they can differ enough to flip a verdict at the 0.05 line, which is exactly when the choice matters. This calculator always computes both, so the gap — or the agreement — is visible rather than assumed.

Chi-square form — with and without continuity correction

The chi-square statistic is χ² = (b − c)² / (b + c), referred to a chi-square distribution with 1 degree of freedom. Under the null, b and c should be close, so the numerator is small; a large imbalance drives the statistic up and the p-value down. The continuity-corrected variant, associated with Edwards, shrinks the gap before squaring: χ² = (|b − c| − 1)² / (b + c). Because counts jump in whole steps while the chi-square curve is smooth, the correction compensates for that graininess — at the price of a systematically larger, more conservative p-value. Neither is the silent default here: both are printed, the toggle in the result panel only marks which one you treat as primary, and the trade-off is conservatism against closeness to the exact calculation.

Exact form — a binomial test on the discordant pairs

The exact form ignores the chi-square curve entirely. Conditional on a pair having changed, the null hypothesis says it was a fair coin which way it moved — so the smaller of b and c is a draw from a binomial distribution with n = b + c trials and probability 0.5. The exact p-value is the two-sided binomial probability of a split at least as uneven as the one observed. It is a direct probability calculation, valid at any discordant total, and it is the same computation as an exact sign test restricted to the changed pairs. When software or a paper says "exact McNemar", this binomial calculation is what it means.

Which form should you use? — the discordant-total rule

The working rule used across textbooks and software documentation: when the discordant total b + c is below 25, report the exact binomial p; when it is 25 or more, the chi-square form (either variant) is close enough to the exact value that the choice rarely changes a conclusion. Below about 10 discordant pairs the chi-square p-values should not be quoted at all — the approximation is simply too coarse, and only the exact figure is defensible. State the rule honestly in your own work: it is guidance distilled from how fast the approximation converges, not a law, and a result sitting exactly on the threshold deserves the exact p reported alongside whichever form you headline. The verdict line in the result panel applies this rule to your own counts.

Worked example — before–after change, both forms by hand

One hundred patients are asked about a symptom before and after a treatment. The question the test answers: do the data show that the proportion of patients showing the symptom differs before and after the treatment? Forty patients have the symptom both times (a = 40) and 27 never have it (d = 27); 25 lose the symptom (b = 25) and 8 gain it (c = 8).

Before–after symptom change, a = 40, b = 25, c = 8, d = 27

The discordant pairs are b = 25 (symptom resolved) and c = 8 (symptom appeared): 33 of the 100 patients changed. The concordant 67 patients set the proportions — 65.0% had the symptom before, 48.0% after — but only the 33 changers enter the test.

  1. Read off the discordant counts: b = 25, c = 8, so b + c = 33 and b − c = 17.
  2. Chi-square form, uncorrected: χ² = (25 − 8)² / 33 = 289 / 33 = 8.758, on 1 degree of freedom, giving p = 0.0031.
  3. Chi-square form with the Edwards continuity correction: χ² = (|25 − 8| − 1)² / 33 = 256 / 33 = 7.758, giving p = 0.0053 — the correction moves the p-value up, as it always does.
  4. Exact form: the smaller discordant count is 8, tested against a binomial distribution with 33 trials and probability 0.5. The two-sided probability of a split this uneven or worse is p = 0.0046 — sitting between the two chi-square figures, closer to the corrected one.
  5. Choose what to report: b + c = 33 is at or above 25, so the chi-square form is dependable here and any of the three p-values supports the same conclusion. The paired odds ratio is 25 / 8 = 3.125, and the net change is 48.0% − 65.0% = −17.0 percentage points.

All three forms agree that the change is statistically significant: patients were about 3.1 times as likely to lose the symptom as to gain it, and the symptom's prevalence fell by 17.0 percentage points. Try other splits in the explorer below — with b + c under 25, watch the verdict switch to the exact p.

Chi-square form, uncorrected
—
Chi-square form, continuity-corrected
—
Exact binomial p
—
Paired odds ratio (b / c)
—

Effect size — paired odds ratio and net change

The p-value answers whether the imbalance between b and c is plausibly noise. The effect sizes answer how big the change is, and McNemar's test has two natural ones. The paired odds ratio is b divided by c: in the worked example, 25 / 8 = 3.125, meaning pairs were a little over three times as likely to change in the Yes-to-No direction as the reverse. Its confidence interval here is built by the log method — the standard error of ln(b/c) is the square root of (1/b + 1/c), and the interval is exponentiated back — and it is undefined when either discordant count is zero, because the ratio itself is then 0 or infinite. This page states those cases honestly instead of adding a silent half to the cells.

The net change is the difference of the two marginal proportions, (c − b) / N, reported in percentage points: the proportion with the outcome after, minus the proportion before. It is the number a clinician or a manager actually acts on, and it needs the full table — from b and c alone you know the imbalance but not the level it moved between, because the concordant counts set the base. Read the two together: the odds ratio is a relative measure that can look dramatic on a handful of pairs, while the net change is absolute and can look small on a large study even when the p-value is tiny. Neither replaces the other.

Assumptions

McNemar's test asks less of the data than most tests, but what it asks is structural — a design that breaks these conditions needs a different test, not a workaround.

  • Paired observations. Each subject (or matched pair) contributes exactly two measurements of the same binary outcome, and the pairing is real — the same person twice, or two units matched by design. Independent groups belong to Fisher's exact test or the chi-square test of independence.
  • A binary outcome, measured the same way both times. The outcome has two categories and the measurement procedure is comparable at both occasions; a changed instrument can manufacture discordant pairs that are artefacts, not change.
  • Pairs are independent of each other. One subject's change must not influence another's. Clustered data — several patients per clinician whose style shifts, repeated pairs per subject — violate this and need a clustered or mixed-effects method.
  • Each pair falls in exactly one cell. The four categories are mutually exclusive and exhaustive: every pair is concordant-Yes, discordant one way, discordant the other way, or concordant-No, with no missing second measurement quietly dropped without thought.
  • Enough discordant pairs for the form you report. The exact binomial form is valid at any discordant total, though with very few changers no result can be significant — with b + c = 5, even a 5-to-0 split gives an exact two-sided p of 0.0625. The chi-square form needs a discordant total around 25 or more before its approximation is trusted.

McNemar vs the alternatives

McNemar's test occupies a precise niche: two measurements, binary outcome, paired data. Each neighbouring test takes over when exactly one of those three conditions changes, and choosing between them is a decision about the design, not about which p-value looks better.

McNemar vs Fisher's exact test and chi-square

Fisher's exact test and the Pearson chi-square test of independence answer a question about independent groups: is the outcome associated with group membership, when each observation belongs to one group only? McNemar's test answers a question about change within subjects. The tables look identical — four counts in a square — which is exactly the trap: run the independence tests on paired data and their core assumption, that all observations are independent, fails, because each subject appears twice and their two answers are correlated. The p-values those tests return for a paired table are not slightly off; they are answers to a different question, computed as if you had twice as many independent subjects as you do. If your two samples are the same people twice, McNemar is the test; if they are genuinely different people, Fisher or chi-square is. The next section shows the numerical size of the error on a real table.

More than two time points — Cochran's Q

Decision line: the same subjects measured on a binary outcome at three or more occasions — before, during and after, say — have outgrown McNemar's test. The extension is Cochran's Q test (William G. Cochran, 1950), which generalises the discordant-pair logic across occasions; a significant Q is then followed by pairwise McNemar comparisons between occasions. Two occasions only? Stay here.

More than two outcome categories — McNemar–Bowker

Decision line: paired data whose outcome has three or more categories — agree / neutral / disagree before and after, for instance — need the McNemar–Bowker test of symmetry (A. H. Bowker, 1948), which checks whether the off-diagonal flows balance across the whole square table, not just across one diagonal pair. It is named here as the route onward, not calculated on this page: collapsing categories down to two just to use McNemar throws away data and can reverse the answer.

The wrong analysis — the same paired table through Fisher and chi-square

Here is the trap, run in numbers. Take the worked-example table — a = 40, b = 25, c = 8, d = 27, one hundred patients measured twice — and feed it to the two tests built for independent groups. Fisher's exact test returns a two-sided p of 0.0003 and Pearson's chi-square a p of 0.0002, against McNemar's exact p of 0.0046. The wrong tests look more significant, by more than a factor of ten, because they count 200 independent observations where there are 100 subjects measured twice: the pairing that halves the real information is invisible to them. With a weaker effect the same inflation can carry a result across the 0.05 line and manufacture a finding.

The demonstration below runs all three tests live on any table you enter. The McNemar figure uses only the discordant pairs, as it should; the Fisher and chi-square figures treat the four cells as two independent groups — which, for paired data, they are not. If your data are paired, the last two numbers are not a cross-check or a second opinion. They are the wrong analysis, shown so you can recognise how far wrong it goes.

McNemar's exact test (correct for paired data)
—
Fisher's exact test (wrong here)
—
Pearson chi-square test (wrong here)
—

The last two tests treat the pairs as independent groups — which they are not. Each subject appears twice in the table, so the independence assumption both tests are built on fails, and their p-values do not apply to paired data.

How to report McNemar's test (APA)

APA 7th edition style for the chi-square form is one compact sentence carrying the statistic, the degrees of freedom, the total number of pairs and the p-value: "Symptoms changed significantly after treatment, χ²(1, N = 100) = 8.76, p = .003." Add the discordant counts and the effect size so a reader can rebuild your table: b = 25 patients lost the symptom and c = 8 gained it, the paired odds ratio was 3.13, and the proportion with the symptom fell from 65.0% to 48.0%, a net change of −17.0 percentage points. For the exact form, name it and give the p directly: "An exact McNemar test (binomial test on the discordant pairs) showed a significant change, p = .005." Report p to three decimal places in APA style, as p < .001 when it falls below that, and never as p = .000.

Declare the choices a reader needs to reproduce you: which form you reported (chi-square or exact), whether the continuity correction was applied if you used the chi-square form, the alpha level, and that the test is two-sided — McNemar's test is inherently two-sided in its standard form, since change in either direction counts against the null. Software routes, with the worked-example table: in R, mcnemar.test(matrix(c(40, 8, 25, 27), nrow = 2), correct = FALSE) for the uncorrected chi-square form, or correct = TRUE for the corrected one; in Python, statsmodels.stats.contingency_tables.mcnemar([[40, 25], [8, 27]], exact = True) for the exact binomial p; in SPSS, the related-samples nonparametric route (Analyze → Nonparametric Tests → Related Samples) or Crosstabs with the McNemar option; in Stata, mcc on the paired counts. Note that R fills its matrix down columns, which is why the c and b entries swap places in that call.

Common mistakes

  • Running Fisher's exact test or a chi-square test of independence on paired data. The tables look the same, but those tests assume independent observations and paired data violate that assumption — each subject is counted twice. The wrong-analysis section above shows the error reaching a factor of ten in the p-value.
  • Judging the test by N instead of by b + c. The concordant pairs do not enter the test, so a study of 1,000 subjects with 9 discordant pairs is a small-sample test wearing a large-sample costume. Check the discordant total before trusting the chi-square form — or your power calculation.
  • Quoting the chi-square p with a tiny discordant total. With b + c under 25 the approximation can mislead, and under 10 it should not be quoted at all. Report the exact binomial p; it is a direct calculation and needs no minimum sample to be valid.
  • Choosing the continuity correction after seeing both p-values. The corrected figure is always the larger p. Deciding which to report based on which side of 0.05 they fall is a quiet form of p-hacking — pick the form (and the correction policy) before you look, or report the exact p and sidestep the choice.
  • Feeding the calculator percentages instead of counts. McNemar's test is built from counts of pairs. Percentages throw away the discordant total, and with it everything that decides which form is valid and how much evidence the table holds.
  • Applying McNemar's test to two independent groups. The mirror-image error: two different samples measured once each have no pairing to exploit, and forcing them into a paired table invents pairs that do not exist. That design belongs to Fisher's exact test or the chi-square test of independence.
  • Reading a significant result as a large effect. The p-value measures the imbalance between b and c against chance; the size of the change lives in the paired odds ratio and the net change in percentage points. Report them together.
  • Treating b + c = 0 as a non-significant result. If no pair changed, there is no test and no p-value — not evidence of no effect, just no information about change. The calculator says so plainly rather than printing p = 1.

Frequently asked questions

What is McNemar's test used for?

McNemar's test is used to compare two paired proportions: the same subjects measured twice on a binary outcome, such as symptom present or absent before and after a treatment, pass or fail before and after a course, or the verdicts of two raters on the same cases arranged as matched pairs. It tests whether the proportion with the outcome changed between the two measurements, using only the pairs whose outcome actually changed — the discordant pairs b and c.

When should I use McNemar instead of Fisher's exact test?

Use McNemar's test whenever the two samples are the same subjects measured twice (or deliberately matched pairs): the observations are paired, so they are not independent. Fisher's exact test assumes independent groups — different subjects in each group, each measured once. Running Fisher on paired data treats each subject as two independent observations, which breaks the independence assumption and can shrink the p-value by an order of magnitude, as the wrong-analysis demonstration on this page shows. Same people twice: McNemar. Different people: Fisher.

How many discordant pairs do I need for McNemar's test?

It depends on the form. The exact binomial form is valid at any discordant total, though very small totals cannot reach significance — even a 5-to-0 split of 5 discordant pairs gives an exact two-sided p of 0.0625. The chi-square form needs a discordant total of roughly 25 or more before its approximation is trusted, which is why this calculator recommends the exact p below that. What matters is b + c, not the total sample size: concordant pairs add nothing to the test, so plan studies around the number of subjects you expect to change.

What is the exact McNemar test?

The exact McNemar test replaces the chi-square approximation with a direct binomial calculation. Take the discordant pairs — the subjects who changed — and ask: if change were directionless, so each changed pair was equally likely to move either way, how probable is a split at least as uneven as the one observed? Formally it is a two-sided binomial test of the smaller of b and c against a binomial distribution with n = b + c trials and probability 0.5. It is exact in the sense that no large-sample approximation is involved, and it is the form to report when the discordant total is small.

Why does McNemar's test ignore the pairs that didn't change?

Because a pair that did not change cannot distinguish the null hypothesis from its alternative. A subject who was Yes both times shows the outcome happens, but says nothing about whether it became more or less common — the same information would be present if the proportions had not moved at all. All the evidence about change sits in the balance between the two directions of change, b versus c, so the test is built from those counts alone. The concordant pairs still matter for describing the data: they set the before and after proportions and the net change.

Should I use the continuity correction?

The Edwards continuity correction subtracts 1 from |b − c| before squaring, compensating for the fact that counts move in whole steps while the chi-square distribution is smooth. It always makes the chi-square statistic smaller and the p-value larger — more conservative, and usually closer to the exact binomial p in small samples. The cleanest policy: when the discordant total is small enough for the question to matter, report the exact binomial p and the correction question disappears. When b + c is large, corrected and uncorrected values nearly coincide. What you should not do is compute both and report whichever crosses 0.05 — decide the policy before looking at the results.