multcomp::cld()无法兼容emmeans的emmList/emmGrid对象问题求助
解决emmeans紧凑字母标记(CLD)显示问题
方法1:使用emmeans内置的CLD()函数
emmeans目前已自带紧凑字母标记生成功能,无需依赖multcomp的cld(),直接调用包内函数即可:
pigs.lm <- lm(log(conc) ~ source + factor(percent), data = pigs) pigs.emm <- emmeans(pigs.lm, "percent", type = "response") CLD(pigs.emm, alpha = 0.10, Letters = LETTERS)
方法2:通过multcomp的glht()中转调用
若坚持使用multcomp的cld(),需先将emmgrid对象转换为glht类型,再执行标记生成:
library(multcomp) pigs.lm <- lm(log(conc) ~ source + factor(percent), data = pigs) pigs.emm <- emmeans(pigs.lm, "percent", type = "response") # 转换为glht对象 pigs.glht <- glht(pigs.lm, linfct = emmeans::linfct(pigs.emm)) # 生成紧凑字母标记 cld(pigs.glht, alpha = 0.10, Letters = LETTERS)
额外提示
- 确保emmeans和multcomp均为最新版本,版本不兼容是接口失效的核心原因
- 若基于线性模型的链接尺度(此例为log尺度)生成标记,可移除
type = "response"参数
内容的提问来源于stack exchange,提问作者SteveMcManaman
相关产品推荐
相关产品推荐

