Fisher's Exact Test Calculator (2x2)

Fisher's Exact Test Calculator (2x2)

Emerging AI Skill PRO

Enter Calculation

Formula

p=(a+b)!(c+d)!(a+c)!(b+d)!n!a!b!c!d!where{a=Cell ab=Cell bc=Cell cd=Cell dn=a+b+c+d\begin{gathered} p = \dfrac{(a+b)!\,(c+d)!\,(a+c)!\,(b+d)!}{n!\;a!\,b!\,c!\,d!} \\[1.5em] \text{where}\quad \left\{ \begin{aligned} a &= \text{Cell a} \\ b &= \text{Cell b} \\ c &= \text{Cell c} \\ d &= \text{Cell d} \\ n &= a + b + c + d \end{aligned} \right. \end{gathered}
Show calculation steps (1)
  1. Two-Sided p-Value

    Ptwo-sided=∑pi≤pobspiP_{\text{two-sided}} = \sum_{\,p_i \le p_{\text{obs}}} p_i

    Sum of the probabilities of all tables (same margins) that are no more likely than the observed table; p_i is the hypergeometric probability of each possible table

Usage stats

Advertisement

Results

Two-sided p-value
0.034965
Fisher exact test (2x2)
Probability of observed table 0.023601
Total observations (n) 16

Report an error on this page

What is Fisher's Exact Test?

Fisher exact test assesses whether two categorical variables in a 2x2 contingency table are associated. Unlike the chi-square test, it computes an exact p-value rather than an approximation, making it ideal for small samples or tables with low expected cell counts. It is widely used in biology, medicine, and social science.

2x2 contingency table with cells labeled a, b, c, d and row, column, and grand totals
A 2x2 contingency table showing the four cell counts a, b, c, d with row and column totals.

How to use this calculator

Enter the four cell counts of your 2x2 table: a and b form the first row, c and d form the second row. The calculator computes the exact hypergeometric probability of the observed table and the two-sided p-value, which sums the probabilities of all tables (with the same row and column totals) that are no more likely than the one you observed.

The formula explained

With margins fixed, the probability of any specific table follows the hypergeometric distribution:

$$p = \dfrac{(a+b)!\,(c+d)!\,(a+c)!\,(b+d)!}{n!\;a!\,b!\,c!\,d!}$$

where \(n = a + b + c + d\). The two-sided p-value adds up \(p\) over every table with the same margins whose probability is less than or equal to the observed probability.

$$P_{\text{two-sided}} = \sum_{\,p_i \le p_{\text{obs}}} p_i$$
Advertisement
Hypergeometric probability distribution of table arrangements with the observed value highlighted
Fisher's test sums hypergeometric probabilities of tables as or more extreme than the observed one.

Worked example

For the table \(a = 8\), \(b = 2\), \(c = 1\), \(d = 5\) (\(n = 16\)), the probability of this exact table is about \(0.01865\). Summing all equally-or-less-likely tables gives a two-sided p-value of roughly \(0.0349\), suggesting a statistically significant association at the \(0.05\) level.

Interpreting Your Fisher's Exact Test Result

  • Below alpha. If the p-value is at or below your chosen significance level (commonly 0.05), the data would be unlikely if the two variables were independent, so you reject the null hypothesis of independence. In the example, p ≈ 0.035 is below 0.05.
  • Above alpha. If the p-value is above alpha, the data are reasonably consistent with independence, and you fail to reject the null hypothesis.
  • Evidence, not effect size. The p-value measures how surprising the table is under independence. It does not measure how strong or practically important the association is. For effect size, look at the odds ratio (here (8 × 5)/(2 × 1) = 20) and its confidence interval. With small counts, such estimates are very imprecise.
  • One-sided vs two-sided. A one-sided p-value counts only tables as extreme or more extreme in one chosen direction (e.g. a ≥ 8, which gives about 0.0245). A two-sided p-value counts extreme tables in both directions. Several two-sided definitions exist; the common one, used here, sums all tables with probability ≤ that of the observed table. The direction should be chosen before looking at the data.
  • Conditional on margins. Fisher's test treats the row and column totals as fixed and asks how the counts could be arranged within them. This is exact for any sample size, but it can be conservative, meaning the actual error rate may be below the nominal alpha, because the p-value can take only discrete values.
  • Non-significant is not "no association". A large p-value may simply reflect a small sample and low power. It is not proof that no association exists.
  • Multiple testing. If you run many tests, some will fall below 0.05 by chance. Adjust (for example with a Bonferroni correction) or report how many tests were done.
Advertisement

Key Terms in Fisher's Exact Test

2×2 contingency table
A table cross-classifying observations by two binary variables, giving four cells of counts.
Cell counts a, b, c, d
The four counts: a and b are the first row (left, right), c and d are the second row. They must be non-negative whole numbers, and n = a + b + c + d.
Marginal totals
The row sums (a + b, c + d) and column sums (a + c, b + d). Fisher's test holds these fixed.
Null hypothesis of independence
The assumption that the row variable and column variable are unrelated, equivalent to a population odds ratio of 1.
Hypergeometric distribution
The distribution of the count a when drawing without replacement with fixed margins: \(P(a)=\dfrac{\binom{a+b}{a}\binom{c+d}{c}}{\binom{n}{a+c}}\).
p-value
The probability, under the null hypothesis, of obtaining a table at least as extreme as the observed one.
One-sided vs two-sided
One-sided tests an association in a single pre-specified direction; two-sided tests for an association in either direction.
Expected cell count
Under independence, (row total × column total)/n. In the example, the expected count for cell a is 10 × 9/16 = 5.625. Fisher's test is often preferred when expected counts are small (a common rule of thumb is below 5).
Odds ratio
(a × d)/(b × c), a measure of association strength. A value of 1 means no association; it is undefined if b × c = 0 without adjustment.
Significance level (alpha)
The threshold chosen beforehand (often 0.05) for rejecting the null hypothesis; it is the maximum accepted probability of a false positive.

FAQ

When should I use Fisher's test instead of chi-square? Use Fisher exact test when sample sizes are small or any expected cell count is below 5, where the chi-square approximation is unreliable.

What does the two-sided p-value mean? It is the probability of obtaining a table at least as extreme as yours in either direction, assuming no association between the variables.

Can the test handle larger tables? This calculator handles 2x2 tables. Larger contingency tables require generalized exact tests.

Last updated:

Most popular in Math and Statistics

View all Math and Statistics calculators