費雪正確性檢定 (Fisher's exact test)

套路53: 費雪正確性檢定 (Fisher's exact test)

1. 使用時機: 用於樣本數較少的列聯表的檢定檢定兩個隨機變數之間是否無關(independent)
2. 分析類型: 類別資料分析(Categorical Data Analysis)
3. 使用R計算費雪正確性檢定範例:
咪路調查不同性別大學生頭髮顏色資料如下:
髮色
黑色
紅色
總數
男生
5
2
7
女生
3
4
7
總數
8
6

試問髮色與性別是否有關?
H0: 髮色與性別無關(independent)
HA: 髮色與性別有關。

第一步: 閱讀基本模組(base)中的fisher.test函數的使用說明。
  help(fisher.test)
第二步: 輸入建立資料
  m <- matrix(c(5, 2, 3, 4), nrow = 2, byrow = TRUE)
  # 將資料轉成2 x 2矩陣。
  m
  # 顯示矩陣內容確保數值排列方式如資料表格所示。
第三步: 使用基本模組(base)中的fisher.test函數代入m
  fisher.test(m, alternative = "two.sided", conf.int = TRUE, conf.level = 0.95)
第四步: 判讀結果
        Fisher's Exact Test for Count Data
data:  m
p-value = 0.5921
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
  0.2418801 55.2697930
sample estimates:
odds ratio  3.043639
  # p-value < 0.05H0: 髮色與性別無關(independent)不成立。
  # p-value > 0.05H0: 髮色與性別無關(independent)成立。

4. 比較,相同數據以卡方獨立檢定分析因資料為2 x 2列聯表(degree of freedom = 1)時需做葉慈修正(Yates' correction)如下列範例所示:

第一步: 閱讀基本模組(base)stats程式套件的chisq.test函數的說明書。
  help(chisq.test)
第二步: 輸入建立資料
  m <- matrix(c(5, 2, 3, 4), nrow = 2, byrow = TRUE)
  # 將資料轉成2 x 2矩陣。
  m
  # 顯示矩陣內容確保數值排列方式如資料表格所示。
第三步: 使用stats程式套件的chisq.test函數代入m
  chisq.test(m, correct = TRUE, simulate.p.value = TRUE, B = 2000)
  # correct = TRUE 2 x 2列聯表(degree of freedom = 1)時需做葉慈修正(Yates' correction)
  # simulate.p.value = TRUE, B = 2000估計p值。
第四步: 判讀結果
        Pearson's Chi-squared test with simulated p-value (based on 2000 replicates)
data:  m
X-squared = 1.1667, df = NA, p-value = 0.6097
  # p-value < 0.05H0: 髮色與性別無關(independent)不成立。
  # p-value > 0.05H0: 髮色與性別無關(independent)成立。
  # 以此例而言雖然兩種方法結論相同,樣本數< 5的情況下仍建議使用費雪正確性檢定較適當

來勁了嗎? 想知道更多?? 補充資料(連結):
6. 關於Pearson's chi-squared test (https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test)
8. 關於R基礎R繪圖及統計快速入門:
   b. Cookbook for R: http://www.cookbook-r.com/
   d. Statistical tools for high-throughput data analysis (STHDA): http://www.sthda.com/english/
e. The Handbook of Biological Statistics: http://www.biostathandbook.com/
f. An R Companion for the Handbook of Biological Statistics: http://rcompanion.org/rcompanion/index.html
9. Zar, JH. 2010. Biostatistical Analysis, Fifth Edition, Pearson.

留言

這個網誌中的熱門文章

統計不球人 目錄 (Table of Contents)

比較二或多組變異數Levene’s 檢定 (Levene’s Test for Comparing Two or More Variances)

三因子變異數分析 (Three Way ANOVA)