You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 20:58:12