FISHER'S EXACT TEST · BARNARD · BOSCHLOO · MID-P · CHI-SQUARE · ODDS RATIO · CMH · MCNEMAR · RUNS IN YOUR BROWSER · NOTHING UPLOADED

Do these two groups differ, or is it chance?

Type four counts, or paste a table: treated versus control and how many recovered, a variant's conversions against the control's, defects by supplier, survey answers by age band. You get Fisher's exact test and, beside it, the exact tests that lose less power: Boschloo's and Barnard's unconditional tests and the mid-p.

Every 2x2 also gets the chi-square tests, the odds ratio (sample and exact conditional), the risk ratio and the risk difference with confidence intervals. Bigger tables get the exact Fisher-Freeman-Halton test and the cells that drive it; tables split by site or department get Cochran-Mantel-Haenszel and a check for Simpson's paradox; before-and-after data on the same people get McNemar's test.

Nothing you enter leaves this browser tab. Statistical output from counts you supply, not advice. Not legal, tax, or financial advice, and not medical advice.

A 2x2 table

Or a table of any size, by strata, or one row per subject

Paste a table or load an example.

Settings

Method and citation

Fisher's exact test. With both margins fixed, the first cell of a 2x2 table is hypergeometric (Fisher 1935). The two-sided p-value adds the probabilities of every table no more probable than the observed one (within a relative 10⁻⁷, as R and scipy do); the one-sided values add a tail. The odds ratio it goes with is the conditional maximum likelihood estimate, the noncentral hypergeometric mean set equal to the observed count, and its interval inverts the one-sided tests (Cornfield's method, as R's fisher.test). The mid-p takes half the observed table's probability off (Lancaster 1961).

Unconditional tests. Most studies fix only the group sizes. Barnard (1945) orders all (n₁+1)(n₂+1) possible outcomes by the z statistic for p₁ − p₂, and Boschloo (1970) by Fisher's one-sided p-value; the p-value is the probability of an outcome at least as extreme, maximised over the unknown common risk π, here on a 1,000-point grid polished by golden-section search. Boschloo's two-sided value is twice the smaller one-sided value, as in scipy.

Larger tables. The Fisher-Freeman-Halton test (Freeman & Halton 1951) sums the probabilities of every table with the same margins that is no more probable than the observed one. Tables are built a column at a time as paths through a network of remaining row totals (Mehta & Patel 1983): partial tables of equal probability arriving at the same node are merged, and a subtree whose most and least probable completions both fall on one side of the observed table is added or dropped whole, using its closed-form total. Past 5 million steps or 6 seconds the tool falls back to 20,000 random tables with both margins fixed and says so. Adjusted residuals (Haberman 1973) show which cells are above or below independence; beyond ±1.96 they are shaded.

Strata. The Cochran-Mantel-Haenszel statistic (Mantel & Haenszel 1959) adds each stratum's first cell minus its expectation, over the summed hypergeometric variances, with R's continuity correction. The common odds ratio's interval uses the Robins-Breslow-Greenland (1986) variance. Breslow-Day with Tarone's (1985) correction tests whether the strata share an odds ratio. The exact stratified test uses the convolution of the strata's hypergeometric distributions, and gives a conditional MLE of the common odds ratio with an exact interval.

Paired. McNemar (1947) uses only the discordant pairs b and c: chi-square (b − c)²/(b + c), with or without the continuity correction, and the exact binomial test of b out of b + c at one half, with its mid-p.

Effect sizes. Risk difference with the Newcombe (1998) hybrid score interval and the Wald interval; risk ratio with the Katz et al. (1978) log interval; sample odds ratio with Woolf's (1955) interval (0.5 added to every cell when one is zero, and the table says so); phi; and the number needed to treat, 1/|risk difference|.

Verified by tests in the source: on 69 tables, Fisher's p-values (all three alternatives) match scipy 1.18.1 to 10⁻⁹ and the conditional odds ratio and its interval to 10⁻⁶; chi-square, Yates, G, Woolf, Katz and Newcombe match scipy and statsmodels 0.15.0; on 8 strata sets CMH, the Mantel-Haenszel odds ratio and interval, Breslow-Day and Tarone match statsmodels; McNemar matches statsmodels; the r x c exact p-value equals plain enumeration of every table on 16 tables; and R's documented values are reproduced (twins 0.0004652, job satisfaction 0.7827, penicillin and rabbits CMH 0.047, exact 0.040 and one-sided 0.020). Barnard's and Boschloo's p-values are never below the maximum of the same function on a 10,001-point grid. In 22 of the Barnard p-values scipy reports a lower number; in every one, a table whose statistic equals the observed one in exact rational arithmetic was left out because the two floating-point values differ in the last bit.

