首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >你能改变R中TukeyHSD的顺序吗?

你能改变R中TukeyHSD的顺序吗?
EN

Stack Overflow用户
提问于 2021-05-20 22:09:38
回答 1查看 29关注 0票数 0

我刚刚在3组之间的r中运行了方差分析(aov)。组1,2,3。

为我的模型运行TukeyHSD后,我的比较将按组的顺序进行比较:

2-1,3-1,3-2

可以将其更改为: 1-2,1-3,2-3

谢谢

EN

回答 1

Stack Overflow用户

发布于 2021-05-20 22:46:48

使用relevel将不起作用,因为您不想更改级别顺序,只想更改标签。首先,我们需要一些可重现的数据:

代码语言:javascript
运行
复制
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的标签:

代码语言:javascript
运行
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67622068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档