A Fisher's exact test calculator tests whether two categories are associated in a 2 × 2 table of counts, without relying on a large-sample approximation. Enter the four counts and it gives the exact probability of your table and the one-sided and two-sided p-values.
How to use the Fisher's exact test calculator
- Enter a and b for the top row of the table and c and d for the bottom row.
- Press Calculate.
- Read the two-sided p-value for a test with no direction, or one of the one-sided values if you predicted the direction before seeing the data.
What the test does
The Wikipedia article on Fisher's exact test says the test is valid for all sample sizes and is exact as long as the procedure keeps the row and column totals fixed.[1] Given the totals, the count a follows a hypergeometric distribution, which the page describes as a draws from a population with a + b successes and c + d failures.[1] The probability of one particular table is C(a + b, a) × C(c + d, c) ÷ C(n, a + c), which can also be written with factorials as (a + b)! (c + d)! (a + c)! (b + d)! ÷ (a! b! c! d! n!).[1] The calculator evaluates this with log-gamma functions, which the page says software uses to avoid overflow with large factorials.[1]
From one table to a p-value
One table is not a p-value. The one-sided p-value adds the probability of your table to the probabilities of the more extreme tables in the same direction.[1] For the two-sided p-value, the page describes the approach of the R function fisher.test: sum the probabilities of all tables whose probability is less than or equal to that of the observed table.[1] We use that rule. The page also warns that for small counts the two-sided value can differ a lot from twice the one-sided value.[1]
The worked example from the page
The page's example table has 1 and 9 in the top row and 11 and 3 in the bottom row. The probability of exactly that table is about 0.001346076.[1] The only more extreme table in that direction has 0 and 10 above 12 and 2, with probability about 0.000033652, so the one-sided p-value is about 0.001379728.[1] Enter 1, 9, 11 and 3 and the calculator shows these numbers. Our two-sided result is about 0.002759, which is twice the one-sided value for this table. The page does not state a two-sided number, so that figure is our own working using its rule.
Another example
Suppose a pilot study has 8 successes and 2 failures in one group and 1 success and 5 failures in the other. The sample odds ratio is (8 × 5) ÷ (2 × 1) = 20. The exact probability of this table is about 0.0236. The one-sided p-value is about 0.0245 and the two-sided p-value about 0.035. With so few observations, a chi-squared approximation would be unreliable. These are our own calculations with the formula above.
When to use it instead of chi-squared
The page says the chi-squared test is not suitable when the expected value in any cell is below 5, or below 10 when there is one degree of freedom, and adds that this rule is now known to be overly conservative.[1] For large samples it recommends chi-squared or, better, a G-test, and it says the exact and asymptotic p-values can be quite different for small, sparse or unbalanced data.[1] It also says the exact test becomes difficult to calculate with large samples.[1] Our calculator therefore accepts totals up to 5,000.
Fixed totals and conservatism
The test is exact when the experiment fixes the row and column totals. Many real studies fix only one set of totals or none. The page says that outside the fixed-margins setting the test is conservative and underpowered, which means the real chance of a false positive is lower than the stated level but at the cost of power.[1] Treat the result as a careful, slightly cautious answer rather than a perfect one.
Reading the odds ratio
The sample odds ratio (a × d) ÷ (b × c) is shown as a descriptive number and is our own addition, not part of the page's calculation. A value of 1 means no association in the sample. If b or c is zero the ratio is infinite, and if both a × d and b × c are zero it is not defined, so the calculator says so in words.
Reading the three p-values
The two-sided p-value answers whether the counts show any association in either direction. The one-sided p-values answer a narrower question: is a as small as this or smaller, or as large as this or larger. Choose before looking at the data, because picking the smaller tail afterwards halves the chance of error in a misleading way. When the table is balanced the two-sided value is close to twice the smaller one-sided value, but the page warns that in sparse tables it can differ a lot.{1}
How many tables are checked
The row and column totals fix the possible values of a, so only a handful of tables are possible for small samples. The calculator counts them and shows the number, for instance 11 tables for the page example. Each is given its hypergeometric probability, and the p-values are sums over some of them.
Common mistakes
- Choosing the tail after seeing the data. Decide on one-sided or two-sided before looking.
- Entering percentages. Use counts of people or events, not rates.
- Reading a small p-value as a large effect. It shows evidence against independence, not size.
What next
Use this often? Add Fisher's Exa to your Home screen.
Frequently asked questions
What is a Fisher's exact test calculator?
A tool that finds the exact p-value for a 2 × 2 table of counts using the hypergeometric distribution, so it works with small samples.
When should I use Fisher's exact test?
When counts are small, such as an expected cell value below 5, or when you want an exact answer. For large samples chi-squared or a G-test is usually used.
How is the two-sided p-value found?
By summing the probabilities of all tables with probability less than or equal to that of the observed table, as in the R function fisher.test.
What is the probability of one table?
C(a + b, a) × C(c + d, c) ÷ C(n, a + c), the hypergeometric probability given the row and column totals.
Does a small p-value prove a cause?
No. It is evidence that the two categories are associated, but the test cannot say why, and it assumes the totals are fixed.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.