Fisher's Exact Test Calculator
This Fisher's exact test calculator computes both the one-tailed and two-tailed p-value for a Fisher's exact test on any 2 x 2 contingency table.
Not sure what Fisher's exact test is? Are you wondering when to use Fisher's exact test or are you looking for a Fisher's exact test example? Scroll down - we give you the Fisher's exact test definition and explain how to calculate Fisher's exact test by hand!
What is Fisher's exact test?
In statistics, Fisher's exact test is a statistical test of independence for categorical variables. We most commonly apply it when there are two variables, and each variable has two possible values (we call such variables "dichotomous"), so we can represent data in a 2 x 2 contingency table (e.g., sex vs. handedness).
We use Fisher's exact test to determine if there is a dependence (contingency) between the two variables, i.e., whether the proportions of one variable differ depending on the value of the other variable (e.g., if left-handedness is more prevalent among men than among women). If there is no dependency, then the two variables are called independent.
Unlike other statistical tests, there is no formula for test statistics. To perform Fisher's exact test, we calculate the p-value directly, according to the hypergeometric distribution. We give more details in the third section of this Fisher's exact test calculator. First, however, let's discuss when you should use Fisher's exact test instead of the chi-squared test, which is another popular test for independence.
When to use Fisher's exact test vs. chi-squared test?
Fisher's exact test and the chi-squared test are two most popular statistical tests for independence:
Fisher's test is an exact test because we know the exact sampling distribution.
The chi-squared test is only an approximate test because the sampling distribution of the test statistic is only approximately (asymptotically) equal to the chi-square distribution.
When to use Fisher's exact test?
Choose the Fisher exact test rather than the chi-squared test if the sample size is small, the marginals are very uneven, or there is a small value (less than five) in one of the cells. This is because the approximation on which the chi-squared test is based might not be very accurate in such conditions.
When to use chi-square test?
Since we have to compute factorials, Fisher's exact test is hard to calculate when the sample is large or the contingency table is well-balanced. Fortunately, there are the conditions under which the approximation used in the chi-squared test flourishes! 🌼
Definition of Fisher's exact test
As you now have a general idea of what Fisher's exact test is, it is high time we tell you how to perform it. The null hypothesis is that the two variables are independent; in other words, that the proportions of one variable are the same for all of the different values of the other variable.
Consider a 2 x 2 contingency table with the cell frequencies represented by
We need to find the marginal totals and the grand total
Fisher showed that, under the assumption that the null hypothesis holds and the values for the marginal totals are fixed, the probability of observing the above table is given by the hypergeometric distribution, which looks like this:
where we see three different binomial coefficients. We can rewrite them as follows:
! denotes the factorial. Finally, we can write the formula as:
Tip. Observe that if we know the marginal totals, only a single degree of freedom is left. The value, e.g., of
a, is sufficient to deduce all the other values. Thus, the probability discussed above depends only on
To find the p-value for a Fisher's exact test, we have to find all possible matrices of non-negative integers with the same row and column totals as the original table and then calculate the probability of each such table. The next step depends on whether you want to determine the one- or two-tailed p-value:
For a two-tailed test, you add together the probabilities of every table that has a probability lower than or the same as that of the observed table.
For a one-tailed test, we want to take into account only those tables that are more extreme than the observed table, but only in one direction:
a < b, then sum the probabilities of all tables that have a value lower than or equal to
ain the upper-left corner, including the observed table.
a > b, then sum the probabilities of all tables that have a value greater than or equal to
ain the upper-left corner, including the observed table.
a = b, you can pick either of the above options: the results will be the same.
Tip. If you're unsure whether to use a one- or two-tailed Fisher's exact test, go for the latter option. You need a really good reason to use a one-tailed test - do it if you are interested in testing only the positive or the negative correlation between the variables.
Check our Fisher's exact test example below to see how to calculate Fisher's exact test on some real data!
How to calculate Fisher's exact test? - an example
We ask 11 people: 5 men and 6 women whether they prefer cycling or swimming. Only one man chose swimming and only two women chose cycling. The remaining people chose the other option. Let's collect our data in a contingency table:
- C stands for cycling;
- S stands for swimming;
- M stands for men; and
- W stands for women.
We calculate the marginal totals:
The probability of observing this table is equal to:
5! 6! 5! 6! / (1! 4! 4! 2! 11!) ≈ 0.16234
Let's display all possible tables (with the same total margins as the original table) and calculate their probabilities:
5! 6! 5! 6! / (0! 5! 5! 1! 11!) ≈ 0.01299
5! 6! 5! 6! / (2! 3! 3! 3! 11!) ≈ 0.43290
5! 6! 5! 6! / (3! 2! 2! 4! 11!) ≈ 0.32468
5! 6! 5! 6! / (4! 1! 1! 5! 11!) ≈ 0.06494
5! 6! 5! 6! / (5! 0! 0! 6! 11!) ≈ 0.00216
Now we have enough information to calculate the the p-value of this Fisher's exact test!
One-tailed p-value is (approximately) equal to
0.01299 + 0.16234 = 0.17532.
This number is the sum of the probability of the observed table and that of the table
Two-tailed p-value is (approximately) equal to
0.01299 + 0.16234 + 06494 + 0.00216 = 0.24242
i.e., to the sum of probabilities of the observed table and of the tables:
We hope that everything is now clear after this Fisher's exact test example 🙂
How to use this Fisher's exact test calculator?
To use the Fisher's exact test calculator you need to do the following:
- First of all, enter the 2 x 2 contingency table that you observed, i.e. enter a, b, c, and d.
- Decide whether you need the one- or two-tailed p-value. If unsure, check the section Definition of Fisher's exact test.
- When all necessary input is present, our Fisher's exact test calculator displays the result of your test.