ThisCalculator

Everyday

Fisher’s Exact Test Calculator: How It Works

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

Fisher's Exact Test Calculator: How It Works

This calculator performs Fisher’s exact test for a 2×2 contingency table, returning the two-tailed p-value that tests whether the row and column variables are independent. You enter the four cell counts (a, b, c, d), and the calculator computes the exact probability of observing your table or one more extreme, given the fixed row and column totals. The result tells you whether the observed association is statistically significant without relying on large-sample approximations.

Formula

Fisher’s exact test uses the hypergeometric distribution. For a 2×2 table with cells a, b, c, d and row totals R1 = a+b, R2 = c+d, column totals C1 = a+c, C2 = b+d, and total N = a+b+c+d, the probability of observing exactly that table under the null hypothesis of independence is:

P = (R1! R2! C1! C2!) / (N! a! b! c! d!)

where ! denotes factorial. The two-tailed p-value is the sum of probabilities of all tables with the same row and column totals that have a probability less than or equal to the observed table’s probability. This is the standard definition used in most statistical software.

Worked Example

Using the default values: a=10, b=5, c=3, d=12. Row totals: R1 = 15, R2 = 15. Column totals: C1 = 13, C2 = 17. Total N = 30.

  1. Compute the probability of the observed table: P_obs = (15! 15! 13! 17!) / (30! 10! 5! 3! 12!) ≈ 0.0175.
  2. Enumerate all possible tables with these margins. The possible values of a range from max(0, C1-R2)=0 to min(R1,C1)=13.
  3. For each possible a, compute the probability using the formula above. The possible tables and their probabilities are: a=0: 0.0000, a=1: 0.0001, a=2: 0.0010, a=3: 0.0050, a=4: 0.0163, a=5: 0.0367, a=6: 0.0598, a=7: 0.0718, a=8: 0.0646, a=9: 0.0438, a=10: 0.0224, a=11: 0.0085, a=12: 0.0023, a=13: 0.0004.
  4. The observed table (a=10) has probability 0.0224. Sum probabilities of all tables with probability ≤ 0.0224: these are a=0,1,2,3,4,9,10,11,12,13. Sum = 0.0000+0.0001+0.0010+0.0050+0.0163+0.0438+0.0224+0.0085+0.0023+0.0004 = 0.0998.
  5. The two-tailed p-value is approximately 0.0998, which rounds to 0.0998.

Since the p-value is above the conventional 0.05 threshold, you would not reject the null hypothesis of independence at the 5% significance level.

When to Use Fisher’s Exact Test

Fisher’s exact test is ideal when you have a 2×2 contingency table and the sample size is small. The chi-square test of independence relies on an approximation that becomes unreliable when expected cell counts are below 5. Fisher’s test computes the exact probability, so it works for any sample size, but it is especially valuable when:

  • Any expected cell count is less than 5.
  • The total sample size is less than 20.
  • One or more cells have a count of zero.
  • You want a precise p-value without relying on asymptotic assumptions.

In practice, many statisticians use Fisher’s test whenever any expected count is below 5, and some use it for all 2×2 tables as a conservative default.

How to Read the Result

The output is a p-value between 0 and 1. It represents the probability of observing a table as extreme as yours (or more so) if the row and column variables were truly independent. A small p-value (typically below 0.05) suggests that the observed association is unlikely to be due to chance alone, leading to rejection of the null hypothesis. A large p-value means the data are consistent with independence. Remember that a non-significant result does not prove independence—it simply means the evidence is insufficient to conclude an association.

Fisher’s test is exact, so the p-value is not an approximation. However, it is conditional on the row and column totals being fixed. In many experimental designs, only one margin is fixed, but the test remains valid and is widely used.

