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

如何用modelsummary并排展示glmmTMB的条件模型与零膨胀模型?

问题:glmmTMB零膨胀模型分模块并排展示失败

尝试使用modelsummary工具将glmmTMB拟合的零膨胀泊松模型的条件模型与零膨胀模型部分并排展示时,运行自定义构造的modelsummary_list代码后报错:

Error: `estimate` is not available. The `estimate` and `statistic` arguments must correspond to column names in the output of this command: `get_estimates(model)`

错误原因

手动构造modelsummary_list的格式不符合要求:原代码将两个组件的tidy结果放在同一个tidy列表下,而非每个模型(组件)对应一个包含tidy和glance的子列表,导致modelsummary无法正确识别所需的统计列。

解决方案

方法1:直接传入整理后的tidy结果列表

无需手动构造modelsummary_list,直接将两个组件的固定效应结果作为列表传入modelsummary,并指定模型名称:

library(glmmTMB)
library(modelsummary)
library(dplyr)

Owls <- transform(Owls,
                  Nest=reorder(Nest,NegPerChick),
                  NCalls=SiblingNegotiation,
                  FT=FoodTreatment)

fit_zipoisson <- glmmTMB(NCalls~(FT+ArrivalTime)*SexParent+
                           offset(log(BroodSize))+(1|Nest),
                         data=Owls,
                         ziformula=~1,
                         family=poisson)

# 分别提取条件模型和零膨胀模型的固定效应结果
tidy_cond <- broom.mixed::tidy(fit_zipoisson, effect = "fixed", component = "cond")
tidy_zi <- broom.mixed::tidy(fit_zipoisson, effect = "fixed", component = "zi")

# 并排展示两个模块
modelsummary(
  list("条件模型" = tidy_cond, "零膨胀模型" = tidy_zi),
  statistic = "std.error" # 可按需指定展示的统计量
)

方法2:正确构造modelsummary_list

如果需要手动构造该类对象,需确保每个子元素对应一个模型(组件),包含tidy和glance两个部分:

# 构造符合要求的modelsummary_list
mod_list <- list(
  list(tidy = tidy_cond, glance = broom.mixed::glance(fit_zipoisson)),
  list(tidy = tidy_zi, glance = broom.mixed::glance(fit_zipoisson))
)
class(mod_list) <- "modelsummary_list"

# 展示结果
modelsummary(mod_list, model.names = c("条件模型", "零膨胀模型"))

内容的提问来源于stack exchange,提问作者robertspierre

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 04:08:13