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)
第三步: 輸入建立資料(邏輯: T為TRUE,F為FALSE)。
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函數代入cnt、Dis及Ins計算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係數,方法三:
第一步: 安裝R的bioconductor中的GenomicRanges程式套件。
  source("https://bioconductor.org/biocLite.R")
  biocLite("GenomicRanges")
第二步: 呼叫GenomicRanges程式套件備用。
  library(GenomicRanges)
第三步: 輸入建立資料(邏輯: T為TRUE,F為FALSE)。
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)  # 指定Dis及Ins為資料欄位名稱。
第四步: 閱讀GenomicRanges程式套件的phicoef函數的使用說明。
  help(phicoef)
第五步: 使用GenomicRanges程式套件的phicoef函數代入Dis及Ins計算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值。
來勁了嗎? 想知道更多?? 補充資料(連結):
4. 關於R基礎,R繪圖及統計快速入門:
   a. R Tutorial: https://www.tutorialspoint.com/r/index.htm
   b. Cookbook for R: http://www.cookbook-r.com/
   c. Quick-R: https://www.statmethods.net/
   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.
 
留言
張貼留言