Fisher's Exact Test
Calculator
Input Your Values
Variable 1 \ Variable 2 | Category 1 | Category 2 |
---|---|---|
Category 1 | ||
Category 2 |
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
1# Create a contingency table
2data <- matrix(c(8, 1, 2, 7), nrow = 2,
3 dimnames = list(
4 c("Recovered", "Not Recovered"),
5 c("Treatment", "Control")
6 ))
7# or simply
8# data = rbind(c(8,1),c(2,7))
9
10# Perform Fisher's exact test
11result <- fisher.test(data, alternative = "greater")
12
13# Print results
14print(result)
1from scipy.stats import fisher_exact
2import numpy as np
3
4# Create contingency table
5contingency_table = np.array([
6 [8, 2], # Recovered (Treatment, Control)
7 [1, 7] # Not Recovered (Treatment, Control)
8])
9
10# Perform Fisher's exact test
11odds_ratio, p_value = fisher_exact(contingency_table, alternative='greater')
12
13print(f'Odds Ratio: {odds_ratio:.4f}')
14print(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
Related Calculators
Contingency Table Calculator
Chi-Square Test of Independence Calculator
Chi-Square Goodness of Fit Calculator
Friedman Test Calculator
Help us improve
Found an error or have a suggestion? Let us know!