来自 gtsummary 包的 Tbl_regression 用于负二项式回归

问题描述

为了评估某些患者组(患者组;分类变量)和疾病(disease_outcome;计数变量)之间是否存在关联,我正在运行负二项式回归模型(由于过度分散)。为了检查其他变量的混杂情况,我运行了 3 个协变量数量不断增加的模型。

要显示 IRR 和 CI,我想使用 tbl_regression 包中的 gtsummary 函数(我使用的是最新版本 1.3.7.9022)。但是,调用该函数会返回 IRR 和相应的 95% CI 未取幂,即使我输入了 exponentiate=TRUE:

# Load packages
library(haven)
library(magrittr)
library(MASS)
library(dplyr)
install.packages("gtsummary")
remotes::install_github("ddsjoberg/gtsummary")
library(gtsummary)

# Load example data.
dat <- read_dta("https://stats.idre.ucla.edu/stat/stata/dae/nb_data.dta")
dat <- within(dat,{
  prog <- factor(prog,levels = 1:3,labels = c("General","Academic","Vocational"))
  id <- factor(id)
})


# Run negative binomial regression and pipe in the tbl_regression function
Model 1 <-  
  glm.nb(data=dat,formula=daysabs ~ prog) %>%
  tbl_regression(exponentiate=TRUE) 

Model 1

这将返回汇总表,但尚未对回归系数取幂。有没有办法让 gtsummary 返回指数系数和 CI?

谢谢!

解决方法

我只是四处看看发生了什么。 tbl_regression() 函数在后台使用 broom::tidy()。 7 天前刚刚添加了对 negbin 模型的支持,但由于某种原因,没有为此类模型添加 exponentiate= 参数。

我将请求添加它。与此同时,这段代码应该能让你开始使用 negbin 模型。

library(gtsummary)
library(tidyverse)

# add a custom tidying function
my_negbin_tidy <- function(x,exponentiate = FALSE,...) {
  df_tidy <- broom::tidy(x,...)
  
  # exponentiate coef and CI if requested
  if (exponentiate) {
    df_tidy <-
      df_tidy %>%
      mutate_at(vars(any_of(c("estimate","conf.low","conf.high"))),exp)
  }
  
  df_tidy
}

# build model
mod <- MASS::glm.nb(response ~ age,gtsummary::trial) 

# summarize model results
tbl <- 
  tbl_regression(
    mod,exponentiate = TRUE,tidy_fun = my_negbin_tidy
  ) 

reprex package (v2.0.0) 于 2021 年 4 月 12 日创建

enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...