使用 R 中的 tbl_regression 函数在一列中具有 95%CI 的回归系数?
Regression coefficient with 95%CI in one column using tbl_regression function in R?
为了测试疾病组(categorical_variable)和疾病(结果;二分法)之间是否存在关联,我是运行逻辑回归。为了检查其他变量的混淆,我是 运行 3 个具有不同数量协变量的模型。
为了显示 OR 和 CIs,我正在使用包 gtsummary
中的 tbl_regression function
(并且我使用 dplyr 函数 mutate
来显示 CIs 在圆括号中)。但是,这会在 OR 的单独列中显示 CI,但我希望它们与 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-04-07 创建
此代码也可以在不设置 JAMA 期刊主题的情况下使用。
tbl <-
glm(response ~ age + grade, data = trial, 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))
听起来您想比较多个模型。这是将它们放在同一个 table.
中的方法
list(tbl, tbl, tbl) %>%
tbl_merge(tab_spanner = paste0("**Model ", 1:3, "**"))
为了测试疾病组(categorical_variable)和疾病(结果;二分法)之间是否存在关联,我是运行逻辑回归。为了检查其他变量的混淆,我是 运行 3 个具有不同数量协变量的模型。
为了显示 OR 和 CIs,我正在使用包 gtsummary
中的 tbl_regression function
(并且我使用 dplyr 函数 mutate
来显示 CIs 在圆括号中)。但是,这会在 OR 的单独列中显示 CI,但我希望它们与 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)
此代码也可以在不设置 JAMA 期刊主题的情况下使用。
tbl <-
glm(response ~ age + grade, data = trial, 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))
听起来您想比较多个模型。这是将它们放在同一个 table.
中的方法list(tbl, tbl, tbl) %>%
tbl_merge(tab_spanner = paste0("**Model ", 1:3, "**"))