BibTeX

@article{fisher1935logic,
  author  = {Fisher, R. A.},
  title   = {The logic of inductive inference},
  journal = {Journal of the Royal Statistical Society},
  volume  = {98}, number = {1}, pages = {39--82}, year = {1935},
  doi     = {10.2307/2342435}
}
@article{barnard1945new,
  author  = {Barnard, G. A.},
  title   = {A new test for 2 x 2 tables},
  journal = {Nature}, volume = {156}, pages = {177}, year = {1945},
  doi     = {10.1038/156177a0}
}
@article{boschloo1970raised,
  author  = {Boschloo, R. D.},
  title   = {Raised conditional level of significance for the 2 x 2-table when testing the equality of two probabilities},
  journal = {Statistica Neerlandica}, volume = {24}, number = {1}, pages = {1--9}, year = {1970},
  doi     = {10.1111/j.1467-9574.1970.tb00104.x}
}
@article{mehta1983network,
  author  = {Mehta, Cyrus R. and Patel, Nitin R.},
  title   = {A network algorithm for performing {F}isher's exact test in r x c contingency tables},
  journal = {Journal of the American Statistical Association},
  volume  = {78}, number = {382}, pages = {427--434}, year = {1983},
  doi     = {10.1080/01621459.1983.10477989}
}
@article{lydersen2009recommended,
  author  = {Lydersen, Stian and Fagerland, Morten W. and Laake, Petter},
  title   = {Recommended tests for association in 2 x 2 tables},
  journal = {Statistics in Medicine}, volume = {28}, number = {7}, pages = {1159--1175}, year = {2009},
  doi     = {10.1002/sim.3531}
}
@article{mantel1959statistical,
  author  = {Mantel, Nathan and Haenszel, William},
  title   = {Statistical aspects of the analysis of data from retrospective studies of disease},
  journal = {Journal of the National Cancer Institute},
  volume  = {22}, number = {4}, pages = {719--748}, year = {1959},
  doi     = {10.1093/jnci/22.4.719}
}

Limits

Questions

When should I use Fisher's exact test instead of chi-square?

When any expected count is below about 5, the chi-square p-value can be badly off, and in this tool's exact calculation Pearson's chi-square rejects a true null up to 6.5% of the time at a nominal 5% with 25 per group. An exact test never exceeds its level. But Fisher's test is conservative: with 20 per group its real false-positive rate averages 1.9%, so it also misses real differences. Boschloo's test is exact too and more powerful, so it is the better default for two independent groups.

What is the difference between Fisher's, Barnard's and Boschloo's tests?

Fisher's test fixes both margins of the table and uses the hypergeometric distribution. Barnard's and Boschloo's tests fix only the group sizes, as in most studies, and take the largest p-value over the unknown common risk, so they never exceed the level either. Barnard orders tables by the z statistic, Boschloo by Fisher's own p-value, which makes Boschloo uniformly more powerful than Fisher.

What is the mid-p value?

Fisher's p-value with only half the probability of the observed table counted. It is not guaranteed to stay below the level, but it is much closer to it than Fisher's test; in this tool's exact calculation it stayed under 5% at every group size from 10 to 50.

Which odds ratio does the tool report?

Two. The sample odds ratio ad/bc with Woolf's interval, and the conditional maximum likelihood estimate with its exact interval, which is what R's fisher.test and scipy's odds_ratio report. They are close in large samples and differ in small ones; the exact interval agrees with Fisher's test.

When do I need the Cochran-Mantel-Haenszel test?

When the groups were compared within strata such as sites, departments, age bands or study centres. Pooling the strata can hide or reverse an association, as in the Berkeley admissions example: men were admitted more often overall, but not within departments. The test combines the strata, and the Breslow-Day-Tarone test says whether they share one odds ratio.

When do I need McNemar's test?

When the two measurements are on the same people or on matched pairs, such as before and after, or two tests on one sample. Only the pairs that changed carry information. With fewer than 25 changed pairs, use the exact or mid-p version.

Is my data uploaded anywhere?

No. The counts or file are read and analysed by JavaScript in this browser tab. There are no accounts, cookies or analytics vendors.

Example data: graduate applications to the six largest departments of the University of California, Berkeley, in fall 1973 (Bickel, Hammel & O'Connell 1975, Science 187, 398-404), as R's UCBAdmissions dataset, retrieved from the Rdatasets collection on 2026-11-17; the twin convictions and job-satisfaction tables are the examples in R's fisher.test documentation, which cites Fisher (1962, 1970) and Agresti (2002, p. 57).