Written and maintained by CASRAI Editorial Board
Last updated
Short answer: Fisher’s exact test (often searched as “Fisher testing” or “Fisher test”) checks whether two categorical variables are associated in a contingency table, using the exact hypergeometric distribution instead of the large-sample chi-square approximation. It is the usual choice when counts are small. The same table can return different two-sided p-values and different odds ratios depending on the convention your software uses, so report which one you used. It has nothing to do with Thermo Fisher Scientific, which is a company name.
Definition and scope
SciPy’s documentation describes the function as performing “a Fisher exact test on a contingency table.” R’s manual states the null hypothesis as “independence of rows and columns in a contingency table with fixed marginals.” Fixed marginals means the row totals and column totals are treated as given, and only the way the observations are split inside the table is considered random.
For a 2×2 table with cells a, b, c and d, SciPy gives the null distribution as hypergeometric with M = a+b+c+d, n = a+b and N = a+c. R’s manual says that, with all marginal totals fixed, the first element of the table has a non-central hypergeometric distribution. The test applies to counts of observations in categories, not to measurements on a continuous scale. For the large-sample counterpart, see the CASRAI guide to the chi-square test.
How the p-value is built
SciPy defines the p-value as “the probability under the null hypothesis of obtaining a table at least as extreme as the one that was actually observed.” Because every possible table with the same margins has an exactly computable probability, no large-sample approximation is involved. For readers new to the quantity itself, see what a p-value is.
For a 2×2 table the “extreme” direction is tied to the odds ratio. SciPy’s alternative argument accepts ‘two-sided’ (the population odds ratio is not one), ‘less’ (odds ratio below one) and ‘greater’ (odds ratio above one). R states that its one-sided alternative is likewise based on the odds ratio. In SciPy this argument is used for 2×2 tables only.
What a “Fisher test table” or calculator needs
A Fisher’s exact test calculator, whether a web page or a function in statistical software, needs the four observed cell counts of a 2×2 table: two groups in the rows, two outcomes in the columns. The row and column totals follow from those counts, which is why only four numbers are entered. Enter raw counts, not percentages. If your software also offers a one-sided option, decide which direction you are testing before you look at the result.
Fisher’s exact test versus chi-square when counts are small
StatsDirect’s help page, a software vendor’s documentation, says the exact test should be used instead of the chi-square test when any expected frequency is less than 1, or when 20% of expected frequencies are less than or equal to 5. Other guides state the small-count cut-off differently, for example any expected count below 5. Treat these as rules of thumb that differ between sources, and name the rule you applied. The CASRAI guide to choosing a statistical test places this choice in a wider decision tree.
Why two packages can disagree on the same table
This is the point most tutorials skip. Three details change what you see.
Two-sided p-value convention
StatsDirect lists the conventions: the two-sided P (after Bailey, 1977) sums the probabilities of all tables whose probability is less than or equal to that of the observed table; some authors instead double the one-sided P; and the mid-P variant counts only half the probability of the observed table in its tail.
Odds ratio estimate
SciPy returns the sample (unconditional) maximum likelihood estimate of the odds ratio, while R’s fisher.test reports the conditional maximum likelihood estimate. SciPy documents that the conditional one is available through scipy.stats.contingency.odds_ratio. The two estimates for one table are not the same number.
A worked example
These values come from SciPy’s fisher_exact applied to the 2×2 tables shown. For the table [[6, 2], [1, 4]], the sample odds ratio is 12.0, the two-sided p-value is 0.10256 and the one-sided (‘greater’) p-value is 0.08625. The same data therefore sits on either side of 0.10 depending only on the alternative chosen. For [[8, 2], [1, 5]], the sample odds ratio is 20.0 and the two-sided p-value is 0.034965.
| Table | Sample odds ratio | Two-sided p | One-sided (‘greater’) p |
|---|---|---|---|
| [[6, 2], [1, 4]] | 12.0 | 0.10256 | 0.08625 |
| [[8, 2], [1, 5]] | 20.0 | 0.034965 | 0.024476 |
For the confidence interval around an odds ratio, see confidence intervals for an odds ratio. R reports one only for the 2×2 case.
Beyond 2×2 tables
Both SciPy and R extend the test to larger tables, but with different mechanics. SciPy, for other table sizes, uses a fixed-marginals independence null and takes the probability mass of the observed table as the statistic; its alternative option is ignored. R notes that for r×c tables the internal tables can be too large for the exact test, in which case an error is signalled. Its options are to enlarge the workspace for the network algorithm (larger problems can need hours) or to set simulate.p.value, a Monte Carlo approximation conditional on the row and column totals.
Common misunderstandings
- “It is only for 2×2 tables.” It is defined for r×c tables; the odds ratio, its confidence interval and the one-sided alternatives are 2×2 features.
- “Exact means assumption-free.” It conditions on fixed margins. StatsDirect describes that fixed-totals assumption as controversial.
- “Every package returns the same odds ratio.” Unconditional and conditional estimates differ, as above.
- “The two-sided p is just double the one-sided p.” That is one convention among several.
FAQ
What is Fisher’s exact test used for?
Testing independence of two categorical variables in a contingency table with fixed margins, most often a 2×2 table of small counts.
When should I use it instead of chi-square?
When expected counts are small. One software vendor’s rule is any expected frequency below 1, or 20% of expected frequencies at or below 5; other sources use other thresholds.
How do I calculate Fisher’s exact test?
Enter the four cell counts into statistical software or a calculator. Examples in code are in the CASRAI guides for SciPy and R crosstabs.
Is “Fisher t test” the same thing?
No. A t-test compares means of a continuous variable; Fisher’s exact test works on counts in categories.
Sources
- SciPy documentation, scipy.stats.fisher_exact, checked 2026-10-29.
- R manual, fisher.test, checked 2026-10-29.
- StatsDirect help, Fisher’s exact test (software vendor documentation), checked 2026-10-29.








