Fisher's Exact Test Calculator

Compute exact two-tailed and one-tailed p-values for 2×2 contingency tables without asymptotic approximation error. Includes full hypergeometric distribution modeling, Cochran's rule check, sample odds ratio, relative risk, and Lancaster's mid-p value.

2 × 2 Contingency Table

Enter observed counts across independent groups

Custom Labels (Rows & Columns)Optional
Frequencies MatrixConditioned on fixed marginal totals
Group
Success (+)
Failure (-)
Row Total
Group 1 (Treatment)
Cell aExp: 2.0
Cell bExp: 2.0
4R₁
Group 2 (Control)
Cell cExp: 2.0
Cell dExp: 2.0
4R₂
Col Total
4C₁
4C₂
N = 8Grand Total
Cochran’s Chi-Square Rule Triggered (Fisher Required)

One or more cells have an expected frequency below 5. Pearson's Chi-Square test suffers from substantial asymptotic approximation error here. Fisher's Exact Test is the necessary and authoritative gold-standard.

Why Fix the Marginals?

Fisher's Exact Test is an exact conditional test. By conditioning on the fixed row totals (R₁, R₂) and column totals (C₁, C₂), the degrees of freedom become 1: knowing cell aalone completely determines the entire 2×2 table. Under the null hypothesis of independence, cell a follows a pure Hypergeometric distribution.

Statistical Decision (α = 0.05)
No Statistically Significant Association (Fail to Reject H₀)
Two-Tailed Exact pActive
0.4857
∑ P(X) ≤ P(observed table)
Right-Tailed p (OR > 1)
0.2429
P(X ≥ 3)
Left-Tailed p (OR < 1)
0.9857
P(X ≤ 3)
Sample Odds Ratio (OR)
9.000
95% CI: [0.367, 220.927]
Relative Risk (RR)
3.000
95% CI: [0.501, 17.954]
Lancaster Mid-P Value
0.1429
Reduced conservatism adjustment

Hypergeometric Distribution of Cell a: [min = 0, max = 4]

Each bar is a possible 2×2 table keeping margins fixed. Hover to inspect.

Observed (a = 3)Extreme (≤ P_obs)Non-Extreme
0
1
2
3
4
Observed Table probability: P(X = 3) = 0.2286. Hover over any bar to view the corresponding 2×2 table and probability.
Comparison: Fisher's Exact vs. Chi-Square Methodsdf = 1
Fisher's Exact Test
p = 0.4857
Exact (Hypergeometric)
Yates' Corrected χ²
p = 0.4795
χ² = 0.50
Pearson χ² (Uncorrected)
p = 0.1573
χ² = 2.00

Complete Step-by-Step Mathematical Walkthrough

Calculated with your exact numbers and fixed marginal totals

1Establish Contingency Marginals and Bounds
Row 1 Total (R₁): a + b = 3 + 1 = 4
Row 2 Total (R₂): c + d = 1 + 3 = 4
Col 1 Total (C₁): a + c = 3 + 1 = 4
Col 2 Total (C₂): b + d = 1 + 3 = 4
Grand Total (N) : 8
Feasible range for cell a: [max(0, R₁ - C₂), min(R₁, C₁)] = [0, 4]
2Hypergeometric Probability of Observed Table

The exact probability of observing cell a = 3 under H₀ is:

P(a = 3) = [ (4! × 4! × 4! × 4!) ] / [ 8! × 3! × 1! × 1! × 3! ]
P(a = 3) = &binom;(4, 3) × &binom;(4, 1) / &binom;(8, 4)
P_observed = 0.2286
3Summing Probabilities for Two-Tailed and One-Tailed P-Values
Two-Tailed Exact P: Sum of all tables with P(X) ≤ 0.2286 = 0.4857
Right-Tailed P (OR > 1): Sum from a = 3 to 4 = 0.2429
Left-Tailed P (OR < 1): Sum from a = 0 to 3 = 0.9857
Lancaster Mid-P: 0.5 × 0.2286 + ∑[P(X) < P_obs] = 0.1429
4Effect Sizes (Odds Ratio, Relative Risk, Risk Difference)
Odds Ratio (OR) = (a × d) / (b × c) = (3 × 3) / (1 × 1) = 9.000
95% CI of OR = [0.367, 220.927]
Group 1 Positive Rate: 3 / 4 = 75.00%
Group 2 Positive Rate: 1 / 4 = 25.00%
Relative Risk (RR) = 3.000
Risk Difference (Δp) = 50.00% [95% CI: -10.01%, 100.00%]
5Final Research Conclusion at α = 0.05

