TSE.
MathematicsFinanceHealthPhysicsEngineeringBrowse all

Mathematics · Statistics · Hypothesis Testing

Fisher's Exact Test Calculator

Calculates the exact p-value for a 2×2 contingency table using Fisher's Exact Test to determine statistical significance of association between two categorical variables.

Calculator

Advertisement

Formula

In the 2×2 table with cells a (top-left), b (top-right), c (bottom-left), d (bottom-right): a = Group 1 successes, b = Group 1 failures, c = Group 2 successes, d = Group 2 failures, n = a + b + c + d (total observations). The formula computes the hypergeometric probability of observing exactly this table given fixed marginal totals. The two-tailed p-value sums probabilities of all tables at least as extreme as observed.

Source: Fisher, R.A. (1922). On the interpretation of chi-squared from contingency tables, and the calculation of P. Journal of the Royal Statistical Society, 85(1), 87–94.

How it works

Fisher's Exact Test evaluates whether two categorical variables in a 2×2 table are independent. The test was devised by Sir Ronald A. Fisher and operates on the hypergeometric distribution. Given fixed row and column marginal totals, it calculates the probability of observing the actual table configuration and all configurations more extreme. This is exact — no approximation is involved — which is why it remains the gold standard for small-sample categorical analysis.

The formula is: p = (a+b)!(c+d)!(a+c)!(b+d)! / (a! b! c! d! n!), where a, b, c, d are the four cell counts and n is the total. The one-tailed p-value is the sum of probabilities of tables with a value of cell 'a' at least as extreme in one direction; the two-tailed p-value sums probabilities of all tables (in both directions) that are at least as unlikely as the observed table. Most research reports the two-tailed p-value unless a directional hypothesis was pre-specified. The odds ratio (OR = ad/bc) quantifies the strength and direction of association — an OR of 1 indicates no association, greater than 1 indicates positive association, less than 1 indicates negative association.

Fisher's Exact Test is applied across a broad range of fields. In clinical trials, researchers test whether a new treatment significantly changes the rate of a binary outcome (e.g., recovered vs. not recovered). In genetics, it tests whether a specific genotype is over-represented in a disease group. In quality control, it assesses whether a defect rate differs between two production lines. Because it is exact rather than asymptotic, it is especially valued when n < 20 or when any expected cell count is below 5, conditions under which the chi-square test can produce unreliable p-values.

Worked example

Suppose a clinical study tests a new drug versus a placebo. The 2×2 table is:

Drug / Recovered: 12 | Drug / Not Recovered: 5 | Placebo / Recovered: 3 | Placebo / Not Recovered: 10

So a = 12, b = 5, c = 3, d = 10, and n = 30.

Step 1 — Row and column totals: Row 1 (drug) = 17, Row 2 (placebo) = 13, Column 1 (recovered) = 15, Column 2 (not recovered) = 15.

Step 2 — Compute log probability of observed table: log P(observed) = log(17!) + log(13!) + log(15!) + log(15!) − log(12!) − log(5!) − log(3!) − log(10!) − log(30!).

Step 3 — Sum probabilities of all tables at least as extreme: Enumerate all valid values of cell a (from max(0, 17−15) = 2 to min(17, 15) = 15). Sum probabilities of tables with log P ≤ log P(observed).

Step 4 — Result: Two-tailed p ≈ 0.0201, which is below the conventional α = 0.05 threshold, indicating a statistically significant association between treatment and recovery. The odds ratio = (12 × 10) / (5 × 3) = 120 / 15 = 8.00, meaning patients in the drug group had 8 times the odds of recovery compared to the placebo group.

Limitations & notes

Fisher's Exact Test is conditionally exact: it conditions on both row and column marginals being fixed, which may not reflect the actual sampling design of a study. When sample sizes are very large (n > 1000), the test becomes computationally intensive and the chi-square test or G-test is typically preferred due to equivalent accuracy. For tables larger than 2×2, Fisher's Exact Test requires extension to multi-dimensional hypergeometric distributions, often handled via Monte Carlo permutation — this calculator handles only 2×2 tables. The odds ratio becomes undefined (infinite) when any cell contains zero; in practice, a continuity correction (adding 0.5 to each cell) is sometimes applied, though this is debated. Additionally, Fisher's test is often conservative — it may yield p-values slightly above the true α level — which becomes more relevant when making decisions near the boundary of significance.

Frequently asked questions

When should I use Fisher's Exact Test instead of the chi-square test?

Use Fisher's Exact Test when your sample size is small (n < 20), when any expected cell frequency is less than 5, or when any observed cell count is 0. The chi-square test relies on a large-sample approximation that breaks down under these conditions, while Fisher's test gives an exact p-value regardless of sample size.

What does the two-tailed p-value mean in Fisher's Exact Test?

The two-tailed p-value is the probability of observing a table configuration at least as extreme as the one you have, in either direction, assuming the null hypothesis of no association is true. If this p-value is below your chosen significance level (typically 0.05), you reject the null hypothesis and conclude the two variables are significantly associated.

What is the odds ratio and how do I interpret it?

The odds ratio (OR = ad/bc) measures the strength of association between the two categorical variables. An OR of 1 means no association. OR > 1 means Group 1 has higher odds of Outcome A than Group 2. OR < 1 means Group 1 has lower odds. For example, OR = 4 means Group 1 has four times the odds of the outcome compared to Group 2.

Can Fisher's Exact Test handle tables larger than 2×2?

The standard Fisher's Exact Test applies only to 2×2 contingency tables. Extensions exist for larger r×c tables using the multivariate hypergeometric distribution, but these typically require Monte Carlo simulation because the exact enumeration becomes computationally prohibitive. This calculator is designed for 2×2 tables only.

What is the difference between the one-tailed and two-tailed p-value in this test?

The one-tailed p-value tests whether the association goes in a specific pre-specified direction (e.g., Group 1 has higher odds than Group 2). The two-tailed p-value tests whether there is any association regardless of direction. Unless you had a directional hypothesis before collecting data, you should report the two-tailed p-value to avoid inflating your Type I error rate.

Last updated: 2025-01-15 · Formula verified against primary sources.