Common Mistakes and Misconceptions

  • Using one-tailed when you need two-tailed: The one-tailed p-value tests a directional hypothesis. The two-tailed p-value is more common and more conservative. Always decide which is appropriate before running the test.
  • Mislabeling rows and columns: The test is symmetric, so swapping rows and columns does not change the p-value. But entering counts in the wrong cells (e.g., swapping b and c) will change the result.
  • Ignoring the fixed margins assumption: Fisher’s test conditions on the observed margins. This is fine for most studies, but if your design does not fix margins, the test is still valid, though slightly conservative.
  • Using Fisher’s test for larger tables: The test extends to r×c tables, but the computation becomes heavy. For larger tables, use a chi-square test or Fisher-Freeman-Halton test.
  • Rounding p-values too early: Report p-values to 3 or 4 decimal places, but do not round intermediate probabilities.

Comparison with Chi-Square Test

The chi-square test of independence is the most common alternative. It is computationally simple and works well for large samples. However, it uses an approximation that can be poor when expected counts are small. Fisher’s exact test gives the exact p-value, but it can be computationally intensive for large counts because it enumerates all possible tables. For a 2×2 table, the number of possible tables is limited by the smaller margin, so even with large counts, modern calculators handle it quickly. In practice, many textbooks recommend using Fisher’s test when any expected count is below 5, and chi-square otherwise. Some researchers use Fisher’s test exclusively for 2×2 tables because it is exact and requires no assumptions about sample size.

Limitations and Practical Considerations

Fisher’s exact test assumes that the row and column totals are fixed by the study design. In many observational studies, only the total sample size is fixed, not the margins. Despite this, the test is still valid and often used. Another limitation is that the test is conditional on the margins, which can make it conservative—meaning it may fail to reject the null hypothesis more often than a test that does not condition on margins. For very large counts, the test can be slow if implemented naively, but optimized algorithms exist. The p-value is exact, but it is still a probability, so it is subject to random variation. Always report the p-value with the effect size and confidence intervals for a complete analysis.

Frequently Asked Questions

What is the difference between one-tailed and two-tailed Fisher’s exact test?

The one-tailed test checks for association in a specific direction (e.g., the proportion in cell a is greater than expected). The two-tailed test checks for any association, regardless of direction. The two-tailed p-value is generally larger and is the default in most software. Use the one-tailed test only if you have a strong prior hypothesis about the direction of the effect.

Can Fisher’s exact test be used for tables larger than 2×2?

Yes, the test generalizes to r×c tables, but the computation becomes much more complex. For larger tables, the Fisher-Freeman-Halton test is used, but it can be computationally intensive. In practice, for tables larger than 2×2, the chi-square test is often preferred unless expected counts are very small.

Why does my p-value differ from a chi-square test?

Fisher’s exact test gives the exact probability, while the chi-square test uses an approximation. When sample sizes are small, the approximation can be poor, leading to different p-values. As sample sizes grow, the two tests converge. Fisher’s test is generally more accurate for small samples.

What does a p-value of 0.05 mean in Fisher’s test?

A p-value of 0.05 means that, if the null hypothesis of independence were true, there is a 5% chance of observing a table as extreme as yours. It is a common threshold for statistical significance, but it is arbitrary. Always interpret the p-value in context, not as a binary yes/no.

Can I use Fisher’s exact test with zero cells?

Yes, Fisher’s test handles zero cells gracefully. In fact, it is one of the few tests that works when a cell count is zero. The exact calculation includes tables with zero counts, so the p-value is still valid.

Is Fisher’s exact test conservative?

Yes, because it conditions on the observed margins, it can be conservative, meaning it may produce larger p-values than tests that do not condition on margins. This is not a problem, but it means the test is less likely to reject the null hypothesis. For large samples, the difference is negligible.

Related

Formula used
in a | Cell a (row 1, col 1) | - | 10 | 0
in b | Cell b (row 1, col 2) | - | 5 | 0
in c | Cell c (row 2, col 1) | - | 3 | 0
in d | Cell d (row 2, col 2) | - | 12 | 0
out p | Two-tailed p-value | - | (compute_fisher_p(a,b,c,d)) | 4

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.