Fisher's Exact Test, Explained
After reading this you can run Fisher's exact test on any 2×2 table by hand or with the calculator, read the p-value and odds ratio correctly, and know when to reach for it instead of chi-square.
What the test does
Fisher's exact test answers one question about a 2×2 table: are the two rows and the two columns associated, or could the pattern you see arise by chance alone? It is called "exact" because it computes the probability of your table directly from the hypergeometric distribution rather than approximating with a continuous curve.
Here is the hook. Suppose you treat 10 patients with a new drug and 6 with a placebo, and count how many recover.
| Recovered | Did not recover | Row total | |
|---|---|---|---|
| Drug | 8 | 2 | 10 |
| Placebo | 1 | 5 | 6 |
| Column total | 9 | 7 | 16 |
With only 16 people, a chi-square test rests on shaky ground. Fisher's test gives you an exact p-value: 0.0110 two-sided. The recovery rates (80% versus about 17%) differ by more than chance would comfortably produce.
When to use it, and when not
Use Fisher's exact test when you have a 2×2 table of counts and any expected cell count is small. A common rule: if the chi-square test would put an expected count below 5 in any cell, prefer Fisher. For the table above the smallest expected count is 6 \times 7 / 16 = 2.625, well under 5, so Fisher is the right call.
The test assumes each observation falls into exactly one cell and that the two classifications (row and column) are independent draws. The classic derivation treats both margins as fixed. In practice people apply it to studies where only one margin is fixed by design, and the p-value stays valid, if slightly conservative.
Do not use Fisher's exact test on paired or matched data, such as the same subjects measured before and after. That structure needs McNemar's test. Fisher assumes the two groups are independent.
For large samples with all expected counts comfortably above 5, the chi-square test of independence gives almost the same answer with less computation. When you are comparing two proportions and want a confidence interval on their difference, the A/B test calculator is the more direct tool.
The formula and the intuition
Label the four cells a, b, c, d:
Hold all four margins fixed: the row totals a+b and c+d, and the column totals a+c and b+d, with grand total n = a+b+c+d. Under independence, the probability of any particular arrangement of counts follows the hypergeometric distribution:
Each \binom{n}{k} is a binomial coefficient, the number of ways to choose k items from n. The numerator counts the ways to split each row into the observed columns; the denominator counts all ways to place the column-1 successes among the n subjects. Because the margins are fixed, the value of a alone determines the whole table, so the distribution has exactly one free coordinate.
The p-value sums the probability of your observed table plus every table (with the same margins) that is at least as extreme. For a two-sided test the usual convention sums all tables whose probability is less than or equal to the observed table's probability.
Worked example with the demo data
Reproducing the recovery table
The calculator's demo uses a = 8, b = 2, c = 1, d = 5. Margins: rows 10 and 6, columns 9 and 7, total 16.
- Compute the probability of the observed table.
P_{\text{obs}} = \dfrac{\binom{10}{8}\binom{6}{1}}{\binom{16}{9}} = \dfrac{45 \times 6}{11440} = 0.02360
- List all tables sharing these margins. With row 1 total 10 and column 1 total 9, the cell
acan range from 3 (so that c = 9 - a stays at most 6) up to 9. That gives seven possible tables, one for each value a \in \{3,4,5,6,7,8,9\}. - Compute each table's hypergeometric probability. The values are:
\begin{array}{ccccccc} a{=}3 & 4 & 5 & 6 & 7 & 8 & 9 \\ 0.0189 & 0.1272 & 0.3055 & 0.3208 & 0.1527 & 0.0236 & 0.0011 \end{array}
- For the two-sided p-value, add up every table whose probability is \le P_{\text{obs}} = 0.02360. Those are a{=}3 (0.0189), a{=}8 (0.0236) and a{=}9 (0.0011).
p = 0.0189 + 0.0236 + 0.0011 = 0.0436
Reported values from the calculator: two-sided p = 0.0436, one-sided p = 0.0247 (the tail from a{=}8 and a{=}9), and odds ratio 20.0. The seven probabilities sum to 1.000, a good arithmetic check.
a under independence. Bars at or below the observed height (a = 3, 8, 9) make up the two-sided p-value of 0.0436.The odds ratio
Alongside the p-value the test reports the odds ratio, which measures the strength of the association rather than just its significance. The sample odds ratio is:
Read it as: the odds of recovery are 20 times higher in the drug group than in the placebo group. An odds ratio of 1 means no association. Values above 1 mean the outcome in column 1 is more likely for row 1; values below 1 mean the reverse.
When any cell is 0 the plain odds ratio is 0 or infinite. Most software then reports a conditional maximum likelihood odds ratio, which can differ slightly from ad/bc. The p-value is unaffected by this choice.
Explore how one cell moves the p-value
Reading and interpreting the result
Compare the p-value to your chosen significance level, usually 0.05. The demo's two-sided p = 0.0436 is below 0.05, so you reject the hypothesis of no association: recovery and treatment are linked in this sample.
Choose one-sided only if you set a directional hypothesis before seeing the data, for example "the drug cannot do worse than placebo." Choosing the tail after looking at the numbers roughly halves your p-value dishonestly. When in doubt, report the two-sided value.
Significance is not size. A p-value of 0.0436 says the association is unlikely to be chance; the odds ratio of 20 says the effect is large. Report both. With only 16 subjects, the confidence interval around that odds ratio is wide, so treat the point estimate as rough.
Common mistakes
- Applying it to bigger-than-2×2 tables
- The formula above is for 2×2. Larger tables need the Freeman-Halton extension or a chi-square test; the calculator here handles the 2×2 case only.
- Confusing counts with percentages
- Enter raw counts, never rates. A table of 80% and 17% carries no information about sample size, and sample size drives the p-value.
- Double-counting a chosen direction
- Do not run a two-sided test, notice the direction, then re-report the one-sided half. Decide the direction first.
- Ignoring paired structure
- If the same units generate both columns, the observations are not independent and Fisher does not apply.
Related tools
For larger samples, the chi-square test of independence is the standard partner to this test, and the p-value calculator converts a chi-square statistic to a p-value. Comparing two proportions with a confidence interval is the job of the one-proportion z-test for one group or the A/B test calculator for two. When your outcome is continuous rather than a count, look at the t-test calculator, the Mann-Whitney U test for a nonparametric comparison, or one-way ANOVA for three or more groups.
Frequently asked questions
Is Fisher's exact test always better than chi-square?
Not always. For small counts it is more accurate because it makes no continuous approximation. For large tables with all expected counts above 5, chi-square gives nearly the same p-value and computes faster. On the demo data chi-square without correction gives about 0.011, Fisher gives 0.0436; the exact test is the trustworthy one here.
Why does the p-value jump instead of changing smoothly?
Because the counts are discrete. With margins 10, 6, 9, 7 there are only seven possible tables, so the p-value can take only a handful of values. That is why the chart shows bars, not a continuous curve.
What does an odds ratio of 20 mean in plain words?
The odds of recovery in the drug group are 20 times the odds in the placebo group. Odds of 8 to 2 is 4; odds of 1 to 5 is 0.2; and 4 divided by 0.2 is 20.
Can I run the test with a zero in one cell?
Yes. The hypergeometric formula handles zeros fine, and the p-value is still exact. Only the plain odds ratio breaks (it becomes 0 or infinite), so the calculator reports a conditional estimate instead.
One-sided or two-sided, which should I report?
Report two-sided unless you fixed a direction before collecting data. Two-sided is the safer default and is what most journals expect.