似然比適合度檢定 (Log-likelihood Ratio Goodness of fit test)

套路47: 似然比適合度檢定 (Log-likelihood Ratio Goodness of fit test)

1. 使用時機: 似然比(Log-likelihood Ratio)適合度檢定用來分析數據之分佈型(distribution)或符合某種比例。
2. 分析類型: 母數分析(parametric analysis)
3. 範例資料: 夢得爾葛格計數黃色圓皮黃色皺皮綠色圓皮及綠色皺皮碗豆資料如下:
性狀
黃色圓皮
黃色皺皮
綠色圓皮
綠色皺皮
總數
觀察值
152
39
53
6
250
期望值
(9/16) x 250
(3/16) x 250
(3/16) x 250
(1/16) x 250

試問黃色圓皮黃色皺皮綠色圓皮及綠色皺皮碗豆比例是否為9:3:3:1?
H0: 黃色圓皮黃色皺皮綠色圓皮及綠色皺皮碗豆比例為9:3:3:1
HA: 黃色圓皮黃色皺皮綠色圓皮及綠色皺皮碗豆比例不是9:3:3:1

4. 使用R計算似然比適合度檢定方法一:
第一步: 安裝DescTools程式套件。
第二步: 呼叫DescTools程式套件備用。
  library(DescTools)
第三步: 閱讀DescTools程式套件的GTest函數的說明書。
  help(GTest)
第四步: 輸入建立資料
  x <- c(152, 39, 53, 6)
第五步: 使用DescTools程式套件的GTest函數代入x及期望值。
  GTest(x, p = c(9/16, 3/16, 3/16, 1/16))
  # p = c(9/16, 3/16, 3/16, 1/16)比例期望值,加總需等於1
  # p = c(9, 3, 3, 1)不行,因為比例期望值加總需等於1
第六步: 判讀結果
Results of Hypothesis Test
--------------------------
Alternative Hypothesis:         
Test Name:                       Log likelihood ratio (G-test) goodness of fit test
Data:                            x
Test Statistic:                      G = 10.83251
Test Statistic Parameter:             X-squared df = 3
P-value:                          0.01266689
  # P-value < 0.05H0: 黃色圓皮黃色皺皮綠色圓皮及綠色皺皮碗豆比例為9:3:3:1不成立。
  # P-value > 0.05H0: 黃色圓皮黃色皺皮綠色圓皮及綠色皺皮碗豆比例為9:3:3:1成立。
5. 使用R計算似然比適合度檢定方法二:
第一步: 安裝RVAideMemoire程式套件。
第二步: 呼叫RVAideMemoire程式套件備用。
  library(RVAideMemoire)
第三步: 閱讀RVAideMemoire程式套件的G.test函數的說明書。
  help(G.test)
第四步: 輸入建立資料
  x <- c(152, 39, 53, 6)
第五步: 使用RVAideMemoire程式套件的G.test函數代入x及期望值。
  G.test (x, p = c(9/16, 3/16, 3/16, 1/16))
  # p = c(9/16, 3/16, 3/16, 1/16)比例期望值,加總需等於1
  # p = c(9, 3, 3, 1)不行,因為比例期望值加總需等於1
第六步: 判讀結果
Results of Hypothesis Test
--------------------------
Alternative Hypothesis:         
Test Name:                       G-test for given probabilities
Data:                            x
Test Statistic:                      G = 10.83251
Test Statistic Parameter:             df = 3
P-value:                          0.01266689
  # P-value < 0.05H0: 黃色圓皮黃色皺皮綠色圓皮及綠色皺皮碗豆比例為9:3:3:1不成立。
  # P-value > 0.05H0: 黃色圓皮黃色皺皮綠色圓皮及綠色皺皮碗豆比例為9:3:3:1成立。

6. 注意有一種狀況是只有兩項(degree of freedom = 1)時需做葉慈修正(Yates' correction)如下列範例所示:
夢得爾葛格計數黃色及綠色碗豆資料如下::

黃色
綠色
總數
碗豆數
84
16
100
試問黃色及綠色碗豆比例是否為3:1?
H0: 黃色及綠色碗豆比例為3:1
HA: 黃色及綠色碗豆比例不是3:1

第一步: 安裝DescTools程式套件。
第二步: 呼叫DescTools程式套件備用。
  library(DescTools)
第三步: 閱讀DescTools程式套件的GTest函數的說明書。
  help(GTest)
第四步: 輸入建立資料
  x <- c(84, 16)
第五步: 使用DescTools程式套件的GTest函數代入x及期望值。
  GTest(x, correct = "yates", p = c(3/4, 1/4))
  # p = c(3/4, 1/4)比例期望值,加總需等於1
  # p = c(3, 1)不行,因為比例期望值加總需等於1
  # correct = "yates" 葉慈修正
第六步: 判讀結果
Results of Hypothesis Test
--------------------------
Alternative Hypothesis:         
Test Name:                       Log likelihood ratio (G-test) goodness of fit test
Data:                            x
Test Statistic:                      G = 4.216863
Test Statistic Parameter:             X-squared df = 1
P-value:                          0.04002409
  # P-value < 0.05H0: 黃色及綠色碗豆比例為3:1不成立。
  # P-value > 0.05H0: 黃色及綠色碗豆比例為3:1成立。

來勁了嗎? 想知道更多?? 補充資料(連結):
2. 關於Likelihood-ratio test (https://en.wikipedia.org/wiki/Likelihood-ratio_test)
4. 關於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
5. Zar, JH. 2010. Biostatistical Analysis, Fifth Edition, Pearson.

留言

這個網誌中的熱門文章

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

如何選擇統計方法 1

如何檢查資料是否接近常態分布 (Normality Test using R)