列聯表: 似然比獨立檢定 (Contingency Table: Log-likelihood Ratio Test of Independence)

套路52: 列聯表: 似然比獨立檢定
(Contingency Table: Log-likelihood Ratio Test of Independence)

1. 使用時機: 用於檢定兩個隨機變數之間是否無關(independent)。。
2. 分析類型: 類別資料分析(Categorical Data Analysis)
3. 範例資料: 咪路調查不同性別大學生頭髮顏色,資料如下:
發色
黑色
棕色
金色
紅色
總數
男生
32
43
16
9
100
女生
55
65
64
16
200
試問發色與性別是否有關?
H0: 發色與性別無關(independent)
HA: 發色與性別有關。

4. 使用R計算似然比獨立檢定方法一:
第一步: 安裝DescTools程式套件。
第二步: 呼叫DescTools程式套件備用。
  library(DescTools)
第三步: 閱讀DescTools程式套件的GTest函數的說明書。
  help(GTest)
第四步: 輸入建立資料。
  v1 <- c(32, 43, 16, 9)
  v2 <- c(55, 65, 64, 16)
  m <- matrix(cbind(c(v1, v2)), nrow = 2, byrow = TRUE)
  # 將兩組vector組合成2 x 4矩陣。
  m
  # 顯示矩陣內容,確保數值排列方式如資料表格所示。
第五步: 使用DescTools程式套件的GTest函數代入m
  GTest(m)
第六步: 判讀結果。
        Log likelihood ratio (G-test) test of independence without correction
data:  m
G = 9.5121, X-squared df = 3, p-value = 0.0232
  # p-value < 0.05H0: 發色與性別無關(independent),不成立。
  # p-value > 0.05H0: 發色與性別無關(independent),成立。

5. 使用R計算似然比獨立檢定方法二:
第一步: 安裝RVAideMemoire程式套件。
第二步: 呼叫RVAideMemoire程式套件備用。
  library(RVAideMemoire)
第三步: 閱讀RVAideMemoire程式套件的G.test函數的使用說明。
  help(G.test)
第四步: 輸入建立資料。
  v1 <- c(32, 43, 16, 9)
  v2 <- c(55, 65, 64, 16)
  m <- matrix(cbind(c(v1, v2)), nrow = 2, byrow = TRUE)
  # 將兩組vector組合成2 x 4矩陣。
  m
  # 顯示矩陣內容,確保數值排列方式如資料表格所示。
第五步: 使用RVAideMemoire程式套件的G.test函數代入m
  G.test(m)
第六步: 判讀結果。
        G-test
data:  m
G = 9.5121, df = 3, p-value = 0.0232
  # p-value < 0.05H0: 發色與性別無關(independent),不成立。
  # p-value > 0.05H0: 發色與性別無關(independent),成立。

6. 注意,有一種狀況是資料為2 x 2列聯表(degree of freedom = 1)時需做葉慈修正(Yates' correction),如下列範例所示:
咪路調查大學生不同性別慣用左手或右手人數,資料如下:

男生
女生
總數
慣用左手
6
12
18
慣用右手
28
24
52
試問慣用左手或右手是否與性別有關?
H0: 慣用左手或右手與性別無關(independent)
HA: 慣用左手或右手與性別有關。

第一步: 安裝DescTools程式套件。
第二步: 呼叫DescTools程式套件備用。
  library(DescTools)
第三步: 閱讀DescTools程式套件的GTest函數的使用說明。
  help(GTest)
第四步: 輸入建立資料。
  v1 <- c(6, 12)
  v2 <- c(28, 24)
  m <- matrix(cbind(c(v1, v2)), nrow = 2, byrow = TRUE)
  # 將兩組vector組合成2 x 2矩陣。
  m
  # 顯示矩陣內容,確保數值排列方式如資料表格所示。
第五步: 使用DescTools程式套件的GTest函數代入m
  GTest(m, correct = "yates")
  # correct = "yates" 葉慈修正
第六步: 判讀結果。
        Log likelihood ratio (G-test) test of independence with Yates' correction
data:  m
G = 1.5233, X-squared df = 1, p-value = 0.2171
  # p-value < 0.05H0: 慣用左手或右手與性別無關(independent),不成立。
  # p-value > 0.05H0: 慣用左手或右手與性別無關(independent),成立。

來勁了嗎? 想知道更多?? 補充資料(連結):
2. 關於Likelihood-ratio test (https://en.wikipedia.org/wiki/Likelihood-ratio_test)
3. 關於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
4. 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)