Fisher's Exact Test Calculator
Perform Fisher's exact test on a 2x2 contingency table to determine if there is a significant association between two categorical variables.
About this calculator
This calculator runs Fisher's exact test on a 2x2 contingency table, computing the exact hypergeometric probability of the observed table (line 22) and summing every table at least as extreme in the same row and column totals to build the two-tailed p-value (lines 25-35). At the defaults (Cell A=8, Cell B=2, Cell C=3, Cell D=7), that comes to a two-tailed p-value of 0.0698 — not significant at α=0.05, even though the observed table alone has only a 3.2% chance under the null (Exact Probability of This Table). Odds Ratio and Relative Risk are computed from the same four cells (lines 45-50), each capped at 9,999 rather than reported as literal infinity when the opposing cell is 0.
One counter-intuitive result from nudging each input up and down: Cell B and Cell C read as having zero effect on every output, but that is an artifact of this calculator's small integer defaults (2 and 3) combined with rounding — `Math.round(inputs.cellB || 0)` (line 5) rounds a 10% move to 2.2 or 1.8 both back to 2, so the value the engine actually sees never changes, even though Cell B and Cell C are both very much part of the row and column totals every probability term depends on. At the defaults, Cell A and Cell D happen to move the two-tailed P-Value by exactly the same amount when each is nudged the same way — a genuine tie produced by this specific table's row and column totals, not a case where one of the two cells matters more than the other. What this does not account for: any correction for multiple comparisons, and it treats every 2x2 table symmetrically regardless of whether the underlying design was a randomized experiment or an observational study, where an odds ratio and a relative risk carry different interpretations.
Inputs
Results
P-Value (two-tailed)
0.07
Odds Ratio
9.33
How to Use This Calculator
- Enter Cell A (Row 1, Col 1), Cell B (Row 1, Col 2), and Cell C (Row 2, Col 1).
- Set Cell D (Row 2, Col 2).
- Review P-Value (two-tailed) and Odds Ratio.
- Use P-Value (one-tailed) and Exact Probability of This Table to inform your decision.
- Use the chart to visualize the results and explore different scenarios by adjusting inputs.
How the result changes with Cell A (Row 1, Col 1)
| Cell A (Row 1, Col 1) | P-Value (two-tailed) | Odds Ratio |
|---|---|---|
| 4 | 0.3 | 4.67 |
| 6 | 0.15 | 7 |
| 12 | 0.01 | 14 |
| 20 | 0 | 23.33 |
What each input means
- Cell A (Row 1, Col 1)
- Count for Group 1, Outcome 1 (e.g., treatment group with positive outcome).
- Cell B (Row 1, Col 2)
- Count for Group 1, Outcome 2 (e.g., treatment group with negative outcome).
- Cell C (Row 2, Col 1)
- Count for Group 2, Outcome 1 (e.g., control group with positive outcome).
- Cell D (Row 2, Col 2)
- Count for Group 2, Outcome 2 (e.g., control group with negative outcome).
How this is calculated
Worked example, using the default values
- Identify Input Parameters4 parametersCell A (Row 1, Col 1) = 8, Cell B (Row 1, Col 2) = 2, Cell C (Row 2, Col 1) = 3, Cell D (Row 2, Col 2) = 7 = 4 input(s) provided
- Calculate P-ValueP-Value0.06978 = 0.06978
- Calculate Odds RatioOdds Ratio = Math9.3333 = 9.3333
- Calculate P-ValueP-Value0.99726 = 0.99726
- Calculate Exact Probability of This TableExact Probability of This Table0.03215 = 0.03215
Engine last updated . Checked against 2 independently-derived tests — how we verify calculators. Built by Paul Gunder, a software engineer, not a licensed financial, medical, or legal professional.
Frequently Asked Questions
Why do Cell B and Cell C appear to have zero effect on the P-Value, when they're clearly part of the table?
It's an artifact of how small their default values are, not genuine irrelevance. The engine reads them through `Math.round(inputs.cellB || 0)` (line 5), and nudging a default of 2 up or down 10% lands at 2.2 and 1.8 — both of which round right back to 2. The rounded value the formula actually sees never changes, which can make it look like Cell B and Cell C don't matter, even though both feed the row and column totals every hypergeometric probability term (line 138) depends on.
Is a two-tailed P-Value of 0.0698 the same as the calculator's Exact Probability of This Table?
No, and they answer different questions. Exact Probability of This Table (3.2% at the defaults) is the hypergeometric probability of this specific 2x2 arrangement alone (line 22); the two-tailed P-Value sums the probabilities of every possible table with the same row and column totals that is at least as extreme (lines 25-35), which is why it comes out roughly double the single-table figure.
Why is Odds Ratio capped at 9,999 instead of showing a huge number or infinity?
When Cell B or Cell C is 0, the odds-ratio formula divides by zero, which the calculator sidesteps by returning a fixed sentinel of 9,999 rather than Infinity (line 45) — then rounds the final value down to that same cap if it's ever exceeded (line 58), so an extreme association reads as a very large finite number instead of breaking the display.
Does raising Cell A always lower the two-tailed P-Value?
At this calculator's defaults, yes — increasing Cell A (currently the larger "positive outcome" count) strengthens the observed association and pushes the two-tailed P-Value down, while pushing Odds Ratio and Relative Risk up, both of which move in the opposite direction from the p-value as the evidence for association gets stronger.
Related Calculators
The questions that sit next to this one — chosen by subject, including calculators filed under a different category.
Chi-Square Test Calculator
Perform a chi-square goodness-of-fit test comparing observed and expected frequencies across four categories.
StatisticsBayesian Prior Calculator
Apply Bayes' theorem to update a prior probability given test sensitivity and false positive rate. Calculate the posterior probability after a positive or negative result.
StatisticsLogistic Regression Calculator
Calculate the predicted probability, odds, and odds ratio from logistic regression coefficients. Visualize the S-shaped probability curve.
More in Math & Statistics.