Fisher Exact Test Calculator
Enter the four counts of a 2x2 table. Fisher's exact p-value is computed exactly, no approximation.
https://flxcode.com/fisher-exact-test-calculator/
Row 1 and row 2 are the two groups, column 1 and column 2 the two outcomes. Whole numbers, 0 or more.
Example Fisher’s exact test
No evidence of an association at the 5% level
Read a 2 × 2 table, 20 in total.
Your table, with totals
| Row | Column 1 | Column 2 | Total |
|---|---|---|---|
| Row 1 | 8 | 2 | 10 |
| Row 2 | 3 | 7 | 10 |
| Total | 11 | 9 | 20 |
The odds ratio shown is the sample one, (a × d) ÷ (b × c). There is no conditional estimate or confidence interval for it on this page.
Pick the one-sided direction before you look at the data. If you did not, use the two-sided p-value.
| Two-sided p-value | 0.0697785 |
|---|---|
| One-sided p-value, greater (odds ratio above 1) | 0.0348893 |
| One-sided p-value, less (odds ratio below 1) | 0.997261 |
| Sample odds ratio (a × d) ÷ (b × c) | 9.33333 |
| Probability of exactly this table | 0.0321505 |
| Row totals | 10 and 10 |
| Column totals | 11 and 9 |
| Total count (n) | 20 |
The steps, with your numbers
The totals are fixed: rows 10 and 10, columns 11 and 9, 20 in all. With those totals the top-left count can be any whole number from 1 to 10.
The chance of a top-left count x is C(10, x) × C(10, 11 − x) ÷ C(20, 11). For your table, x = 8: 0.0321505.
Two-sided p adds the chances of every table that is no more likely than yours (a tolerance of 1e−7 on the ratio, as R and scipy use): 0.0697785.
Greater adds the chances of x = 8 and every larger count: 0.0348893. Less adds x = 8 and every smaller count: 0.997261.
No ads. No account. Nothing you type or record is uploaded. We count page events with a daily code. Check it. What this tool keeps and sends.
Problem or idea? Email us
Quick start
- Type the four counts: the first row is one group, the second row the other, and the columns are the two outcomes.
- The headline is the two-sided p-value. The one-sided values, the odds ratio and your table with its totals are below.
Worked examples
| Case | Counts | Two-sided p | One-sided p (greater) | Odds ratio |
|---|---|---|---|---|
| Tea tasting | 3 and 1 in the top row, 1 and 3 in the bottom | 0.485714 | 0.242857 | 9 |
| Treated or not | 8 and 2, then 3 and 7 (the example above) | 0.0697785 | 0.0348893 | 9.333 |
| Perfect split | 0 and 5, then 5 and 0 | 0.00793651 | 1 | zero |
| Larger counts | 120 and 80, then 90 and 110 | 0.00363519 | 0.00181759 | 1.833 |
| Rare then common | 2 and 10, then 12 and 4 | 0.00632955 | 0.999829 | 0.06667 |
The tea tasting table is Fisher's own example: a lady claims she can tell whether milk went in first, and gets 3 of 4 cups right. Even that is not strong evidence, with a two-sided p of 0.485714.
The formulas
With the totals fixed, the top-left count x has the chance C(r₁, x) × C(r₂, c₁ − x) / C(n, c₁), where r₁ and r₂ are the row totals, c₁ the first column total and n the grand total. The page builds all these chances from the most likely table outward, so nothing overflows even with a hundred thousand counts, and adds the ones the p-value needs.
Excel and Google Sheets
Put the counts in B2:C3. The chance of exactly your table is one function, and the one-sided sums follow from its cumulative form.
| What | Formula | Gives (example) |
|---|---|---|
| Your table | =HYPGEOM.DIST(B2,B2+C2,B2+B3,SUM(B2:C3),FALSE) | 0.0321505 |
| One-sided, less | =HYPGEOM.DIST(B2,B2+C2,B2+B3,SUM(B2:C3),TRUE) | 0.997261 |
| One-sided, greater | =1-HYPGEOM.DIST(B2-1,B2+C2,B2+B3,SUM(B2:C3),TRUE) | 0.0348893 |
For the two-sided p-value, add the chances of every table no more likely than yours, or use this page, which does it exactly.
Numbers this uses
- Method is exact, no approximation. Hypergeometric chances summed in log-free ratios.
- Accuracy is matches scipy to 9 digits or better. Checked on 300 random tables up to 100,000 counts, plus Fisher’s tea tasting.
- Limit is 1,000,000 counts in total. Kept low so the page stays quick on a phone.
Limits
This page does one 2 × 2 table. There is no conditional odds ratio or confidence interval, no stratified (Mantel-Haenszel) version and no larger tables. Counts must be whole numbers, and no row or column may add up to 0. The test assumes each person or item is in the table once, so it does not suit before-and-after counts on the same people.
FAQ
When do I use Fisher’s exact test?
For a 2 × 2 table of counts when the numbers are small: the usual rule is that an expected count below 5 makes the chi-square test unreliable. Fisher’s test has no such rule because it does not approximate. It also works fine with big counts, just not much differently from chi-square.
What does exact mean?
With the row and column totals fixed, only a limited set of tables is possible, and each has a known chance (the hypergeometric distribution). The p-value adds up the chances of the tables at least as unlikely as yours. No bell curve is used.
Two-sided or one-sided?
Two-sided asks whether the groups differ in either direction and is the usual choice. One-sided "greater" asks whether the top-left count is larger than chance would give (odds ratio above 1). For the example it gives p = 0.0348893 against 0.0697785 two-sided. Choose the direction before you see the data.
How is the two-sided p-value defined?
It adds every table whose chance is no larger than the chance of yours, with a tiny tolerance for rounding (a relative 1e−7). R and scipy do the same. Some programs double the smaller one-sided p instead, which gives a different number for lopsided tables.
What is the odds ratio shown?
The sample odds ratio (a × d) ÷ (b × c). It is infinite when b × c is 0. R reports a slightly different conditional estimate with a confidence interval; this page does not.
Fisher or chi-square?
For a 2 × 2 table with small counts, Fisher. With large counts they agree closely. For tables bigger than 2 × 2 use the chi-square test calculator; this page handles 2 × 2 only.
More from FLXCode
- Chi-Square Test CalculatorChi-square test of independence and goodness of fit from a pasted table, with expected counts and Cramér's V.
- P-Value Calculatorp-value from a z, t, chi-square or F statistic, one or two tailed, with the tails shown.
- T-Test CalculatorOne-sample, Welch, Student and paired t-tests from raw data or summary numbers, with p, CI and d.
- Z-Score Calculatorz-score from a value, mean and standard deviation, or from data, with percentile and p-values.