Fisher's Exact Test Calculator
Enter the four counts of a 2×2 contingency table and get the exact p-value for Fisher's exact test (two-sided and one-sided), plus the sample odds ratio and an interpretation at the 0.05 level.
Test a 2×2 Table for Association
Fisher's Exact Test Formula
Where:
- \(a, b, c, d\) — the four cell counts of the 2×2 table (\(a\) and \(b\) are row 1, \(c\) and \(d\) are row 2)
- \(r_1 = a+b\) — the first row total; \(r_2 = c+d\), \(c_1 = a+c\), \(c_2 = b+d\) are the other margins
- \(n = r_1+r_2\) — the total number of observations
- \(X\) — the value of cell \(a\) in a random table with the same fixed margins; it follows the hypergeometric distribution
Conditioning on the observed row and column totals, the probability of each possible table is given exactly by the hypergeometric formula — no large-sample approximation is involved. The two-sided p-value sums the probabilities of all tables that are no more likely than the one actually observed (the convention used by R's fisher.test). The one-sided p-values are \(p_- = P(X \le a)\) for odds ratio < 1 and \(p_+ = P(X \ge a)\) for odds ratio > 1. The sample odds ratio is \(OR = (a\,d)/(b\,c)\).
Fisher's Exact Test – Calculation Example
Example: a study compares two groups of 10 people each. In Group 1, 8 show outcome 1 and 2 show outcome 2; in Group 2, 1 shows outcome 1 and 9 show outcome 2. So \(a=8\), \(b=2\), \(c=1\), \(d=9\), with margins \(r_1=r_2=10\), \(c_1=9\), \(c_2=11\), \(n=20\).
\[ P(X=8)=\frac{\binom{9}{8}\binom{11}{2}}{\binom{20}{10}}=\frac{9\cdot 55}{184\,756}=\frac{495}{184\,756}\approx 0.002679 \]
Tables at most as likely as the observed one are \(x=0,1,8,9\), with probabilities \(0.0000595,\ 0.002679,\ 0.002679,\ 0.0000595\). Summing them:
\[ p_{\text{two}}=2\,(0.0000595+0.002679)\approx 0.005477 \]
\[ OR=\frac{a\,d}{b\,c}=\frac{8\cdot 9}{2\cdot 1}=36 \]
Result: two-sided exact p-value ≈ 0.00548, one-sided p (OR > 1) ≈ 0.00274, one-sided p (OR < 1) ≈ 0.99994, sample odds ratio = 36. The association is statistically significant at the 0.05 level.
How to use the calculator
- Enter the count for the first group and first outcome in Outcome 1 under Group 1 (row 1) — this is cell \(a\).
- Enter the count for the first group and second outcome in Outcome 2 under Group 1 (row 1) — cell \(b\).
- Fill in Outcome 1 and Outcome 2 under Group 2 (row 2) — cells \(c\) and \(d\).
- Choose the Alternative hypothesis: two-sided for any association (the standard choice), or one-sided if the direction was fixed before the data were collected.
- Read the results: the two-sided exact p-value, both one-sided p-values, the sample odds ratio, and the interpretation block, which also reports the smallest expected cell count and whether a chi-square approximation would have been acceptable.
What Fisher's exact test is
Fisher's exact test assesses whether two categorical variables — typically a grouping (treatment vs. control, exposed vs. unexposed) and a binary outcome — are associated, using the counts of a 2×2 contingency table. It answers the question: if the row and column totals were fixed and the two variables were actually independent, how likely is it to see a table at least as extreme as the one observed?
The word exact is the key distinction from the chi-square test. The chi-square test relies on a large-sample approximation that becomes unreliable when expected cell counts are small (the classic rule of thumb warns below 5). Fisher's test instead computes probabilities directly from the hypergeometric distribution, so the p-value is valid for any sample size, including tables with very small counts or zero cells.
The p-value is the probability, under the null hypothesis of no association, of obtaining a table at least as extreme as the observed one. A small p-value (conventionally ≤ 0.05) means such an uneven table would rarely arise by chance, so the data provide evidence of an association. A large p-value means the data are consistent with no association — not that the null hypothesis is proven. To gauge the strength of the association rather than just its statistical significance, look at the odds ratio, which this calculator reports alongside the p-values; see the Odds Ratio & Relative Risk calculator for a fuller treatment.
Which alternative to use matters. The two-sided test asks about association in either direction and is the default in most software. A one-sided test is more powerful for detecting an effect in one specific direction, but the direction must be chosen before seeing the data — switching to a one-sided test after observing the result inflates the false-positive rate.
Assumptions, limitations and practical tips
- Counts, not percentages. The cells must contain raw counts of independent observations. Never enter rates, proportions or percentages — the test would be invalid.
- Independent observations. Each subject must contribute to exactly one cell. Matched or paired designs (e.g. before/after on the same people) violate this; McNemar's test is the appropriate alternative.
- Fixed margins. The exact p-value is conditional on the observed row and column totals. This is the classical formulation and matches what R and most software report.
- Zero cells. The test handles zero cells without problems. The sample odds ratio, however, becomes 0 or infinite when \(b\,c = 0\); in that case the calculator also reports the 0.5-corrected estimate \((a+0.5)(d+0.5)/((b+0.5)(c+0.5))\).
- Significance is not effect size. A tiny p-value with a large sample can correspond to a weak association. Always interpret the p-value together with the odds ratio — and consider a confidence interval for the effect size when reporting results.
- When the chi-square test is fine. If all expected cell counts are at least 5, both tests give similar answers and chi-square with Yates' continuity correction is a common alternative. The calculator's interpretation block tells you the smallest expected count, so you can judge this directly.
- One table dimension. This calculator handles 2×2 tables only. Larger tables require a general Fisher–Freeman–Halton test or an exact chi-square procedure in statistical software.
Quick reference: the four p-values you may see
| Quantity | Definition | When to use |
|---|---|---|
| Two-sided p | Sum of probabilities of all tables no more likely than the observed one | Default; any direction of association |
| One-sided p (OR > 1) | \(P(X \ge a)\) | Direction (higher odds in group 1) fixed in advance |
| One-sided p (OR < 1) | \(P(X \le a)\) | Direction (lower odds in group 1) fixed in advance |
| Odds ratio | \((a\,d)/(b\,c)\) | Effect size, not a p-value; interpret alongside the test |
Frequently Asked Questions
When should I use Fisher's exact test instead of a chi-square test?
Use Fisher's exact test whenever any expected cell count falls below about 5, when your total sample is small, or when a cell contains zero — situations where the chi-square approximation breaks down. With large samples and all expected counts of 5 or more, both tests give very similar results and either is acceptable. This calculator reports your smallest expected count so you can check instantly which situation you are in.
Why do different programs give different two-sided p-values for the same table?
Several two-sided conventions exist. This calculator uses the most common one, matching R's fisher.test: it sums the probabilities of all tables that are no more likely than the observed one. Alternatives include doubling the smaller one-sided p-value or summing tables whose odds ratio is at least as far from 1 as the observed one. Small numerical differences are normal and rarely change the conclusion at the 0.05 level.
How do I calculate Fisher's exact test by hand?
First compute the probability of your observed table from the hypergeometric distribution: \(P = \binom{a+c}{a}\binom{b+d}{b} / \binom{n}{a+b}\), using factorials for the binomial coefficients. Then enumerate every possible table with the same row and column totals, compute each probability the same way, and sum the probabilities of all tables no more likely than yours — that sum is the two-sided p-value. With tiny margins this is feasible by hand; otherwise software is much safer.
What is a good or normal p-value?
There is no "normal" p-value — it depends entirely on your data. By convention, p ≤ 0.05 is called statistically significant evidence of an association, p ≤ 0.01 stronger evidence, and p > 0.05 means the data are consistent with no association. A non-significant result does not prove there is no effect, especially with small samples. Always pair the p-value with the odds ratio to judge the strength of the association.
Can I use this test with zero cells or very small samples?
Yes — that is exactly where the exact test shines. Zero cells in the table cause no problem for the p-value because the hypergeometric formula remains valid. Only the sample odds ratio is affected: if a zero falls in the denominator product \(b\,c\), it becomes 0 or infinite, and a 0.5-corrected estimate is used instead. Even a table with a total of 4 observations yields a valid exact p-value.
What are the most common mistakes when using this calculator?
The biggest one is entering percentages, proportions, or rates instead of raw counts — the test is only valid for whole-number counts of independent observations. Other frequent errors include using it for paired or before/after data on the same subjects (McNemar's test is correct there) and switching to a one-sided test after seeing the result, which inflates the false-positive rate. Also avoid reordering rows and columns after the fact to make the p-value smaller.
Is Fisher's exact test conservative, and does it matter?
It can be slightly conservative because the p-value is computed assuming both row and column margins are fixed, when in real studies usually only the row totals (group sizes) are truly fixed. This makes the test a bit more likely to miss a real effect than its nominal 5% error rate suggests. The effect is usually small and the test remains widely accepted; alternatives like Boschloo's or Barnard's exact tests are less conservative but less standard.