成對樣本符號檢定 (Sign test for Paired-Sample Data)

套路18: 成對樣本符號檢定 (Sign test for Paired-Sample Data)

1. 使用時機: 用於分析二兩組成對資料的差異。
2. 分析類型: 無母數分析(non-parametric test)直接使用資料數值算統計叫parametric方法把資料排序之後用排序的名次算統計叫non-parametric方法。
3. 資料範例: 咪路測量幫愛斯基摩人拉車的狗狗前腿與後腿長度,資料如下:
狗狗
後腿(cm)
前腿(cm)
差異
1
14.2
13.8
+
2
14.0
13.6
+
3
14.4
14.7
-
4
14.4
13.9
+
5
14.2
14.3
-
6
14.6
14.1
+
7
14.9
14.3
+
8
15.0
14.5
+
9
14.2
13.6
+
10
14.8
14.6
+
 H0拉車的狗狗前腿與後腿長度沒差。HA拉車的狗狗前腿與後腿長度有差。
4. 方法一:
第一步安裝BSDA程式套件。
第二步呼叫BSDA程式套件備用。
  library(BSDA)
第三步閱讀BSDA程式套件中SIGN.test函數的說明書。
  help(SIGN.test)
第四步輸入建立資料,計算狗狗前腿與後腿長度差。
  h <- c(14.2, 14.0, 14.4, 14.4, 14.2, 14.6, 14.9, 15.0, 14.2, 14.8)
  f <- c(13.8, 13.6, 14.7, 13.9, 14.3, 14.1, 14.3, 14.5, 13.6, 14.6)
  diff <- h – f
第五步使用BSDA程式套件中SIGN.test函數代入資料diff
  SIGN.test(diff, md = 0, alternative = "two.sided", conf.level = 0.95)
  # md = 0表示假設前後腿長度沒差,diff中資料中位數(median) = 0
  # alternative = "two.sided"執行雙尾檢定。
第六步判讀結果。
        One-sample Sign-Test
data: diff
s = 8, p-value = 0.1094   # p-value > 0.05,狗狗前腿與後腿長度沒差,成立。
alternative hypothesis: true median is not equal to 0
95 percent confidence interval:
-0.002666667 0.567555556
sample estimates:
median of x 0.45  # 由資料估計的中位數。
Achieved and Interpolated Confidence Intervals:
                  Conf.Level L.E.pt U.E.pt
Lower Achieved CI     0.8906 0.2000 0.5000
Interpolated CI       0.9500 -0.0027 0.5676
Upper Achieved CI     0.9785 -0.1000 0.6000
  # p-value < 0.05,拉車的狗狗前腿與後腿長度沒差,不成立。
  # p-value > 0.05,拉車的狗狗前腿與後腿長度沒差,成立。

5. 方法二:
第一步安裝BSDA程式套件。
第二步呼叫BSDA程式套件備用。
  library(BSDA)
第三步閱讀BSDA程式套件中SIGN.test函數的說明書。
  help(SIGN.test)
第四步輸入建立資料。
  h <- c(14.2, 14.0, 14.4, 14.4, 14.2, 14.6, 14.9, 15.0, 14.2, 14.8)
  f <- c(13.8, 13.6, 14.7, 13.9, 14.3, 14.1, 14.3, 14.5, 13.6, 14.6)
第五步使用BSDA程式套件中SIGN.test函數代入資料hf
  SIGN.test(h, f, md = 0, alternative = "two.sided", conf.level = 0.95)
  # md = 0表示假設前後腿長度沒差,diff中資料中位數(median) = 0
  # alternative = "two.sided"執行雙尾檢定。
第六步判讀結果。
      Dependent-samples Sign-Test
