Fisher's Exact Test Calculator

Fisher's Exact Test Calculator

Test a 2 × 2 table exactly, without the large-sample approximation of chi-square: two-sided and one-sided p-values, plus the odds ratio.

P(table) = C(a + b, a) × C(c + d, c) ÷ C(n, a + c)

Enter the four counts of the 2 × 2 table
Outcome yesOutcome no
Group 1
Group 2

Enter counts, not percentages. Rows are the two groups, columns the two outcomes.

Fill in all four cells of the table

What is Fisher's Exact Test?

Fisher's exact test checks whether two groups differ in the share with some outcome, using the exact probability of every possible table rather than an approximation. That makes it the right test for small samples.

It treats the row and column totals as fixed and asks: if group made no difference, how likely would a table this lopsided, or more so, be? Those probabilities come straight from the hypergeometric distribution.

It's widely used in medicine and biology, where small trials and rare outcomes leave expected counts too low for a chi-square test.

Fisher's Exact Test Formula

As introduced by Fisher (1935); the two-sided p sums every table no more likely than the observed one, as in R's fisher.test. See Sources.

1. Probability of one table

P = (a + b)! (c + d)! (a + c)! (b + d)! ÷ (n! a! b! c! d!)

2. List every table with the same totals

Vary a from max(0, (a + c) − (c + d)) to min(a + b, a + c)

3. Add up the extreme ones

Two-sided p = Σ P(table) over tables with P ≤ P(observed)
Odds ratio = (a × d) ÷ (b × c)

Worked Example: The Lady Tasting Tea

Given:
Fisher's famous experiment: a colleague claimed she could tell whether milk was poured first. Of 4 milk-first cups she named 3 correctly; of 4 tea-first cups, 3. Table: 3, 1 / 1, 3.
Step 1:
Ways to pick 4 cups as "milk first":
C(8, 4) = 70
Step 2:
Ways to get 3 right:
C(4, 3) × C(4, 1) = 16 → P = 16/70 = 0.229
Step 3:
Tables as or less likely, in both directions:
(1 + 16 + 16 + 1) ÷ 70 = 34/70 = 0.486
Result:
Two-sided p = 0.486

Six out of eight sounds impressive, but guessing does that or better almost half the time. Only a perfect 8 out of 8 (p = 1/70 = 0.014 one-sided) would have been convincing.

Every Possible Result of the Tea Experiment

With 4 milk-first cups among 8, if she were only guessing.

Probability of each number of correctly identified milk-first cups
Milk-first cups foundWaysChance
0 of 41 / 700.0143
1 of 416 / 700.2286
2 of 436 / 700.5143
3 of 416 / 700.2286
4 of 41 / 700.0143

Common Fisher's Exact Test Mistakes

  • Doubling the one-sided p. The two-sided p is the sum of all tables as or less likely, which isn't always twice the one-sided value.
  • Using chi-square on tiny counts. With expected counts below 5, chi-square can be badly off; Fisher's test is exact.
  • Entering percentages. The test needs the actual counts.
  • Using it for paired data. Before/after on the same people needs McNemar's test, not Fisher's.

Fisher's Exact Test FAQs

When should I use Fisher’s exact test?

For 2 × 2 tables with small counts, especially when any expected count is below 5. It’s valid for large tables too, just slower.

Why is it called exact?

It calculates the p-value directly from the hypergeometric probabilities, with no large-sample approximation.

What does the odds ratio tell me?

How much higher group 1’s odds of “yes” are than group 2’s. 1 means no difference; 9 in the tea example means much higher odds.

Why is the odds ratio infinite sometimes?

When b or c is zero, the formula divides by zero. That happens with perfect separation and is shown as ∞.

Is Fisher’s test conservative?

Slightly. Because counts are whole numbers, the real false-positive rate is often a little below α.

Who was the lady tasting tea?

Muriel Bristol, a colleague of Fisher at Rothamsted. He described the experiment in his 1935 book The Design of Experiments.

Does it matter which way round the table is?

No for the two-sided p-value. It does matter for which one-sided p and which odds ratio you report.

How do I run it in R?

fisher.test(matrix(c(3, 1, 1, 3), nrow = 2)) gives the same two-sided p-value, 0.4857.

Sources

  • R. A. Fisher, The Design of Experiments (Oliver and Boyd, 1935), chapter 2: the lady tasting tea.
  • A. Agresti, Categorical Data Analysis, 3rd edition (Wiley, 2013), section 3.5: small-sample tests.

Related Tools