Phi係數 (Phi coefficient)

套路33: Phi係數(Phi coefficient)

1. 使用時機: Phi係數是兩個二元變量(dichotomous variable)的關聯性度量。
2. 範例資料: 某機構研究某昆蟲與植物疾病的關連,原始資料如下:
植物
1
2
3
4
5
6
7
8
9
10
11
12
13
14
有病
+
+
-
-
+
+
+
-
+
-
-
-
+
+
有蟲
-
-
-
+
+
+
+
+
+
+
+
-
-
-
3. 上述資料可整理成2 x 2矩陣如下:

植物有病
植物沒病
加總
有蟲
4
4
8
沒蟲
4
2
6
加總
8
6
14
4. 使用R計算Phi係數方法一:
第一步: 安裝sjstats程式套件
第二步: 呼叫sjstats程式套件備用
 library(sjstats)
第三步: 輸入建立資料(邏輯: TTRUEFFALSE)
cnt <- read.table(header = T, text = "
Dis Ins
T F
T F
F F
F T
T T
T T
T T
F T
T T
F T
F T
F F
T F
T F")
第四步: 閱讀sjstats程式套件的xtab_statistics函數的使用說明
  help(xtab_statistics)
第五步: 使用sjstats程式套件的xtab_statistics函數代入cntDisIns計算Phi係數及p
  xtab_statistics(cnt, Dis, Ins, statistics = "phi")
第六步: 判讀計算結果
    Measure of Association for Contingency Tables
                  (using Fisher's Exact Test)
     Chi-squared: 0.0061
         Phi: 0.1667
     p-value: 0.6270
  # 如計算結果p-value < 0.05,虛無假設(H0: 蟲與植病無關)不成立,蟲與植病有關
  # 如計算結果p-value > 0.05,虛無假設(H0: 蟲與植病無關)成立,蟲與植病無關
5. 使用R計算Phi係數方法二:
第一步: 安裝sjstats程式套件
第二步: 呼叫sjstats程式套件
  library(sjstats)
第三步: 輸入建立資料(前述2 x 2矩陣資料)
  cnt <- matrix(c(4, 4, 4, 2), nrow = 2, byrow = T)
第四步: 閱讀sjstats程式套件的phi函數的使用說明
  help(phi)
第五步: 使用sjstats程式套件的phi函數代入cnt計算Phi係數
  phi(cnt)
[1] 0.1666667   # 計算結果
  # 沒有提供假設檢定p值。
6. 使用R計算Phi係數方法三:
第一步: 安裝Rbioconductor中的GenomicRanges程式套件。
  source("https://bioconductor.org/biocLite.R")
  biocLite("GenomicRanges")
第二步: 呼叫GenomicRanges程式套件備用。
  library(GenomicRanges)
第三步: 輸入建立資料(邏輯: TTRUEFFALSE)
cnt <- read.table(header = T, text = "
Dis Ins
T F
T F
F F
F T
T T
T T
T T
F T
T T
F T
F T
F F
T F
T F")  # 資料空白分隔。
  attach(cnt)  # 告訴R要使用cnt中的資料。
  names(cnt)  # 指定DisIns為資料欄位名稱。
第四步: 閱讀GenomicRanges程式套件的phicoef函數的使用說明
  help(phicoef)
第五步: 使用GenomicRanges程式套件的phicoef函數代入DisIns計算Phi係數
  phicoef(Dis, Ins)
[1] -0.1666667  # 計算結果。
  # 沒有提供假設檢定p值。

7. 使用R計算Phi係數方法四:
第一步: 安裝psych程式套件
第二步: 呼叫psych程式套件
  library(psych)
第三步: 輸入建立資料(前述2 x 2矩陣資料)
  cnt <- matrix(c(4, 4, 4, 2), nrow = 2, byrow = T)
第四步: 閱讀psych程式套件的phi函數的使用說明
  help(phi)
第五步: 使用psych程式套件的phi函數代入cnt計算Phi係數
  phi(cnt)
[1] -0.17   # 計算結果
  # 沒有提供假設檢定p值。

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

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

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