Advertisement
Advertisement
STATISTICS

McNemar's Test Calculator — paired 2×2 tables, four p-values

Enter the four cells of a matched-pairs table and get the asymptotic, continuity-corrected, exact conditional and mid-p results side by side, with the discordant counts that drive all of them.

Pairs where both measurements agreed on the outcome of interest.
A discordant pair. This cell and cell c are the only ones the test uses.
The other discordant cell. Swapping b and c leaves every p-value unchanged.
Pairs where both measurements agreed on the absence of the outcome.
Used only to phrase the comparison. It does not change any p-value the tool reports.
Mid-p two-sided p-value
0
 
0
Asymptotic χ² (no correction)
0
Asymptotic p-value
0
Continuity-corrected p-value
0
Exact conditional p-value
Working:
Tip: the concordant cells a and d never enter the arithmetic. If the four p-values disagree with each other, the discordant total b + c is small and the disagreement is about approximation quality, not about the data.
Advertisement

The McNemar's test calculator above tests whether two paired binary measurements have the same marginal proportion. It is the test you need when the same subject was measured twice — before and after, test A and test B, rater one and rater two — and each measurement produced a yes or no. The pairing is the whole point: the two measurements are correlated because they come from the same subject, and a test that assumes independent groups will give you the wrong answer.

Arb Digital publishes it because paired binary data turns up constantly in work that has nothing to do with medicine, where it started. Two ad creatives shown to the same panel, two spam filters run over the same inbox, two classifiers scored on the same holdout set, a survey question asked before and after a campaign. In all of those the subjects are shared, and our chi-square calculator is the wrong tool because it assumes the rows are independent samples. This page is the paired counterpart, and the boundary between the two is the single most common mistake in this corner of statistics.

What This McNemar's Test Calculator Does

It takes the four cells of a 2×2 table of pairs and reports four different p-values for the null hypothesis that the two marginal proportions are equal. The four are the asymptotic chi-square test, the same test with Edwards' continuity correction, the exact conditional test based on the binomial distribution, and the mid-p test. It also reports the difference in proportions, the ratio of the discordant counts, and the size of the discordant total that all four tests actually depend on.

Presenting four is deliberate. These tests do not agree, and the literature does not treat them as interchangeable. Showing one and hiding the rest would let you report whichever number happened to fall on the convenient side of your threshold without ever knowing that the alternatives existed. The bars plot all four together so the spread is visible at a glance.

The tool does not tell you whether to reject anything. It reports the p-values and the counts, phrases the comparison against the level you enter, and leaves the decision where it belongs.

How to Use It

  1. Build the table by pairs, not by observations. Each of the four cells counts pairs. A study of 200 subjects measured twice has 200 pairs, not 400 rows.
  2. Enter b and c carefully. Cell b is the count where the first measurement was positive and the second was negative; cell c is the reverse. These two are the test.
  3. Enter a and d for completeness. They appear in the proportions and in the sample size but not in any p-value.
  4. Read the discordant total. If b + c is under about 25, the asymptotic tests are approximations of an approximation and the mid-p or exact result is the one to quote.
  5. Compare the bars before you decide anything. A result that is significant under one variant and not under another is a result that needs a larger sample, not a choice of variant.

The Formula and How It Is Calculated

Label the paired table with a for pairs positive on both measurements, b and c for the two discordant patterns, and d for pairs negative on both. The two marginal proportions are (a + b) divided by n and (a + c) divided by n, so their difference is exactly (b − c) divided by n. The concordant cells cancel, which is why the test uses only b and c.

Under the null hypothesis, each discordant pair is equally likely to fall in b or in c, so b behaves like a binomial count out of b + c trials with probability one half. The asymptotic test statistic is (b − c)² divided by (b + c), compared to a chi-square distribution with one degree of freedom. Penn State's STAT 504 lesson on dependent samples in two-way tables derives this as the test of marginal homogeneity for a 2×2 table.

