Skip to content

Fisher's Exact Test Calculator - Free Statistical Tool

Calculate exact p-values for 2×2 contingency tables with Fisher's exact test. Perfect for small sample sizes when chi-square assumptions fail. Free online tool.

Loading calculator...
📚

Documentation

What Is Fisher's Exact Test?

Fisher's exact test is a statistical method that checks whether two categorical variables are related, using data arranged in a 2×2 table. It calculates an exact probability, called a p-value, instead of an approximation. This makes it useful when a sample is small.

The test compares counts in two rows and two columns, such as "treated" versus "untreated" patients who did or did not recover. A 2×2 table has four cells, usually labeled A, B, C, and D, plus row and column totals.

Fisher's Exact Test vs. Chi-Square Test

The chi-square test also checks for a relationship between two categorical variables, but it relies on an approximation that works well only when cell counts are large enough. A common rule of thumb: if any expected cell count in the table is below 5, the chi-square approximation becomes unreliable, and Fisher's exact test is the better choice. Fisher's exact test works at any sample size, but it is mathematically exact rather than approximate, which is its main advantage for small samples.

AspectFisher's Exact TestChi-Square Test
ResultExact probabilityApproximation
Best forSmall samples, low cell countsLarger samples with all expected counts ≥ 5
Table sizeBuilt for 2×2 tables (extensions exist for larger tables)Any table size
SpeedCan be slower for large samplesFast at any sample size

How to Calculate Fisher's Exact Test

The test uses the hypergeometric distribution, which describes the probability of drawing a certain number of items from a group without putting them back. Given the row and column totals of a table, the hypergeometric distribution gives the probability of any specific arrangement of the four cell counts.

The probability formula

For a table with cells A, B, C, D, row totals r₁ = A + B and r₂ = C + D, column totals c₁ = A + C and c₂ = B + D, and total sample size n = A + B + C + D, the probability of that exact table is:

P=r1!r2!c1!c2!A!B!C!D!n!P = \frac{r_1!\, r_2!\, c_1!\, c_2!}{A!\, B!\, C!\, D!\, n!}

Here "!" means factorial: 5! = 5 × 4 × 3 × 2 × 1.

One-tailed p-value

A one-tailed p-value adds up the probability of the observed table plus every other table with the same row and column totals that shows an equal or stronger relationship in the same direction. "Direction" is decided by comparing cell A to the value it would have if the two variables were unrelated, called its expected value: E(A) = r₁c₁ / n.

  • If A is equal to or greater than E(A), the association leans positive, and the sum runs over every possible value of cell A from the observed value up to its highest possible value.
  • If A is less than E(A), the association leans negative, and the sum runs from the lowest possible value of cell A up to the observed value.

Two-tailed p-value

A two-tailed p-value adds up the probabilities of every possible table with the same row and column totals whose probability is equal to or smaller than the observed table's probability. This counts extreme results in both directions, so a two-tailed p-value is normally larger than a one-tailed p-value calculated from the same table.

Worked Example

A small trial gives a new drug to 10 patients and a placebo to 10 others. The results:

ImprovedDid not improveTotal
Treated8210
Control3710
Total11920

Here A = 8, B = 2, C = 3, D = 7, and n = 20. The expected value of A under independence is E(A) = (10 × 11) / 20 = 5.5. Since 8 is above 5.5, the association leans positive, so the one-tailed sum runs from A = 8 up to the highest possible value of A, which is 10.

Working through the hypergeometric probabilities for A = 8, 9, and 10 gives a one-tailed p-value of about 0.0349. Adding the probabilities of every table (in both directions) with a probability at or below the observed table's probability gives a two-tailed p-value of about 0.0698.

At the common 0.05 threshold, the one-tailed result counts as statistically significant, while the two-tailed result does not. This shows why choosing the test type matters: a one-tailed test is only appropriate when the direction of the effect (here, that the drug improves outcomes) was predicted before looking at the data.

When to Use Fisher's Exact Test

Fisher's exact test is common in:

  • Clinical trials with a small number of patients.
  • Quality-control checks comparing defect counts between two production batches.
  • Genetics research comparing counts of a trait between two small groups.
  • Any 2×2 table where an expected cell count is below 5.

Frequently Asked Questions

What is Fisher's exact test used for? It tests whether two categorical variables are related, using counts from a 2×2 table. It is often chosen over the chi-square test when a sample is small.

When should Fisher's exact test be used instead of chi-square? When any expected cell count in the table is below 5, or when extra certainty about the exact probability is needed regardless of sample size.

What is the difference between one-tailed and two-tailed results? A one-tailed p-value tests a predicted direction of effect, decided before the data are seen. A two-tailed p-value tests whether any association exists, in either direction. A two-tailed p-value from the same table is usually larger.

Does this calculator report an odds ratio? No. It reports only the exact p-value. An odds ratio for the same table can be found separately by dividing A × D by B × C.

Can Fisher's exact test be used on tables larger than 2×2? The version described here is for 2×2 tables. Larger tables need a related method called the Freeman-Halton extension, available in most statistics software.

Can Fisher's exact test be used on paired data, like before-and-after measurements on the same people? No. It assumes two independent groups. Paired categorical data need McNemar's test instead.

References

  1. Fisher, R.A. (1922). "On the interpretation of χ² from contingency tables, and the calculation of P." Journal of the Royal Statistical Society, 85(1), 87–94.
  2. Freeman, G.H. & Halton, J.H. (1951). "Note on an exact treatment of contingency, goodness of fit and other problems of significance." Biometrika, 38(1/2), 141–149.
  3. Agresti, A. (2018). An Introduction to Categorical Data Analysis (3rd ed.). Wiley.