---
tag: YB9390ZE4W
kind: definition
name: Fisher's exact test
msc: [62H17, 62F03]
defines: J6JP5CJNPX
uses: [PANSMHE0SW, 0SPBPW3K61, 0EHYZFZ4PK, 087P03NEND]
sources:
  - url: https://en.wikipedia.org/wiki/Fisher%27s_exact_test
---

## Definition

Consider a $2 \times 2$ [[contingency table|PANSMHE0SW]] of counts $a, b$ in the first row and $c, d$ in the second row, with total $n = a + b + c + d$.
Fix the row totals $r_1 = a + b$, $r_2 = c + d$ and the column totals $k_1 = a + c$, $k_2 = b + d$.
Assume the null hypothesis that the row factor and the column factor are independent.
Then, conditionally on these totals, $a$ has the [[hypergeometric distribution|0SPBPW3K61]]
$$P(a) = \binom{r_1}{a} \binom{r_2}{k_1 - a} \Big/ \binom{n}{k_1}.$$
*Fisher's exact test* computes the [[p-value|0EHYZFZ4PK]] as a sum of $P(a')$ over tables with the same totals.
The sum runs over the tables at least as extreme as the observed one.
The one-sided version sums over $a' \ge a$; the usual two-sided version sums over all $a'$ with $P(a') \le P(a)$.

## Remarks

Example: in the lady tasting tea experiment, $r_1 = r_2 = k_1 = k_2 = 4$, $n = 8$, and she classifies all cups correctly, so $a = 4$.
Then $P(4) = \binom{4}{4}\binom{4}{0}/\binom{8}{4} = 1/70$, and the one-sided p-value is $1/70 \approx 0.014$.
Non-example: replacing the hypergeometric law by its chi-squared approximation gives Pearson's [[chi-squared test|0EN0V3NY20]], whose p-value is only approximate.
The test is conservative: since the conditional law is discrete, the probability of a type I error is at most $\alpha$ and often smaller.