Edwards' continuity correction subtracts one from the absolute difference before squaring, giving (|b − c| − 1)² divided by (b + c). The exact conditional test drops the approximation entirely and computes the two-sided binomial tail directly: twice the probability that a binomial with b + c trials and success probability one half lands at or below the smaller of b and c, capped at one. The mid-p test subtracts half the probability of the observed point before doubling, which removes the systematic conservatism the exact test inherits from the discreteness of the binomial.

Advertisement

Which Of The Four You Should Report

The evidence here is unusually clear, and it does not favour the version most software prints by default. Fagerland, Lydersen and Laake evaluated all four across nearly ten thousand scenarios and published the results in BMC Medical Research Methodology as "The McNemar test for binary matched-pairs data: mid-p and asymptotic are better than exact conditional". Their conclusion is that the mid-p test can be recommended in any situation, that the asymptotic test is acceptable if small but frequent violations of the nominal level are tolerable, and that they do not recommend the exact conditional test or the asymptotic test with continuity correction in any situation.

That is worth restating because it inverts a common instinct. The exact test sounds like the safe choice — it is exact, after all — but its exactness is about the conditional distribution, not about the error rate, and in practice it is conservative: it rejects less often than the nominal level, which costs power without buying protection. The continuity correction pushes in the same direction, and harder. If you have been reporting the corrected chi-square because it seemed cautious, you have been paying for caution you did not need.

None of this makes the other three wrong to compute. Reviewers and reporting standards in some fields still expect the exact figure, and it is useful to know when your conclusion survives all four. This tool computes all four so that you can see the answer to that question rather than assuming it.

Why The Concordant Cells Are Discarded

Newcomers to the test usually object at this point. You collected 200 pairs, 170 of them agreed, and the test throws all 170 away. That feels like discarding most of the data.

It is not, and the reason is worth understanding. The question McNemar's test asks is whether the two marginal proportions differ. A pair that was positive on both measurements contributes equally to both margins, so it contributes nothing to their difference. The same is true of a pair negative on both. Only the discordant pairs can move the two margins apart, so only they carry information about the hypothesis being tested.

The concordant cells are not useless in general — they carry information about the strength of the association between the two measurements, and about agreement, which is what Cohen's kappa measures. They just carry no information about the specific question of whether the margins are equal. If your real question is about agreement rather than about a shift, McNemar's test is answering something you did not ask.

The Boundary With Independent-Sample Tests

The most consequential error in this area is running an independent-groups test on paired data. If you have 100 subjects each tested by two methods and you build a table of method against result — 200 rows, two groups of 100 — you have thrown away the pairing, and our chi-square test of independence will treat two measurements of the same subject as two unrelated observations. Because paired measurements are positively correlated, that inflates the standard error and costs you power. The pairing is an asset; discarding it makes the study weaker than it is.

The mirror-image error is running McNemar's test on data that are not paired. Two independent groups of customers, two separate cohorts, two different mailing lists — there is no correspondence between row i of one group and row i of the other, so there are no discordant pairs to count, and constructing them by arbitrary pairing manufactures a result out of nothing. For genuinely independent proportions on small counts, our Fisher's exact test calculator is the right choice; for a conversion-rate comparison in the form most experiment platforms expect, the A/B test calculator handles it.

Sample Size, Power And The Discordant Total

An unusual feature of this test is that its power depends almost entirely on b + c rather than on n. Two studies with the same number of subjects can have wildly different power if one produced 12 discordant pairs and the other produced 90. That has a practical consequence: when you plan a paired study, the quantity you need to estimate is the discordant rate, not the outcome rate.

Highly correlated measurements — two tests that usually agree, a before-and-after with a small effect — produce very few discordant pairs, and a paired design with 500 subjects can end up with the power of an unpaired design with 40. Enter b = 6 and c = 1 in the tool and watch how far apart the four p-values become; that spread is a direct signal that the discordant total is too small for any of them to be trusted very far. Our statistical power calculator and sample size calculator cover the general planning arithmetic.

