Historical Context & Motivation
In the early decades of the twentieth century, statisticians increasingly confronted the problem of analyzing categorical data arranged in contingency tables. The chi-squared test, introduced by Karl Pearson in 1900, provided an asymptotic framework for evaluating the independence of two categorical variables. However, the chi-squared approximation becomes unreliable when expected cell frequencies are small — a situation that arises routinely in clinical trials, genetics studies, and epidemiological investigations where sample sizes are limited. This shortcoming motivated the search for a method that would yield exact probabilities without relying on large-sample approximations.
The solution arrived through the work of Sir Ronald A. Fisher, one of the most influential statisticians of the twentieth century. Fisher devised an elegant test that computes the probability of obtaining any particular arrangement of cell counts in a 2×2 table, conditional on the fixed marginal totals. The famous illustration of this method involved a colleague, Dr. Muriel Bristol, who claimed she could distinguish whether milk or tea had been poured into the cup first — an anecdote that has become one of the most celebrated thought experiments in the history of statistics.
The central question Fisher addressed is deceptively simple: given the observed marginal totals of a 2×2 contingency table, how likely is it to observe the specific arrangement of cell counts — or one more extreme — if the row and column variables are truly statistically independent? By computing this probability exactly rather than relying on an asymptotic χ² distribution, Fisher's test provides valid inference even when cells contain very few observations, making it indispensable in modern biostatistical practice.
Core Principles & Definitions
Fisher's exact test rests upon a set of interlocking principles that distinguish it from approximate methods like the chi-squared test. Understanding these principles is essential before engaging with the mathematical machinery, because the test's validity hinges on the specific probabilistic model it invokes — namely, the hypergeometric distribution applied to the cell counts of a 2×2 contingency table with fixed marginal totals.
Conditioning on Margins
Exact Probability Calculation
Null Hypothesis of Independence
The Hypergeometric Model
One-Tailed vs. Two-Tailed
Visual Explanation
The following diagram illustrates the structure of a 2×2 contingency table and the relationship between the cell counts, marginal totals, and the grand total. Because the marginals are treated as fixed, only one cell value (here, cell a) is free to vary; the remaining three cells are determined by subtraction. The diagram also shows how the hypergeometric probability is constructed from the factorial terms associated with each margin and cell.
As the diagram makes clear, once the four marginal totals are fixed, specifying any single cell — say, cell a — automatically determines the other three by subtraction: b = (a + b) − a, c = (a + c) − a, and d = n − a − b − c. This means there is only one degree of freedom in the table, and the test evaluates all possible values of a under H₀ to compute the p-value.
Mathematical Framework
The mathematical foundation of Fisher's exact test is the hypergeometric probability of observing a particular cell count a given fixed marginal totals. We denote the row totals as R₁ = a + b and R₂ = c + d, the column totals as C₁ = a + c and C₂ = b + d, and the grand total as n. The probability of the observed table — or equivalently, the probability that cell a takes a particular value — is given by the following expression.
An equivalent formulation, often seen in textbooks, expresses the probability directly in terms of factorials of the margins and cells.
To compute the p-value, one sums the hypergeometric probabilities of all table configurations that are as extreme as or more extreme than the observed table. For a one-tailed test in the direction of a positive association, this means summing over all values of a from the observed value up to min(R₁, C₁). For a two-tailed test, one also includes tables in the opposite tail whose individual probabilities are less than or equal to the probability of the observed table.
Probability Landscape of All Possible Tables
To build intuition for how the p-value is computed, consider a concrete scenario. Suppose we observe a 2×2 table with marginals R₁ = 5, R₂ = 7, C₁ = 4, and C₂ = 8 (n = 12). The free cell a can range from max(0, 4 − 7) = 0 to min(5, 4) = 4, giving five possible table configurations. The diagram below plots the hypergeometric probability of each configuration and shows which tables are included in one-tailed and two-tailed p-value calculations when the observed value is a = 4.
The bar chart reveals that under independence, the most probable table configurations are a = 1 and a = 2, which together account for over 76% of the probability mass. The observed value a = 4 lies in the extreme right tail with a probability of only 0.008. The one-tailed p-value (testing whether a is unusually large) sums P(a ≥ 3) = 0.088 + 0.008 = 0.096. Since this exceeds the conventional α = 0.05 threshold, we would fail to reject H₀ at the 5% level in this example, though the result would be significant at α = 0.10.
Worked Example: Drug Efficacy Trial
Consider a small clinical trial in which 12 patients are randomized to either a new drug (n = 5) or placebo (n = 7). The primary outcome is binary: improvement (yes/no). Suppose 3 of the 5 drug patients and 1 of the 7 placebo patients improve. We wish to test whether the drug is associated with improvement using Fisher's exact test at the α = 0.05 significance level (one-tailed, since we are testing whether the drug improves outcomes).
| Improved | Not Improved | Total | |
|---|---|---|---|
| Drug | 3 (a) | 2 (b) | 5 |
| Placebo | 1 (c) | 6 (d) | 7 |
| Total | 4 | 8 | 12 |
fisher.test(), Python's scipy.stats.fisher_exact()) handles this automatically.Fisher's Exact Test vs. Chi-Squared Test
A natural question arises: when should one use Fisher's exact test rather than the more familiar Pearson's chi-squared test? The answer depends on sample size, expected cell counts, and the specific inferential context. The table below summarizes the key distinctions between these two approaches to testing independence in 2×2 contingency tables.
| Feature | Fisher's Exact Test | Chi-Squared Test |
|---|---|---|
| Probability model | Hypergeometric (exact) | χ² approximation (asymptotic) |
| Sample size requirement | None — valid for any sample size | All expected counts ≥ 5 (rule of thumb) |
| Computational cost | Higher for large n (combinatorial enumeration) | Low — single formula |
| Type I error control | Conservative (actual α ≤ nominal α) | Liberal when expected counts are small |
| Marginals | Conditions on fixed margins | Does not require fixed margins |
| Extensions | Generalizable to r×c tables (computationally expensive) | Naturally extends to r×c and multi-way tables |
| When to prefer | Small samples, sparse cells, regulatory submissions | Large samples, exploratory analysis |
Connections to Advanced Methods
Fisher's exact test for 2×2 tables is the simplest member of a broader family of exact conditional tests. Understanding its relationship to more advanced methods helps situate the test within the larger statistical ecosystem and prepares the student for extensions encountered in advanced biostatistics coursework.
| Feature | Fisher's Exact Test (2×2) | Advanced Extensions |
|---|---|---|
| Table dimension | 2×2 only | Fisher–Freeman–Halton test extends to r×c tables |
| Stratification | Single 2×2 table | Cochran–Mantel–Haenszel test pools evidence across K strata |
| Effect estimation | Provides p-value only (no direct effect estimate) | Exact logistic regression provides conditional maximum likelihood estimates and exact confidence intervals |
| Multiple testing | Single comparison | Permutation tests and exact methods in genomics handle thousands of simultaneous comparisons |
| Bayesian analog | Frequentist exact inference | Bayesian analysis of contingency tables with Dirichlet priors provides posterior probability of association |
A particularly important connection is to exact logistic regression, which can be understood as a multivariate generalization of Fisher's exact test. Where Fisher's test conditions on the marginals of a single 2×2 table, exact logistic regression conditions on the sufficient statistics of the logistic model to obtain exact conditional distributions for the regression coefficients. This method is invaluable when modeling binary outcomes with small samples and multiple predictors — a scenario where standard maximum likelihood logistic regression may fail to converge.
Additionally, the Barnard's test offers an unconditional alternative to Fisher's test. Rather than fixing both sets of margins, Barnard's test fixes only one margin and maximizes the p-value over nuisance parameters. Although Barnard's test can be more powerful than Fisher's in certain configurations, it is computationally more demanding and less widely implemented in standard software, which explains Fisher's test's continued dominance in practice.
Practice Problems
Summary & Review
Fisher's exact test is a non-parametric statistical test that evaluates the independence of two categorical variables in a 2×2 contingency table by computing exact probabilities under the hypergeometric distribution. Unlike the chi-squared test, which relies on large-sample approximations, Fisher's test is valid for any sample size and does not require a minimum expected cell count. The test conditions on the fixed marginal totals of the table, reducing the problem to a single free cell whose distribution under the null hypothesis is fully specified.
The p-value is computed by summing the probabilities of all tables as extreme as or more extreme than the observed table. The test may be conducted as one-tailed or two-tailed depending on the research hypothesis. Although Fisher's test is conservative due to the discreteness of the hypergeometric distribution, the mid-p correction can bring the actual Type I error rate closer to the nominal level. The test remains a cornerstone of biostatistical practice, indispensable in clinical trials, genetics, and epidemiology whenever sample sizes are small or data are sparse.