在modelsummary中移除组件

编程语言 2026-07-10

请看下列示例:

library(glmmTMB)
library(modelsummary)

mod <- glmmTMB(
  formula = mpg ~ cyl + disp + hp + (1|gear),
  data = mtcars,
  ziformula = ~ hp + wt
)

modelsummary(mod,
             output = "flextable",
             shape = component + effect + term + statistic ~ model,
             )

其结果为:

在此输入图片描述

如何从表格中去掉 conditional -> randomzero_inflated -> fixed 行,只保留 conditional -> fixed 组件?

解决方案

简要说明 使用 component = "cond"effects = "fixed",并将 componentshape 规范中排除。

modelsummary(mod,
             output = "flextable",
             component = "cond", effects = "fixed",
             shape = effect + term + statistic ~ model,
             )

你可以通过 model_summary()get_estimates()parameters::model_parameters() 传递参数。看看后者的参数集(args(parameters:::model_parameters.glmmTMB)),似乎你应该能够传入 effects = "fixed"component = "cond",仅为条件组件获得固定效果。

如果你仍然希望在表格中显示「组件」列,或包含在 shape 参数中,你需要再费点功夫,因为指定 component = "cond"effects = "fixed 会在返回的参数表中漏掉 component 参数。在这种情况下,你需要 component = "condcoef_map = names(fixef(mod)$cond) ...

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章