Kruskal-Wallis检验是单向方差分析的非参数类似物。非参数测试用于不满足参数测试假设的情况。如果我们发现Kruskal-Wallis之间存在显着差异,则进行事后测试以找出存在差异的地方。为此,我们可以执行dunn测试。可以通过FSA软件包访问dunn测试功能。
加载FSA软件包:
> library(FSA)
请看以下数据帧:
> x1<-sample(LETTERS[1:5],20,replace=TRUE) > y1<-rnorm(20,1,0.35) > df1<-data.frame(x1,y1) > df1
输出结果
x1 y1 1 E 1.1191117 2 D 1.1276032 3 D 1.5610692 4 E 1.1585054 5 E 1.0239322 6 C 0.8000165 7 C 1.2009313 8 B 1.1928228 9 A 0.7421504 10 B 0.7212436 11 C 1.4088902 12 B 1.3171291 13 D 0.9434812 14 A 0.7986718 15 C 1.0394762 16 A 0.9239324 17 E 1.1447561 18 D 1.0192032 19 B 0.8772467 20 A 0.5723085
执行dunnTest:
> dunnTest(y1~x1,data=df1) Dunn (1964) Kruskal-Wallis multiple comparison p-values adjusted with the Holm method.
输出结果
Comparison Z P.unadj P.adj 1 A - B -1.61355862 0.10662320 0.7463624 2 A - C -2.21117293 0.02702386 0.2702386 3 B - C -0.59761430 0.55009732 1.0000000 4 A - D -2.09165007 0.03646983 0.2917586 5 B - D -0.47809144 0.63258512 1.0000000 6 C - D 0.11952286 0.90486113 1.0000000 7 A - E -2.15141150 0.03144373 0.2829936 8 B - E -0.53785287 0.59067863 1.0000000 9 C - E 0.05976143 0.95234564 1.0000000 10 D - E -0.05976143 0.95234564 0.9523456 Warning message: x1 was coerced to a factor.
> x2<-sample(c("India","Russia","China","Croatia"),20,replace=TRUE) > y2<-rpois(20,5) > df2<-data.frame(x2,y2) > df2
输出结果
x2 y2 1 Russia 0 2 Russia 6 3 Croatia 8 4 Croatia 5 5 Russia 5 6 Croatia 9 7 India 9 8 Croatia 6 9 India 4 10 China 1 11 Croatia 7 12 China 3 13 India 3 14 India 4 15 Croatia 6 16 China 7 17 China 8 18 Croatia 10 19 India 8 20 China 7
> dunnTest(y2~x2,data=df2) Dunn (1964) Kruskal-Wallis multiple comparison p-values adjusted with the Holm method.
输出结果
Comparison Z P.unadj P.adj 1 China - Croatia -1.18245422 0.23702552 1.0000000 2 China - India -0.08066504 0.93570834 0.9357083 3 Croatia - India 1.09532601 0.27337384 1.0000000 4 China - Russia 0.77619975 0.43763106 0.8752621 5 Croatia - Russia 1.82479827 0.06803148 0.4081889 6 India - Russia 0.84605772 0.39752054 1.0000000 Warning message: x2 was coerced to a factor.
> x3<-sample(c("G1","G2","G3","G4","G5"),20,replace=TRUE) > y3<-rexp(20,1.34) > df3<-data.frame(x3,y3) > df3
输出结果
x3 y3 1 G2 1.89169184 2 G3 2.74074462 3 G3 0.17273122 4 G2 0.34856852 5 G2 0.80544065 6 G1 0.54582070 7 G2 0.24551988 8 G5 0.02546690 9 G3 2.86315652 10 G1 0.43704405 11 G1 1.89036598 12 G5 0.02423629 13 G5 0.03848270 14 G1 1.01897322 15 G1 0.44416202 16 G5 0.96637068 17 G2 0.74919567 18 G5 3.24106689 19 G1 1.22994992 20 G3 0.84658591
> dunnTest(y3~x3,data=df3) Dunn (1964) Kruskal-Wallis multiple comparison p-values adjusted with the Holm method.
输出结果
Comparison Z P.unadj P.adj 1 G1 - G2 0.4745469 0.6351099 1.0000000 2 G1 - G3 -0.4582576 0.6467674 0.6467674 3 G2 - G3 -0.8693183 0.3846731 1.0000000 4 G1 - G5 1.0328375 0.3016800 1.0000000 5 G2 - G5 0.5345225 0.5929801 1.0000000 6 G3 - G5 1.3732709 0.1696681 1.0000000 Warning message: x3 was coerced to a factor.