This calculator helps you determine whether there is a significant relationship between two categorical variables, especially when sample sizes are small (n < 20) or when cell values are less than 5. Unlike the Chi-Square test, Fisher's Exact Test calculates the exact probability of observing a particular distribution of frequencies in a 2×2 contingency table, making it ideal when expected cell counts are low. This test is widely used in fields like genetics, clinical trials, and social sciences to analyze small datasets. Click here to populate the sample data for a quick example.
Calculator
1. Load Your Data
2. Select Columns & Options
Learn More
Fisher's Exact Test
Definition
Fisher's Exact Test is used to determine whether there is a significant association between two categorical variables in a 2×2 contingency table. It's particularly useful when sample sizes are small or when cell values are less than 5. The test calculates the exact probability of observing the data assuming the null hypothesis of independence is true.
Formula
The probability of observing any particular table:
Where:
- cell frequencies
- total sample size
- denotes factorial
Odds Ratio:
Key Assumptions
Fisher's Exact Test: Step-by-Step Example
Step 1: State the Data
Drug effectiveness study results:
Group | Treated | Control | Total |
---|---|---|---|
Recovered | 8 | 2 | 10 |
Not Recovered | 1 | 7 | 8 |
Total | 9 | 9 | 18 |
Step 2: Calculate Table Probability
(This is the probability of observing exactly this table configuration)
Step 3: Calculate P-values
For right-sided test (treatment increases recovery), we need all possible tables maintaining margins:
When :
8 | 2 | 10 |
1 | 7 | 8 |
9 | 9 | 18 |
When :
9 | 1 | 10 |
0 | 8 | 8 |
9 | 9 | 18 |
Right-sided p-value calculation:
Step 4: Calculate Odds Ratio
Step 5: Draw Conclusion
Since -value () (), we reject . There is strong evidence that the treatment increases recovery rate, with the odds of recovery being 28 times higher in the treatment group.
Note:
- The initial probability (0.0074) is for our observed table only
- The p-value (0.0076) includes all tables as or more extreme
- We maintain row and column totals for all possible tables
Code Examples
# Create a contingency table
data <- matrix(c(8, 1, 2, 7), nrow = 2,
dimnames = list(
c("Recovered", "Not Recovered"),
c("Treatment", "Control")
))
# or simply
# data = rbind(c(8,1),c(2,7))
# Perform Fisher's exact test
result <- fisher.test(data, alternative = "greater")
# Print results
print(result)
from scipy.stats import fisher_exact
import numpy as np
# Create contingency table
contingency_table = np.array([
[8, 2], # Recovered (Treatment, Control)
[1, 7] # Not Recovered (Treatment, Control)
])
# Perform Fisher's exact test
odds_ratio, p_value = fisher_exact(contingency_table, alternative='greater')
print(f'Odds Ratio: {odds_ratio:.4f}')
print(f'p-value: {p_value:.4f}')
Alternative Tests
Consider these alternatives:
- Chi-square Test: For larger sample sizes
- Barnard's Test: When marginal totals aren't fixed