我刚刚在3组之间的r中运行了方差分析(aov)。组1,2,3。
为我的模型运行TukeyHSD后,我的比较将按组的顺序进行比较:
2-1,3-1,3-2
可以将其更改为: 1-2,1-3,2-3
谢谢
发布于 2021-05-20 22:46:48
使用relevel
将不起作用,因为您不想更改级别顺序,只想更改标签。首先,我们需要一些可重现的数据:
data(iris)
SL <- iris$Sepal.Length
Sp <- as.factor(as.numeric(iris$Species))
iris.aov <- aov(SL~Sp)
iris.mc <- TukeyHSD(iris.aov)
iris.mc
# Tukey multiple comparisons of means
# 95% family-wise confidence level
#
# Fit: aov(formula = SL ~ Sp)
#
# $Sp
# diff lwr upr p adj
# 2-1 0.930 0.6862273 1.1737727 0
# 3-1 1.582 1.3382273 1.8257727 0
# 3-2 0.652 0.4082273 0.8957727 0
现在,为了切换标签,我们使用expand.grid
来创建切换了第一个和第二个组id的标签:
ngroups <- 3
Grps <- expand.grid(seq(ngroups), seq(ngroups))
Grps <- Grps[Grps$Var1 < Grps$Var2,] # Unique groups
newlbls <- unname(apply(Grps, 1, paste0, collapse="-"))
dimnames(iris.mc$Sp)[[1]] <- newlbls
iris.mc
# Tukey multiple comparisons of means
# 95% family-wise confidence level
#
# Fit: aov(formula = SL ~ Sp)
#
# $Sp
# diff lwr upr p adj
# 1-2 0.930 0.6862273 1.1737727 0
# 1-3 1.582 1.3382273 1.8257727 0
# 2-3 0.652 0.4082273 0.8957727 0
https://stackoverflow.com/questions/67622068
复制相似问题