What Is A Fisher's Exact Test

12 min read

Fisher's exact test is a statistical significance test used to analyze contingency tables, specifically designed for small sample sizes where the assumptions of the chi-squared test are violated. On top of that, unlike approximate tests that rely on large-sample distribution theory, this method calculates the exact probability of obtaining the observed data distribution, or one more extreme, assuming the null hypothesis of independence is true. It remains the gold standard for analyzing 2x2 tables when expected cell counts fall below five, offering researchers a precise p-value without relying on asymptotic approximations Took long enough..

Understanding the Core Concept

At its heart, Fisher's exact test evaluates the association between two categorical variables. So naturally, imagine a medical study comparing a new drug against a placebo, with outcomes categorized as "Recovered" or "Not Recovered. " The data forms a 2x2 contingency table. The null hypothesis posits that the treatment and outcome are independent—meaning the drug has no effect.

You'll probably want to bookmark this section.

The test derives its name from Sir Ronald Fisher, who introduced it in the mid-1930s. The legend goes that Fisher devised the test to analyze a claim by a colleague, Muriel Bristol, who asserted she could taste whether milk or tea was poured first into a cup. Fisher designed the experiment and the exact statistical method to evaluate her claim rigorously.

The mathematical engine driving the test is the hypergeometric distribution. This distribution models the probability of drawing a specific number of "successes" (e.g.Day to day, , recovered patients in the treatment group) from a finite population without replacement, given fixed marginal totals. And "Fixed marginal totals" is a critical concept: the test conditions on the row and column totals observed in the data, treating them as fixed constants. It then asks: *Given these specific totals, how likely is this specific arrangement of data?

When to Use Fisher's Exact Test vs. Chi-Squared

Choosing between Fisher's exact test and the Pearson chi-squared test is a common decision point in data analysis. The chi-squared test relies on an approximation to the chi-squared distribution, which becomes accurate only when expected cell frequencies are sufficiently large. A standard rule of thumb suggests that no more than 20% of cells should have expected counts less than 5, and no cell should have an expected count less than 1 Simple, but easy to overlook..

If your dataset violates these conditions—common in pilot studies, rare disease research, or stratified analyses with small strata—Fisher's exact test is the appropriate choice. It maintains the correct Type I error rate (false positive rate) regardless of sample size.

Even so, Fisher's test is not exclusively for tiny datasets. With modern computing power, it is perfectly valid and often preferred for larger tables as well, provided computational resources allow. Historically, the test was computationally intensive for tables larger than 2x2 or for large sample sizes because it requires summing probabilities for all tables as extreme or more extreme than the observed one. Today, algorithms like the Mehta-Patel network algorithm make exact inference feasible for much larger tables (e.g., r x c tables) and moderate sample sizes (up to hundreds or thousands of observations).

The Mechanics: How the P-Value is Calculated

To understand the output, one must grasp the calculation logic. Consider a standard 2x2 table:

Success Failure Row Total
Group A a b R1
Group B c d R2
Col Total C1 C2 N

The probability of observing this specific table under the null hypothesis is given by the hypergeometric formula:

