如何解决使用 R 中的 tbl_regression 函数在一列中使用 95% CI 的回归系数?
为了测试疾病组(categorical_variable)和疾病(结果;二分法)之间是否存在关联,我正在运行逻辑回归。为了检查其他变量的混淆,我运行了 3 个具有不同协变量数量的模型。
为了显示 OR 和 CI,我使用了 tbl_regression function
包中的 gtsummary
(我使用了 dplyr 函数 mutate
在圆括号中显示 CI)。但是,这将 CI 显示在与 OR 不同的列中,但我希望它们与 OR 后的圆括号中的 CI 位于同一列中。
我的代码:
library(gtsummary)
library(dplyr)
Model 1 <-
glm(data=wide_dataset,formula=outcome ~ categorical_variable,family=binomial(link="logit") %>%
tbl_regression(
exponentiate = TRUE) %>%
# remove the p-value column
modify_column_hide(column=p.value) %>%
# CI in round brackets:
modify_table_body(mutate,ci=gsub("(\\d\\.\\d{,4})(,)(\\d\\.\\d{,4})","\\(\\1 \\3\\)",ci))
Model 1
提前致谢!
解决方法
使用开发版软件包(将于下周发布到 CRAN)将优势比和 CI 放在同一列中要容易得多。
如果使用 JAMA 期刊主题,OR 和 CI 将自动合并为一列。
remotes::install_github("ddsjoberg/gtsummary")
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.3.7.9016'
# set the JAMA theme to display OR and CI in same column
theme_gtsummary_journal("jama")
#> Setting theme `JAMA`
tbl <-
glm(response ~ age + grade,data = trial,family = binomial) %>%
tbl_regression(exponentiate = TRUE) %>%
modify_column_hide(p.value)
由 reprex package (v2.0.0) 于 2021 年 4 月 7 日创建
此代码也可以在不设置 JAMA 期刊主题的情况下使用。
tbl <-
glm(response ~ age + grade,family = binomial) %>%
tbl_regression(exponentiate = TRUE) %>%
# merge OR and CI into single column
modify_table_styling(
column = estimate,rows = !is.na(estimate),cols_merge_pattern = "{estimate} ({conf.low} to {conf.high})"
) %>%
modify_header(estimate ~ "**OR (95% CI)**") %>%
modify_column_hide(c(ci,p.value))
听起来您想比较多个模型。以下是将它们放在同一个表中的方法。
list(tbl,tbl,tbl) %>%
tbl_merge(tab_spanner = paste0("**Model ",1:3,"**"))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。