LoginSignup
0
0

Rで多重比較(Bonferroni, Wilcoxon, Kruskal-Wallis, Dunn)

Last updated at Posted at 2024-01-25

多重比較

3群以上のデータに対して、どの群間に平均値の差があるかを検定には多重比較を用いる。2群間の検定を繰り返し行ってはいけない。これは、第一種の過誤(αエラー)が増大し、検定の精度が低下するためである。

複数回の検定を行った際に適切な有意水準が保たれるようにする方法の一つにボンフェローニ(Bonferroni)補正がある。

Rで多重比較を行う

Bonferroni補正を用いた多重比較をRで行う方法を記す。

Wilcoxon rank sam 検定(ボンフェローニ補正)

まずはサンプルデータの入力。

data <- c(301, 311, 320, 291, 388, 412, 325, 361, 287, 197, 180, 247, 260, 248, 199, 179, 134, 163, 200, 209, 302, 187, 166, 234, 290, 175, 116, 342, 216, 316, 386, 324, 145, 254, 228)

group <- factor(rep(c("A", "B", "C", "D"), c(9, 10, 8, 8)))

pairwise.wilcox.testを実行。公式ドキュメント

x=:インプットするデータを指定。
g=:群のラベルを指定。
paired=:データの対応の有無を指定。
p.adjust.method=:p値の補正方法を"bonferroni"に指定。

pairwise.wilcox.test(x=data, g=group, paired=F, p.adjust.method="bonferroni")

結果

	Pairwise comparisons using Wilcoxon rank sum exact test 

data:  data and group 

  A       B       C      
B 0.00013 -       -      
C 0.00592 1.00000 -      
D 1.00000 0.20568 0.49790

P value adjustment method: bonferroni 

Dunn検定

パッケージ"dunn.test"のインストールと読み込み。公式ドキュメント

install.packages("dunn.test")
library(dunn.test)

dunn.testを実行。

x=:インプットするデータを指定。
g=:群のラベルを指定。
paired=:データの対応の有無を指定。
method=::p値の補正方法を"bonferroni"に指定。

dunn.test(x=data, g=group, method="bonferroni")

結果

  Kruskal-Wallis rank sum test

data: data and group
Kruskal-Wallis chi-squared = 17.0615, df = 3, p-value = 0


                         Comparison of data by group                        
                                 (Bonferroni)                                  
Col Mean-|
Row Mean |          A          B          C
---------+---------------------------------
       B |   3.655600
         |    0.0008*
         |
       C |   3.210627  -0.252028
         |    0.0040*     1.0000
         |
       D |   1.352870  -2.155103  -1.805415
         |     0.5283     0.0935     0.2130

alpha = 0.05
Reject Ho if p <= alpha/2

t 検定(ボンフェローニ補正)

pairwise.t.testを実行。公式ドキュメント

x=:インプットするデータを指定。
g=:群のラベルを指定。
paired=:データの対応の有無を指定。
p.adjust.method=:p値の補正方法を"bonferroni"に指定。

pairwise.t.test(x=data, g=group, paired=F, p.adjust.method="bonferroni")

結果

    Pairwise comparisons using t tests with pooled SD 

data:  data and group3

  A       B       C      
B 0.00013 -       -      
C 0.00070 1.00000 -      
D 0.30912 0.05520 0.16404

P value adjustment method: bonferroni 
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0