Free Fisher's Exact Test Calculator
Contingency Table
Results
Enter values in the table above to see results.
What Is Fisher’s Exact Test?
Fisher’s exact test is a nonparametric statistical procedure used to examine the independence of two categorical variables. It is especially suited for data organized in a 2×2 contingency table when sample sizes are small. Unlike the chi‑squared test, which relies on an asymptotic approximation, Fisher’s exact test computes an exact p‑value using the hypergeometric distribution. This Fisher exact test calculator provides both the one‑tailed and two‑tailed p‑value for any 2×2 table, acting as a dedicated p‑value calculator for categorical data analysis.
When to Use Fisher’s Exact Test vs. the Chi‑Squared Test
Both Fisher’s exact test and the chi‑squared test evaluate whether two categorical variables are independent. The main difference is:
- Fisher’s exact test is an exact test; its sampling distribution is known precisely, so no approximation is needed.
- The chi‑squared test is an approximate test; its test statistic only follows a chi‑squared distribution in large samples.
You should choose Fisher’s exact test when the sample size is small, the marginal totals are highly unbalanced, or any cell has an expected frequency below 5. Under these conditions the chi‑squared approximation can be inaccurate. On the other hand, when the sample is large and the table is well balanced, the chi‑squared test performs well, while Fisher’s test becomes computationally intensive because it requires factorial calculations.
How the P‑Value Is Calculated
The null hypothesis states that the two variables are independent. Assuming fixed row and column totals (the marginals), the probability of observing a particular 2×2 table follows the hypergeometric distribution:
where:
- and are the cells in the first row,
- and are the cells in the second row,
- is the grand total.
Because the marginals are fixed, only one cell (say ) is free to vary; the other three cells are determined through simple relations: , , . This reduces the degrees of freedom to one.
To obtain the p‑value, we must enumerate all possible 2×2 tables that share the same row and column totals as the observed data. For each such table we compute its probability using the formula above. Then:
- One‑tailed test: sum the probabilities of all tables that are as extreme or more extreme in the direction indicated by the data (i.e., tables with an upper‑left cell or the observed value, depending on the direction).
- Two‑tailed test: sum the probabilities of all tables whose probability is less than or equal to that of the observed table.
Worked Example
Consider a small survey of 11 people (5 men, 6 women) about their preferred sport: swimming (S) or cycling (C). The results are:
| Swimming | Cycling | Total | |
|---|---|---|---|
| Men | 1 | 4 | 5 |
| Women | 4 | 2 | 6 |
| Total | 5 | 6 | 11 |
The observed table has probability:
All tables that can occur with the same marginal totals are those where the upper‑left cell ranges from 0 to 5. Their probabilities are:
| Probability | |
|---|---|
| 0 | 0.01299 |
| 1 | 0.16234 |
| 2 | 0.43290 |
| 3 | 0.32468 |
| 4 | 0.06494 |
| 5 | 0.00216 |
In this example the observed . The one‑tailed p‑value (testing the direction where ) sums the probabilities for and :
The two‑tailed p‑value sums the probabilities of tables with probability , i.e., those with :
A p‑value smaller than a chosen significance level (e.g., 0.05) would lead to rejecting the null hypothesis of independence. Here, both p‑values are well above 0.05, so we conclude there is insufficient evidence to suggest an association between sex and sport preference.
How to Use This Fisher’s Exact Test Calculator
- Input the four cell values of your 2×2 contingency table: (row 1, col 1), (row 1, col 2), (row 2, col 1), and (row 2, col 2). All values must be non‑negative integers.
- Select the test direction – one‑tailed or two‑tailed. A two‑tailed test is the standard choice unless you have a strong a priori directional hypothesis.
- The calculator instantly returns the exact p‑value for the selected test.
For a more complete analysis of categorical data, an odds ratio calculator can complement this tool by quantifying the strength of the observed association, although the primary output of this calculator remains the exact p‑value.
FAQ
1. When should I use Fisher's exact test instead of the chi-squared test?
Use Fisher's exact test when sample sizes are small, marginal totals are unbalanced, or any expected cell count is less than 5. Under these conditions the chi-squared approximation may be inaccurate, while Fisher's test provides an exact p-value.
2. How is the p-value calculated in Fisher's exact test?
The p-value is obtained by listing all 2×2 tables with the same marginal totals as the observed data. For each table the probability is computed using the hypergeometric distribution formula (involving factorials). The one‑tailed or two‑tailed p-value is the sum of the probabilities of tables considered as extreme or more extreme than the observed table.
3. What is the difference between one‑tailed and two‑tailed Fisher's exact test?
A one‑tailed test sums the probabilities of tables that are extreme in a single direction (e.g., upper‑left cell ≤ observed value). A two‑tailed test sums the probabilities of all tables whose probability is ≤ that of the observed table, regardless of direction. The two‑tailed test is recommended unless you have a specific directional hypothesis.
4. Can I use this calculator for large samples?
Yes, the calculator can handle any sample size. However, the enumeration of all possible tables becomes factorial‑intensive for very large or well‑balanced tables. In such cases the chi‑squared test is a practical alternative, but this tool will still compute the exact p-value correctly.
5. What does the p‑value from Fisher's exact test tell me?
The p‑value is the probability, under the null hypothesis of independence, of observing data as extreme (or more extreme) than what you actually observed. A small p‑value (e.g., below 0.05) suggests that the association between the two variables is unlikely to have occurred by chance, leading to rejection of the independence hypothesis.
How to Use
- Enter the contingency table - Enter the four observed frequencies (a, b, c, d) of your 2x2 contingency table.
- Select test type - Choose between a one-tailed or two-tailed Fisher's exact test.
- View results - The calculator displays the p-value and odds ratio for your data.