Because the test p-value (0.4857) is greater than or equal to α = 0.05, we fail to reject the null hypothesis. The observed association does not exceed random hypergeometric chance fluctuation at the 5% significance level.

What is Fisher's Exact Test?

Fisher's Exact Test is a non-parametric statistical significance test introduced by Sir Ronald A. Fisher in 1935. It evaluates whether there is a non-random association between two categorical variables in a 2 × 2 contingency table. Unlike Pearson's Chi-Square test—which relies on large-sample asymptotic approximations that require the central limit theorem—Fisher's test calculates the exact mathematical probability of obtaining the observed table (and tables more extreme) under the null hypothesis.

The test is especially indispensable when sample sizes are small, or when any cell in the 2×2 table has an expected frequency of less than 5. It conditions on the marginal totals (the sum of each row and column being fixed), allowing the distribution of cell frequencies to be modeled precisely via the Hypergeometric distribution.

When to Choose Fisher's Exact Test vs. Alternative Tests

Statistical test selection for 2×2 contingency tables depends primarily on sample size and study design:

Statistical TestSample Size CriteriaSubject PairingBest Practical Use
Fisher's Exact TestSmall (N < 20 or any E < 5)Independent groupsGold standard for rare outcomes, small clinical trials, and cell counts < 5.
Pearson's Chi-Square (χ²)Large (All E ≥ 5)Independent groupsStandard asymptotic test for large survey and epidemiological datasets.
Yates' Continuity Corrected χ²Moderate (N > 20, E ≈ 5)Independent groupsReduces chi-square over-optimism by subtracting 0.5 from |O - E|.
McNemar's TestAny sample sizePaired / Repeated MeasuresMatched case-control or pre-post binary tests on the exact same subjects.
Barnard's Exact TestSmall samplesIndependent groups (unconditional)Unconditional test that does not fix both margins; slightly higher statistical power.

Historical Origin: The “Lady Tasting Tea” Experiment

At Rothamsted Experimental Station in the late 1920s, Dr. Muriel Bristol asserted that she could taste whether milk or tea had been poured into a cup first. Her colleague, the statistician Ronald A. Fisher, designed a rigorous blinded randomized trial with 8 cups of tea: 4 with milk poured first, and 4 with tea poured first.

• Total cups: N = 8
• Milk first cups: R₁ = 4, Tea first cups: R₂ = 4
• Lady was told: exactly 4 cups were milk first (C₁ = 4)
• Number of combinations: &binom;(8, 4) = 70 possible tables

Dr. Bristol successfully identified 3 of the 4 milk-first cups (cell a = 3). Under Fisher's exact hypergeometric calculation, the probability of correctly identifying all 4 cups by pure luck is &binom;(4,4)×&binom;(4,0)/70 = 1/70 ≈ 0.0143. The probability of identifying at least 3 cups is (1 + 16)/70 = 17/70 ≈ 0.2429. This famous milestone laid the foundation for modern randomized experimental design and exact hypothesis testing!

Verifying Results in R, Python, and SPSS

Our calculator produces outputs that match the scientific computing industry standards:

R (stats::fisher.test)Base R
# 2x2 matrix: matrix(c(a, c, b, d), nrow=2)
# R fills columns first!
mat <- matrix(c(3, 1, 1, 3), nrow = 2,
              dimnames = list("Treatment" = c("Yes", "No"),
                             "Outcome"   = c("Success", "Fail")))

# Two-sided Fisher's Exact Test:
fisher.test(mat, alternative = "two.sided")

# One-sided Right:
# fisher.test(mat, alternative = "greater")
Python (scipy.stats.fisher_exact)SciPy
from scipy.stats import fisher_exact

# Table format: [[a, b], [c, d]]
table = [[3, 1],
         [1, 3]]

# Two-sided test:
odds_ratio, p_value = fisher_exact(table, alternative='two-sided')
print("Odds Ratio:", odds_ratio)
print("Two-sided p-value:", p_value)

# One-sided right test:
# res = fisher_exact(table, alternative='greater')

Frequently Asked Questions

William Davis

Created by William Davis

Last updated: October 14, 2026

Add to Google Preferred