The ratio b divided by c also has a natural reading as a conditional odds ratio for the paired design, and it is reported in the working line. It says how many times more often the shift went one way than the other among the pairs that shifted at all. Unlike the p-value, it does not shrink as the sample grows, which makes it the better number to report alongside the test.

Extensions This Page Does Not Cover

McNemar's test handles two paired binary measurements and nothing else. Three or more repeated binary measurements need Cochran's Q, which is the natural generalisation. A paired table with more than two outcome categories needs the Stuart-Maxwell test for marginal homogeneity, or Bowker's test for symmetry, both of which reduce to McNemar's test in the 2×2 case. Paired continuous data needs a paired t-test or a signed-rank test instead.

Clustered paired data — several pairs from the same clinic, school or account — breaks the independence assumption between pairs, which McNemar's test still requires even though it drops independence within a pair. In that situation a conditional logistic regression or a generalised estimating equation is the correct route, and the plain test will overstate significance. If you are comparing two diagnostic procedures, the paired structure also affects how you compare sensitivity and specificity; our sensitivity and specificity calculator computes those measures for a single test.

Comparing two versions on the same audience?

Arb Digital designs tests where the pairing is preserved in the analysis, because throwing it away is the most common way a well-designed experiment ends up underpowered.

Browse All Free Tools Talk To Our Team

Common Mistakes to Avoid

  • Filling the table with observations instead of pairs — every cell counts pairs, and the four cells must sum to the number of subjects, not to twice that.
  • Using an independent-groups chi-square on paired data — it discards the correlation that the paired design was built to exploit and loses power for nothing.
  • Reporting the continuity-corrected p-value as the cautious option — it is conservative rather than accurate, and the published comparison recommends against it.
  • Ignoring the size of b + c — the test's power lives there, and a large n with a tiny discordant total is a small study wearing a disguise.
  • Quoting a p-value with no effect measure — the difference in proportions and the ratio b to c say how big the shift was, which the p-value never does.

Related Free Tools From Arb Digital

Test independent categorical groups with the chi-square calculator, handle small independent 2×2 tables with the Fisher's exact test calculator, convert a test statistic with the p-value calculator, size a study with the sample size calculator, or quantify the size of a difference with the effect size calculator. The free online tools hub lists every statistics tool we publish.

Frequently Asked Questions

Why does McNemar's test ignore cells a and d?

Because a pair that agreed on both measurements contributes identically to both marginal proportions, so it cannot move them apart. Only the discordant pairs carry information about whether the margins differ.

Which of the four p-values should I report?

The published comparison by Fagerland, Lydersen and Laake recommends the mid-p test in any situation and accepts the plain asymptotic test. It recommends against the exact conditional test and against the continuity-corrected version.

When is the sample too small for the asymptotic test?

The usual guidance is that the discordant total b plus c should be at least about 25. Below that, quote the mid-p result and treat the chi-square figure as an approximation.

Can I use a chi-square test of independence instead?

Not on paired data. That test assumes the rows are independent observations, and two measurements of the same subject are not. Using it discards the pairing and reduces power.

What if I have three or more repeated measurements?

Use Cochran's Q test, which generalises McNemar's test to more than two paired binary measurements. This calculator handles the two-measurement case only.

Does swapping cells b and c change the result?

No. Every p-value depends on the absolute difference between b and c and on their total, so swapping them leaves all four unchanged. Only the sign of the reported proportion difference flips.

Is McNemar's test the same as a test of agreement?

No. It tests whether the two marginal proportions are equal, not whether the two measurements agree pair by pair. Agreement is measured by Cohen's kappa, which uses the concordant cells this test discards.

This page explains a standard statistical test for educational purposes. It reports p-values from counts you enter and makes no clinical, diagnostic or research recommendation; interpretation of any study belongs with a qualified statistician and the reporting standards of your field.

Advertisement
Advertisement

Take it further