$ P = \frac{\binom{R1}{a} \binom{R2}{c}}{\binom{N}{C1}} = \frac{R1! Practically speaking, b! c! Because of that, r2! And c2! a! }{N! C1! d!

The p-value is the sum of probabilities for the observed table and all other possible tables with the same marginal totals that are "as extreme or more extreme" than the observed data.

One-Tailed vs. Two-Tailed Testing

This distinction is vital for interpretation.

  • One-Tailed Test: Used when the research hypothesis predicts a specific direction of association (e.g., "Treatment increases recovery rate"). The p-value sums probabilities of tables showing an association in that specific direction only.
  • Two-Tailed Test: Used when the hypothesis is non-directional (e.g., "Treatment affects recovery rate," either increase or decrease). Calculating a two-tailed p-value for Fisher's test is nuanced. There are two common methods:
    1. Doubling the one-tailed p-value: Simple but can be conservative, especially with asymmetric distributions.
    2. Summing probabilities less than or equal to the observed table's probability: This is the standard method (often called the "central" method or the method of summing small p-values). It identifies all tables with a probability less than or equal to the observed table's probability and sums them. This approach respects the discrete nature of the data better than simple doubling.

Most statistical software (R, SAS, SPSS, Stata) defaults to the second method for two-tailed tests. Always check your software documentation to know which method is being reported Most people skip this — try not to. Nothing fancy..

Assumptions and Limitations

While solid, Fisher's exact test rests on specific assumptions:

  1. Fixed Margins (Conditionality): The test assumes the row and column totals are fixed by design. This is true in randomized controlled trials where group sizes (row totals) are fixed by the researcher, but rarely true for column totals (outcome counts). In observational studies, neither margin is fixed. Critics argue that conditioning on both margins (as Fisher's test does) can be overly conservative for observational data, potentially reducing statistical power.
  2. Independence of Observations: Each observation must be independent. The test is invalid for matched-pair data (e.g., before/after measurements on the same subjects) or clustered data. For paired binary data, McNemar's test is the correct alternative.
  3. Categorical Data: Variables must be nominal or ordinal. It is not designed for continuous variables.
  4. Computational Intensity: For very large tables (e.g., 10x10) with huge sample sizes (N > 10,000), exact calculation can be prohibitively slow or memory-intensive. In these cases, Monte Carlo simulation (estimating the p-value by randomly sampling millions of tables) or the chi-squared test with Yates' continuity correction are practical alternatives.

Effect Size: Beyond the P-Value

A significant p-value tells you an association exists, but not its strength. With large samples, even trivial associations become statistically significant. That's why, reporting an effect size is essential.

For 2x2 tables, the Odds Ratio (OR) is the standard effect size metric accompanying Fisher's exact test Easy to understand, harder to ignore..

$ OR = \frac{a \times d}{b \times c} $

  • OR = 1: No association.
  • OR > 1: Higher odds of success in Group A.
  • OR < 1: Lower odds of success in Group A.

Because the sampling distribution of the OR is skewed, confidence intervals (CI) are typically calculated on the log scale and exponentiated. g.The exact conditional confidence interval for the odds ratio (based on the non-central hypergeometric distribution) pairs naturally with Fisher's exact test. This interval is guaranteed to have at least the nominal coverage probability (e., 95%), unlike the Wald interval which can perform poorly with small samples And that's really what it comes down to. Worth knowing..

Risk Difference (RD) and Relative Risk (RR) are alternative effect sizes, though exact CIs for these are less commonly implemented in standard software packages compared to the OR.

Practical Implementation in Statistical Software

R

The base stats package provides `fisher

…fisher.test() function, which computes the exact p‑value for a 2 × 2 contingency table (and, with the workspace argument, for larger tables up to the limits of memory). A minimal call looks like:

# Example data: a 2×2 table
#               Success  Failure
# Treatment      a        b
# Control        c        d
dat <- matrix(c(a, b, c, d), nrow = 2,
              dimnames = list(Group = c("Treatment","Control"),
                              Outcome = c("Success","Failure")))

# Two‑sided exact test
fisher.test(dat)

# One‑sided test (alternative = "greater" or "less")
fisher.test(dat, alternative = "greater")

The returned object contains:

  • p.value – the exact (conditional) probability of observing a table as extreme or more extreme than the one supplied.
  • estimate – the maximum‑likelihood odds ratio (conditional on the fixed margins).
  • conf.int – the exact confidence interval for the odds ratio, based on the non‑central hypergeometric distribution; the confidence level can be changed via conf.level.
  • null.value – the hypothesized odds ratio under the null (usually 1).

For tables larger than 2 × 2, fisher.test() still works, but the computational burden grows quickly. When the workspace required exceeds the default limit, increase it:

fisher.test(big_table, workspace = 2e5)   # workspace in bytes

If the exact calculation remains infeasible, the function can fall back to a Monte‑Carlo approximation:

fisher.test(big_table, simulate.p.value = TRUE,
            B = 2e5)   # number of simulated tables

The Monte‑Carlo p‑value is accompanied by a standard error (sqrt(p*(1-p)/B)) that helps gauge its precision That's the part that actually makes a difference. Still holds up..


Python (SciPy & statsmodels)

In Python, SciPy offers fisher_exact for 2 × 2 tables:

import numpy as np
from scipy.stats import fisher_exact

# table = [[a, b], [c, d]]
oddsratio, p_value = fisher_exact(table, alternative='two-sided')
print(f"Odds ratio = {oddsratio:.3f}, p = {p_value:.4g}")

For exact confidence intervals, statsmodels provides:

import statsmodels.stats.contingency_tables as ct
tbl = ct.Table2x2(table)
ci = tbl.oddsratio_confint()   # default 95% CI
print(ci)

When dealing with larger tables, the fisher_exact function in SciPy does not support Monte‑Carlo simulation directly; one can implement a custom sampler or rely on the R interface via rpy2.


SAS

SAS /STAT includes Fisher’s exact test in PROC FREQ:

proc freq data=mydata;
   tables Group*Outcome / fisher;
   exact fisher;   /* requests exact p‑value */
run;

The EXACT statement also yields exact confidence intervals for the odds ratio (OR) and risk difference (RD) when the CLODDS or CLRISK options are added.


Stata

Stata’s tabulate command with the exact option performs Fisher’s test:

tabulate group outcome, exact

For confidence intervals, use cci (for case‑control data) or ir/rr (for cohort data) with the exact qualifier That alone is useful..


Reporting Recommendations

  1. State the test used – e.g., “Fisher’s exact test (two‑sided) was applied to the 2 × 2 table.”
  2. Report the p‑value – with appropriate precision (typically three decimal places; for very small values, use scientific notation).
  3. Present an effect size – the odds ratio with its exact confidence interval is the default; if the study design favors risk differences or relative risks, note that exact intervals for those are less widely available and may require specialized software or bootstrapping.
  4. Mention any computational approximations – if a Monte‑Carlo p‑value was employed, report the number of replicates (B) and the resulting standard error.
  5. Check assumptions – verify independence of observations and discuss whether fixed margins are plausible; if not, consider alternatives (e.g., Barnard’s test, Boschloo’s test, or a chi‑square test with continuity correction).

Conclusion

Fisher’s exact test remains a cornerstone for analyzing small or sparse contingency tables because it provides an exact conditional p‑value that does not rely on large‑sample approximations. Its validity hinges on the assumptions of fixed margins and independent observations; when these are untenable, especially in

When the fixed‑margin assumption is questionable — for example, when the sample sizes for rows or columns are not truly predetermined — researchers can turn to exact alternatives that condition on a different set of margins. In larger or unbalanced designs, exact methods become prohibitive; in those cases a Monte‑Carlo approximation (e.On the flip side, barnard’s exact test, which enumerates all possible tables with the same row totals but allows column totals to vary, often yields a more powerful p‑value than the classic Fisher approach, though its computational cost grows rapidly with table size. g.Boschloo’s exact test provides a family‑wise adjustment for the size of the table, making it useful when many 2 × 2 strata are examined simultaneously. , drawing from the hypergeometric distribution) can be employed, and the resulting p‑value should be reported together with the number of simulated tables to convey its precision Turns out it matters..

This changes depending on context. Keep that in mind.

Software implementations differ in the exact statistics they supply. In real terms, stats. contingency_tables.On top of that, fisher_exact, which internally uses a Monte‑Carlo approach when the table is too large for exhaustive enumeration. In R, the exact2×2function from theexact2×2package delivers both Fisher and Barnard p‑values, while themidpargument enables a mid‑p correction that can improve approximate chi‑square performance without sacrificing the exact nature of the test. That's why python’sstatsmodelslibrary now includes an exact conditional test for 2 × 2 tables viastatsmodels. SAS and Stata continue to provide the classic Fisher exact test, and both now support the EXACT or exact qualifiers that automatically produce confidence intervals for the odds ratio, risk difference, or relative risk, depending on the analyst’s choice of effect measure.

In practice, the choice of test should be guided by three considerations: the size and sparsity of the data, the plausibility of fixed margins, and the interpretability of the effect metric. On the flip side, for small, tightly stratified tables, Fisher’s exact test (or its Barnard variant) is the most defensible option. When the table is larger or when confidence in the odds ratio is very important, reporting the exact confidence interval — available directly in statsmodels, SAS, or Stata — adds transparency. Finally, any approximation (Monte‑Carlo, mid‑p, or chi‑square) must be documented, including the number of simulations or the continuity correction applied, so that readers can assess the reliability of the inference.

Conclusion
Fisher’s exact test remains the gold standard for 2 × 2 tables with modest sample sizes, provided the fixed‑margin and independence assumptions hold. When those assumptions are doubtful, exact alternatives such as Barnard’s or Boschloo’s tests, or carefully documented Monte‑Carlo approximations, can preserve the exactness of inference while accommodating more realistic study designs. Reporting the p‑value with appropriate precision, accompanied by an exact confidence interval for the chosen effect size, ensures that the analysis is both statistically rigorous and scientifically transparent Most people skip this — try not to..

Dropping Now

What's Just Gone Live

Round It Out

Others Found Helpful

Thank you for reading about What Is A Fisher's Exact Test. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home