1

全部,

我想在诸如 kruskal wallis 之类的秩中位数移位测试中执行相当于 TukeyHSD

X=matrix(c(1,1,1,1,2,2,2,4,4,4,4,4,1,3,6,9,4,6,8,10,1,2,1,3),ncol=2)
anova=aov(X[,2]~factor(X[,1]))
TukeyHSD(anova)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = X[, 2] ~ factor(X[, 1]))
##
## $`factor(X[, 1])`
## diff lwr upr p adj
## 2-1 1.25 -5.927068 8.427068 0.8794664
## 4-1 -1.35 -7.653691 4.953691 0.8246844
## 4-2 -2.60 -9.462589 4.262589 0.5617125
kruskal.test(X[,2]~factor(X[,1]))
##
## Kruskal-Wallis rank sum test
##
## data: X[, 2] by factor(X[, 1])
## Kruskal-Wallis chi-squared = 1.7325, df = 2, p-value = 0.4205

我现在想分析一下对比。请帮忙。谢谢。里克

4

2 回答 2

0

如果要在 Kruskal-Wallis 测试后进行多重比较,则需要包中的kruskalmc函数pgirmess。在实现此功能之前,您需要将矩阵转换为数据框。在您的示例中:

# convert matrix to dataframe
dfx <- as.data.frame(X)

# the Kruskal-Wallis test & output
kruskal.test(dfx$V2~factor(dfx$V1))


    Kruskal-Wallis rank sum test

data:  dfx$V2 by factor(dfx$V1)
Kruskal-Wallis chi-squared = 1.7325, df = 2, p-value = 0.4205

# the post-hoc tests & output
kruskalmc(V2~factor(V1), data = dfx)

Multiple comparison test after Kruskal-Wallis 
p.value: 0.05 
Comparisons
    obs.dif critical.dif difference
1-2    1.75     6.592506      FALSE
1-4    1.65     5.790265      FALSE
2-4    3.40     6.303642      FALSE
于 2015-04-26T06:37:25.370 回答
0

如果您想要类似于从 TukeyHSD 输出的紧凑字母显示,对于 Kruskal 测试,库agricolae允许它使用函数kruskal. 使用您自己的数据:

  library(agricolae)
print( kruskal(X[, 2], factor(X[, 1]), group=TRUE, p.adj="bonferroni") )
#### ...
#### $groups
####   trt means M
#### 1   2  8.50 a
#### 2   1  6.75 a
#### 3   4  5.10 a

(好吧,在这个例子中,这些组不被认为是不同的,与其他答案相同的结果..)

于 2016-09-22T10:20:13.383 回答