- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to perform fisher test in R?
The fisher test helps us to understand whether there exists a significant non-random relationship among categorical variables or not. It is applied on contingency tables because these tables are used to represent the frequency for categorical variables and we can apply it on a matrix as well as matrices have the similar form. In R, we can use fisher.test function to perform the fisher test.
Example
M1<-matrix(1:9,ncol=3) M1
Output
[,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9
fisher.test(M1)
Fisher's Exact Test for Count Data data: M1 p-value = 0.9888 alternative hypothesis: two.sided
Example
M2<-matrix(1:16,ncol=4) M2
Output
[,1] [,2] [,3] [,4] [1,] 1 5 9 13 [2,] 2 6 10 14 [3,] 3 7 11 15 [4,] 4 8 12 16
fisher.test(M2)
Fisher's Exact Test for Count Data data: M2 p-value = 0.9993 alternative hypothesis: two.sided
Example
M3<-matrix(sample(0:4,9,replace=TRUE),nrow=3) M3
Output
[,1] [,2] [,3] [1,] 0 0 4 [2,] 4 0 4 [3,] 1 2 3
fisher.test(M3)
Fisher's Exact Test for Count Data data: M3 p-value = 0.5567 alternative hypothesis: two.sided
Example
M4<-matrix(c(14,27,15,24,27,17,39,19,24),nrow=3) M4
Output
[,1] [,2] [,3] [1,] 14 24 39 [2,] 27 27 19 [3,] 15 17 24
fisher.test(M4)
Fisher's Exact Test for Count Data data: M4 p-value = 0.02126 alternative hypothesis: two.sided
fisher.test(M4,alternative="greater")
Fisher's Exact Test for Count Data data: M4 p-value = 0.02126 alternative hypothesis: greater
fisher.test(M4,alternative="less")
Fisher's Exact Test for Count Data data: M4 p-value = 0.02126 alternative hypothesis: less
Example
M5<-matrix(sample(c(545,501,576),4,replace=TRUE),nrow=2) M5
Output
[,1] [,2] [1,] 545 545 [2,] 545 545
fisher.test(M5)
Fisher's Exact Test for Count Data data: M5 p-value = 1 alternative hypothesis: true odds ratio is not equal to 1 95 percent confidence interval: 0.8391933 1.1916205 sample estimates: odds ratio 1
fisher.test(M5,alternative="greater")
Fisher's Exact Test for Count Data data: M5 p-value = 0.5175 alternative hypothesis: true odds ratio is greater than 1 95 percent confidence interval: 0.8626582 Inf sample estimates: odds ratio 1
fisher.test(M5,alternative="less")
Fisher's Exact Test for Count Data data: M5 p-value = 0.5175 alternative hypothesis: true odds ratio is less than 1 95 percent confidence interval: 0.000000 1.159208 sample estimates: odds ratio 1
- Related Articles
- How to perform Friedman test in R?
- How to perform one sample Kolmogorov-Smirnov test in R?
- How to perform post hoc test for Kruskal-Wallis in R?
- How to perform paired t test for multiple columns in R?
- How to perform chi square test for goodness of fit in R?
- How to perform homogeneity of variance test for two-way anova in R?
- How to perform Wilcoxon test for all columns in an R data frame?
- How to perform shapiro test for all columns in an R data frame?
- How to Perform Bartlettís Test in Python?
- How To Perform Dunnís Test In Python?
- How to Perform Grubbs Test in Python
- How to Perform an F-Test in Python
- How to perform paired t test in R with a factor column in the data frame?
- How to Perform a Brown ñ Forsythe Test in Python
- How to perform tukey HSD in base R?

Advertisements