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

如何在modelsummary中移除指定组件行,仅保留conditional->fixed组件?

保留modelsummary表格中conditional->fixed组件行的方法

要移除conditional->random和zero_inflated->fixed行,仅保留conditional->fixed组件,有两种简洁的实现方式:

方法一:使用coef_omit参数筛选

通过modelsummary自带的coef_omit参数,用正则表达式匹配需要排除的行:

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,
             coef_omit = "(random|zero_inflated)"
             )

coef_omit会排除所有匹配到random或zero_inflated的行,只保留目标组件内容。

方法二:先提取并筛选系数数据

先通过tidy()提取模型的系数信息,再精准筛选目标行后传入modelsummary:

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

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

# 筛选conditional->fixed的系数行
tidy_mod <- tidy(mod) |>
  filter(component == "conditional", effect == "fixed")

# 生成表格
modelsummary(tidy_mod,
             output = "flextable",
             shape = component + effect + term + statistic ~ model
             )

这种方式更灵活,适合需要自定义筛选逻辑的场景。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.01 17:12:27