如何在 R 中執行 Fisher 檢驗?
Fisher 檢驗幫助我們瞭解分類變數之間是否存在顯著的非隨機關係。它應用於列聯表,因為這些表用於表示分類變數的頻率,並且我們既可以將其應用於矩陣,也可以將其應用於行矩陣,因為它們具有類似的形式。在 R 中,我們可以使用 fisher.test 函式來執行 Fisher 檢驗。
範例
M1<-matrix(1:9,ncol=3) M1
輸出
[,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
範例
M2<-matrix(1:16,ncol=4) M2
輸出
[,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
範例
M3<-matrix(sample(0:4,9,replace=TRUE),nrow=3) M3
輸出
[,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
範例
M4<-matrix(c(14,27,15,24,27,17,39,19,24),nrow=3) M4
輸出
[,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
範例
M5<-matrix(sample(c(545,501,576),4,replace=TRUE),nrow=2) M5
輸出
[,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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP