Run Fisher's exact test on 2 × 2 and r × c contingency tables with two-sided and one-sided exact p-values, mid-p adjustment, odds ratio with exact 95% CI, and Barnard's and Boschloo's unconditional exact tests. Reproducible R, Python, and APA output for small-sample categorical data.
| Event | No event | Total | |
|---|---|---|---|
| Treatment | 20 | ||
| Control | 20 | ||
| Total | 15 | 25 | 40 |
Use Fisher's exact when any expected cell count is below 5, when the total N is small, or when an exact p-value is required by your guideline (CONSORT, regulatory). For sparse 2×2 tables Fisher beats Pearson's chi-square, which relies on a large-sample approximation. The conditional MLE odds ratio with its exact confidence interval (the value R's fisher.test reports) is shown alongside the sample odds ratio; the latter uses a Haldane-Anscombe (+0.5) correction only when any cell is zero.
Ronald A. Fisher introduced his exact test for 2 × 2 contingency tables in a 1922 paper on the interpretation of χ² (and famously again in The Design of Experiments, 1935, in the discussion of the lady tasting tea). The motivation was sparse data: Pearson's chi-square statistic Σ(O − E)² / E is asymptotically χ²(1)-distributed, but the approximation breaks down when expected cell counts fall below 5. Rather than approximate, Fisher's test enumerates every 2 × 2 table with the same row and column totals as the observed one and computes the exact probability of each under the hypergeometric distribution. Summing the probabilities of tables at least as extreme as the observed gives a p-value that is exactly calibrated regardless of sample size.
The hypergeometric framing is conditional: both row totals (r₁, r₂) and column totals (c₁, c₂) are treated as fixed. In the lady-tasting-tea setup that is literally true, because the experimenter pre-specifies how many cups of each kind to serve. But in most modern applications only one set of marginals is fixed by design (the row totals in a randomised trial; neither in an observational cohort). Conditioning on the random marginal too is the price Fisher pays for the elegant exact computation, and it is also the source of conservatism: the observed table contributes its full probability mass to both tails, inflating the p-value. The mid-p adjustment (Lancaster 1961) halves the observed-table contribution and is the recommended compromise for sparse observational data.
The unconditional exact tests of Barnard (1945) and Boschloo (1970) take a different route: only the row totals are fixed, the columns are random under the null, and the unknown common success probability π is treated as a nuisance parameter. The p-value is then maximised over π on a grid. This restores the power that Fisher loses to conditioning. Boschloo's test specifically uses Fisher's p-value as the test statistic and, by maximising over π, dominates Fisher's: for every 2 × 2 table the Boschloo p is ≤ the Fisher p. The calculator computes both via grid search up to N = 80; beyond that, defer to R's Exact::exact.test or Python's scipy.stats.boschloo_exact which use the convex-optimisation algorithm of Lloyd (2008).
For tables larger than 2 × 2, Freeman and Halton (1951) extended Fisher's idea: the probability of any r × c contingency table with fixed row and column marginals follows a multivariate hypergeometric distribution. Exact enumeration is feasible only for small tables; the number of admissible tables explodes combinatorially. The calculator runs a Monte Carlo permutation (default 10 000 shuffles), reports the simulated p-value together with its binomial standard error, and uses the log-probability of each permuted table as the order statistic. The same approach powers R's fisher.test(simulate.p.value = TRUE) and is the standard modern recommendation for r × c tables with sparse cells. For definitive results, full enumeration is available via R's fisher.test(workspace = 2e8) and StatXact's network algorithm.
Beyond the p-value, the calculator reports the conditional maximum-likelihood odds ratio with its exact confidence interval, computed directly from Fisher's noncentral hypergeometric distribution (the same estimate R's fisher.test returns), alongside the sample odds ratio with a log-Wald CI (Haldane-Anscombe +0.5 correction when any cell is zero), the risk ratio, the absolute risk difference, and the number needed to treat (NNT). The clinical audience needs all four: OR exaggerates RR when the outcome is common, while ARD and NNT translate the statistical association into a treatment-decision quantity. For regulatory submissions (FDA, EMA), the exact mid-p CI on the OR via the central method (Vollset 1993) is also defensible: compute it in R with exact2x2::exact2x2(tbl, tsmethod = "central").
Fisher's exact test feeds into other tools in the suite. For a full 2 × 2 analysis with all four effect measures (OR, RR, ARD, NNT) and Haldane corrections, use the odds ratio calculator or the relative risk calculator. For Pearson's chi-square with Cramér's V and Yates' correction, use the chi-square calculator. For one-sample binomial probabilities and exact tests on a single proportion, use the binomial probability calculator. And for full categorical-data analysis with logistic regression, McNemar's test for paired data, and a publication-ready APA write-up by a PhD statistician, the statistical analysis service covers everything end-to-end.
2×2 Fisher for two-group binary comparisons (default); r×c for tables with more than two rows or columns; Barnard / Boschloo for unconditional exact tests when both row sizes are fixed by design.
Type the four cells a, b, c, d directly, or paste a full r×c matrix with one row per line. All values must be non-negative integers.
Two-sided exact p (highlighted) is the default report. Also shown: one-sided p(X ≤ a) and p(X ≥ a), plus the mid-p versions for less conservative inference on sparse data.
Odds ratio with 95% CI (Haldane-Anscombe correction when sparse), risk ratio, absolute risk difference, NNT, and the expected counts under independence.
The Barnard / Boschloo tab returns unconditional exact tests via grid search over the nuisance parameter. Boschloo's is uniformly more powerful than Fisher's for the standard 2×2 independence test.
Reproducible snippets paste straight into RStudio (fisher.test, exact2x2, Exact::exact.test) or Jupyter (scipy.stats.fisher_exact, barnard_exact, boschloo_exact). APA includes cells, OR, 95% CI, and exact p.
Next step
A PhD statistician handles stratified Mantel-Haenszel pooling, conditional logistic regression for matched designs, exact mid-p confidence intervals, and a publication-ready APA results section.
Our promise: Free re-run and re-write if reviewers question the analysis or reporting.
Timeline
Most projects deliver in under 2 weeks. We confirm an exact date in your quote.
If reviewers push back
If reviewers question the analysis, assumptions, or reporting, we re-run and re-write free.
Confidentiality
NDA available on request before any project discussion. Your data, study design, and manuscript stay private either way.
Want a PhD methodologist to handle the whole project?
Get a complete categorical analysis with conditional and unconditional exact tests, exact CIs on the OR and RR, stratified Mantel-Haenszel pooling, logistic regression, and APA-formatted reporting by a PhD statistician. Free re-run and re-write if reviewers question the analysis or reporting. Pay only after you approve your quote.
P(X = a) = C(r₁, a) × C(r₂, c₁ − a) / C(n, c₁)
The probability of observing cell a given fixed row totals r₁, r₂ and column totals c₁, c₂. Fisher's exact p sums P(X = k) over all tables with PMF ≤ the observed table's PMF. R: dhyper(a, r1, r2, c1). Python: scipy.stats.hypergeom.pmf(a, n, r1, c1).
p = Σ P(X = k) over k where P(X = k) ≤ P(X = a_obs)
R's default for fisher.test(). Sums the PMF over the tail in BOTH directions where the table is at least as 'extreme' as observed. Mid-p halves the observed-table contribution: p_mid = p − P(X = a_obs) / 2.
OR = (a × d) / (b × c) Haldane-Anscombe: add 0.5 if any cell = 0
Log-Wald 95% CI: log(OR) ± 1.96 × √(1/a + 1/b + 1/c + 1/d). For definitive small-sample inference use conditional MLE with central or minlike exact CI (exact2x2::exact2x2).
p_B = sup over π in (0,1) of P(p_Fisher(X, Y) ≤ p_Fisher(a, c) | π)
Maximises Fisher's p over the nuisance parameter π. Uniformly more powerful than Fisher for 2×2 independence tests. R: Exact::exact.test(tbl, method = 'boschloo'). Python: scipy.stats.boschloo_exact(table).
Z(X, Y) = (X/n₁ − Y/n₂) / √(π̂(1 − π̂)(1/n₁ + 1/n₂))
Same maximisation principle as Boschloo but using the pooled z-statistic as the order statistic. Original 1945 unconditional test. Python: scipy.stats.barnard_exact(table).
P(table) ∝ Π r_i! × Π c_j! / (n! × Π x_ij!)
Probability of any r × c table with fixed row and column marginals. The calculator's Monte Carlo permutation samples 10 000 shuffles by default and counts the fraction at least as extreme as observed. R: fisher.test(m, simulate.p.value = TRUE, B = 1e5).
A Fisher's exact test write-up needs four things: the justification (an expected cell count below 5), the two-sided exact p value, the odds ratio with its exact confidence interval, and the absolute risks per group. Because the exact test has no test statistic like χ², there is no statistic-with-degrees-of-freedom to report; the p value and effect estimate carry the result. Using the calculator's default table (12/8 versus 3/17):
Fisher's exact test was used to examine the association between group and outcome across 40 observations, because the smallest expected cell count fell below 5. The association was statistically significant, two-sided exact p = .008. The conditional maximum-likelihood odds ratio was 8.00, exact 95% CI [1.57, 56.86]. Events occurred in 60.0% of the treatment group versus 15.0% of controls.
Note that the odds ratio reported with an exact test should be the conditional maximum-likelihood estimate (8.00 here), which differs from the sample cross-product ratio (8.50); statistical reviewers check this. The APA Report button downloads the write-up as a Word document with the labeled contingency table in APA format, the risks and number needed to treat, a plain-English interpretation, and a reporting checklist covering the exact-versus-mid-p choice.
Fisher's exact test is a statistical procedure for analysing 2 × 2 contingency tables, developed by Ronald A. Fisher (1922; 1934). It calculates the exact probability of observing the data under the null hypothesis of independence by enumerating every possible table with the same row and column marginals as the observed one, using the hypergeometric distribution. Unlike Pearson's chi-square test, it makes no large-sample approximation, so it remains valid for small samples and sparse cells.
Use Fisher's exact test when (1) any expected cell count falls below 5, (2) the total sample size is small (roughly N < 40), or (3) your reporting guideline requires an exact p-value (e.g., CONSORT for small RCTs, regulatory submissions, rare-event analyses). Pearson's chi-square relies on a large-sample approximation that becomes unreliable with sparse data and tends to inflate Type I error. For large balanced tables both tests agree closely; for small or sparse data, prefer Fisher.
Fisher's test is conditional: it fixes both the row and column marginals at their observed values, which simplifies the computation by reducing the sample space to a single hypergeometric distribution. Barnard's (1945) and Boschloo's (1970) tests are unconditional: only the row totals are fixed by design, while the column totals are random under the null. By maximising the p-value over the unknown common success probability (the nuisance parameter), unconditional tests recover power. Boschloo's is uniformly more powerful than Fisher's for the standard 2 × 2 independence test and is the modern recommendation when both row sizes are fixed by the design (e.g., a randomised trial with pre-specified arm sizes).
The standard Fisher p-value is conservative because the hypergeometric distribution is discrete: the observed table contributes its full PMF to both tails. The mid-p adjustment (Lancaster 1961) attributes only half of the observed table's PMF to each tail, producing a less conservative but still valid p-value on average. Mid-p is widely recommended for sparse-cell observational data and meta-analyses where the strict conservatism of Fisher loses power. R provides it via epitools::oddsratio.fisher() and exact2x2::exact2x2(tsmethod = "central").
The calculator reports two odds ratios. The primary one is the conditional maximum-likelihood odds ratio with an exact confidence interval, computed from Fisher's noncentral hypergeometric distribution: the point estimate is the value whose conditional mean equals the observed cell, and the 95% interval is found by inverting the two one-sided exact tests. This is the same quantity R's fisher.test() and Python's scipy.stats.contingency.odds_ratio(kind='conditional') return, and it is the value to report in a paper. The calculator also shows the sample odds ratio (a × d) / (b × c) with a log-Wald 95% CI (SE = √(1/a + 1/b + 1/c + 1/d)); when any cell is zero, a Haldane-Anscombe +0.5 correction keeps that sample estimate defined. For sparse data the conditional estimate and exact interval are preferred because the Wald interval becomes unreliable.
Fisher's original test was defined for 2 × 2 tables. Freeman and Halton (1951) generalised it to general r × c tables by enumerating every table with the same row and column marginals. Exact enumeration becomes computationally infeasible past small tables, so the calculator runs a Monte Carlo permutation (default 10 000 random shuffles of the cell allocations subject to the fixed marginals) and reports the simulated p-value with its standard error. R's fisher.test(simulate.p.value = TRUE, B = 1e5) is the standard reference; full enumeration uses fisher.test(workspace = 2e8).
Three assumptions. (1) Observations are independent, with no clustering or repeated measures (use McNemar's for paired binary data). (2) The two classifications (row variable and column variable) are categorical with mutually exclusive levels. (3) The marginals are treated as fixed by design (a debated point for retrospective observational data where neither marginal is truly fixed, in which case Barnard's unconditional test is then more appropriate). Fisher's test does NOT require normality or large samples, which is its key advantage over chi-square.
The odds ratio (OR) is (a × d) / (b × c) for cells [[a, b], [c, d]]. OR = 1 means the exposure has no association with the outcome. OR > 1 means the exposed group has higher odds of the outcome than the unexposed; OR < 1 means lower odds. The 95% CI tells you the range of population OR values consistent with your data; if the CI excludes 1, the association is statistically significant at α = 0.05. For interventions, also report the risk ratio (RR), risk difference (ARD), and NNT for clinical interpretation. The OR overstates the RR when the outcome is common (> 10%); use RR or absolute risk for prevalent outcomes.
The two tests answer the same question with different distributions. Pearson's chi-square computes Σ(O − E)² / E and refers it to a χ²(1) distribution, a continuous large-sample approximation. Fisher's enumerates all hypergeometric tables with the same marginals and counts the exact tail probability, a discrete exact computation. For large balanced tables (all expected counts ≥ 5) the two p-values agree to two decimal places. For sparse data, chi-square is anti-conservative (rejects too often) while Fisher remains exactly calibrated.
Report the 2 × 2 table (a, b, c, d), the two-sided exact p-value, and an effect measure with its 95% CI. APA example: 'A Fisher's exact test on the 2 × 2 table of treatment by outcome (treatment events = 12/20; control events = 3/20) showed a significant association, p = .009, OR = 8.50, 95% CI [1.84, 39.21].' For unconditional tests add the method: 'Boschloo's exact test, p = .006.' For r × c tables: 'Fisher-Freeman-Halton exact test (Monte Carlo, 10 000 iterations), p = .032.' Always state which method (Fisher conditional, Fisher mid-p, Barnard, Boschloo, Freeman-Halton) was pre-specified in the protocol.
For a full 2 × 2 analysis with OR, RR, ARD, NNT, and Haldane-Anscombe corrections, see the odds ratio calculator and relative risk calculator. For Pearson's chi-square with Cramér's V, Yates' correction, and r × c contingency tables, see the chi-square calculator. For one-sample binomial probabilities and exact tests on a single proportion, see the binomial probability calculator. For confidence intervals on the difference of two proportions (Newcombe, log-Wald, Wilson), see the confidence interval calculator. And to plan sample size for a 2 × 2 trial given a target OR and α, see the sample size calculator.
Reviewed by
Dr. Sarah Mitchell holds a PhD in Biostatistics from Johns Hopkins Bloomberg School of Public Health and has over 15 years of experience in systematic review methodology and meta-analysis. She has authored or co-authored 40+ peer-reviewed publications in journals including the Journal of Clinical Epidemiology, BMC Medical Research Methodology, and Research Synthesis Methods. A former Cochrane Review Group statistician and current editorial board member of Systematic Reviews, Dr. Mitchell has supervised 200+ evidence synthesis projects across clinical medicine, public health, and social sciences. She reviews all Research Gold tools to ensure statistical accuracy and compliance with Cochrane Handbook and PRISMA 2020 standards.
From data cleaning and assumption checks to the full analysis and a publication-ready results section, we handle the numbers so you can focus on the science.
Our promise: Free re-run and re-write if reviewers question the analysis or reporting.
Your project is led by a named PhD methodologist with real credentials and published work.
4.9 / 5 across 1,194+ delivered projects