data: h and f
S = 8, p-value = 0.1094   # p-value > 0.05,狗狗前腿與後腿長度沒差,成立。
alternative hypothesis: true median difference is not equal to 0
95 percent confidence interval:
-0.002666667 0.567555556
sample estimates:
median of x-y 0.45  ## 由資料估計前後腿長度差的中位數
Achieved and Interpolated Confidence Intervals:
                 Conf.Level L.E.pt U.E.pt
Lower Achieved CI     0.8906 0.2000 0.5000
Interpolated CI       0.9500 -0.0027 0.5676
Upper Achieved CI     0.9785 -0.1000 0.6000
  # p-value < 0.05,拉車的狗狗前腿與後腿長度沒差,不成立。
  # p-value > 0.05,拉車的狗狗前腿與後腿長度沒差,成立。

 6. 同樣的資料可用成對t檢定 (paired t test)分析:
第一步閱讀基本模組(base)t.test函數的說明書。
  help(t.test)
第二步輸入建立資料。
  h <- c(14.2, 14.0, 14.4, 14.4, 14.2, 14.6, 14.9, 15.0, 14.2, 14.8)
  f <- c(13.8, 13.6, 14.7, 13.9, 14.3, 14.1, 14.3, 14.5, 13.6, 14.6)
第三步: 執行基本模組(base)t.test函數代入hf資料。
  t.test(h, f, alternative = "two.sided", paired = TRUE, conf.level = 0.95)
  # alternative = "two.sided"執行雙尾檢定。
  # paired = TRUE執行成對t檢定。
第四步判讀結果。
          Paired t-test
data:  h and f
t = 3.4138, df = 9, p-value = 0.007703  # p-value < 0.05,狗狗前腿與後腿長度沒差,不成立。
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 0.1113248 0.5486752
sample estimates:
mean of the differences  0.33
  # p-value < 0.05,拉車的狗狗前腿與後腿長度沒差,不成立。
  # p-value > 0.05,拉車的狗狗前腿與後腿長度沒差,成立。
  # 由此可見兩種分析結論大不相同。

7. 同樣的資料可用成對樣本曼恩-惠尼U檢定:
第一步: 閱讀基本模組(base)中的wilcox.test函數的使用說明。
  help(wilcox.test)
第二步輸入建立資料。
  h <- c(14.2, 14.0, 14.4, 14.4, 14.2, 14.6, 14.9, 15.0, 14.2, 14.8)
  f <- c(13.8, 13.6, 14.7, 13.9, 14.3, 14.1, 14.3, 14.5, 13.6, 14.6)
第三步: 使用基本模組(base)wilcox.test函數代入資料數值。
  wilcox.test(h, f, alternative = "two.sided", paired = TRUE, conf.level = 0.95)
  # paired = TRUE樣本為成對資料。
  # alternative = "two.sided" 執行雙尾檢定。
  # 如果要檢定: H0: 狗狗前腿比後腿長 & HA: 狗狗前腿比後腿短,alternative = "less"
  # 如果要檢定: H0: 狗狗前腿比後腿短 & HA: 狗狗前腿比後腿長,alternative = "greater"
第四步: 判讀結果
        Wilcoxon signed rank test with continuity correction
data:  h and f
V = 51, p-value = 0.01867    # p-value < 0.05H0狗狗前腿與後腿長度沒差不成立。
alternative hypothesis: true location shift is not equal to 0
  # p-value < 0.05H0拉車的狗狗前腿與後腿長度沒差不成立。
  # p-value > 0.05H0拉車的狗狗前腿與後腿長度沒差成立。

來勁了嗎想知道更多?? 補充資料(連結):
1. 關於Categorical variable (https://en.wikipedia.org/wiki/Categorical_variable)
2. 關於 Statistical hypothesis testing (https://en.wikipedia.org/wiki/Statistical_hypothesis_testing)
5. 關於R基礎,R繪圖及統計快速入門:
   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
6. Zar, JH. 2010. Biostatistical Analysis, Fifth Edition, Pearson.

留言

這個網誌中的熱門文章

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

如何選擇統計方法 1

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