gsummary 中的 Wald 置信区间
Wald confidence interval in gtsummary
有没有办法在gtsummary中指定计算置信区间的方法。我问这个是因为 confint
函数与配置文件置信区间存在一些不一致。
查看下面 var1 和 var2 的 pvalues 和 CI:
library(tidyverse)
library(gtsummary)
set.seed(2021)
testdata <- tibble(
var1 = rbinom(1114, 1, 0.12),
var2 = rbinom(1114, 1, 0.82),
var3 = rbinom(1114, 1, 0.60),
var4 = rbinom(1114, 1, 0.18),
var5 = rbinom(1114, 1, 0.12),
var6 = rbinom(1114, 1, 0.05),
var7 = rbinom(1114, 1, 0.63),
var8 = rbinom(1114, 1, 0.20),
var9 = rbinom(1114, 1, 0.06),
var10 = rbinom(1114, 1, 0.40),
var11 = rbinom(1114, 1, 0.35),
var12 = rbinom(1114, 1, 0.32),
outcome = rbinom(1114, 1, 0.04)
) %>%
mutate(across(.cols = everything(),
~factor(., levels = c(0, 1),
labels = c("No", "Yes"))))
mvariate.regress <- function(outcome, covariates, mydata) {
form <- paste(outcome, "~",
paste(covariates, collapse = " + "))
model1 <- glm(as.formula(form),
data = mydata, family = binomial)
model1
}
ipvars <- paste0("var", 1:12)
mlogitfit <- mvariate.regress("outcome", ipvars, testdata)
mlogitfit %>%
tbl_regression(
exponentiate = TRUE
) %>%
bold_p() %>%
bold_p(t = 0.05) %>%
bold_labels() %>%
modify_header(label = "**Variable**",
estimate = "**adjusted OR**") %>%
modify_table_styling(
columns = c("ci", "estimate"),
rows = reference_row %in% TRUE,
missing_symbol = "Ref"
)
如果我使用 confint.default
函数
,我会得到想要的结果
gtstummary
软件包网站对此有解决方案。寻找“Wald 置信区间”here 或查看下面的 my_tidy
函数。您可以单独计算 Wald 置信区间并将其绑定到 table.
my_tidy <- function(x, exponentiate = TRUE, conf.level = 0.95, ...) {
dplyr::bind_cols(
broom::tidy(x, exponentiate = exponentiate, conf.int = FALSE),
# calculate the confidence intervals, and save them in a tibble
stats::confint.default(x) %>%
tibble::as_tibble() %>%
rlang::set_names(c("conf.low", "conf.high")) )
}
mlogitfit %>%
tbl_regression(tidy_fun = my_tidy) %>%
bold_p() %>%
bold_p(t = 0.05) %>%
bold_labels() %>%
modify_header(label = "**Variable**",
estimate = "**adjusted OR**") %>%
modify_table_styling(
columns = c("ci", "estimate"),
rows = reference_row %in% TRUE,
missing_symbol = "Ref"
)
有没有办法在gtsummary中指定计算置信区间的方法。我问这个是因为 confint
函数与配置文件置信区间存在一些不一致。
查看下面 var1 和 var2 的 pvalues 和 CI:
library(tidyverse)
library(gtsummary)
set.seed(2021)
testdata <- tibble(
var1 = rbinom(1114, 1, 0.12),
var2 = rbinom(1114, 1, 0.82),
var3 = rbinom(1114, 1, 0.60),
var4 = rbinom(1114, 1, 0.18),
var5 = rbinom(1114, 1, 0.12),
var6 = rbinom(1114, 1, 0.05),
var7 = rbinom(1114, 1, 0.63),
var8 = rbinom(1114, 1, 0.20),
var9 = rbinom(1114, 1, 0.06),
var10 = rbinom(1114, 1, 0.40),
var11 = rbinom(1114, 1, 0.35),
var12 = rbinom(1114, 1, 0.32),
outcome = rbinom(1114, 1, 0.04)
) %>%
mutate(across(.cols = everything(),
~factor(., levels = c(0, 1),
labels = c("No", "Yes"))))
mvariate.regress <- function(outcome, covariates, mydata) {
form <- paste(outcome, "~",
paste(covariates, collapse = " + "))
model1 <- glm(as.formula(form),
data = mydata, family = binomial)
model1
}
ipvars <- paste0("var", 1:12)
mlogitfit <- mvariate.regress("outcome", ipvars, testdata)
mlogitfit %>%
tbl_regression(
exponentiate = TRUE
) %>%
bold_p() %>%
bold_p(t = 0.05) %>%
bold_labels() %>%
modify_header(label = "**Variable**",
estimate = "**adjusted OR**") %>%
modify_table_styling(
columns = c("ci", "estimate"),
rows = reference_row %in% TRUE,
missing_symbol = "Ref"
)
如果我使用 confint.default
函数
gtstummary
软件包网站对此有解决方案。寻找“Wald 置信区间”here 或查看下面的 my_tidy
函数。您可以单独计算 Wald 置信区间并将其绑定到 table.
my_tidy <- function(x, exponentiate = TRUE, conf.level = 0.95, ...) {
dplyr::bind_cols(
broom::tidy(x, exponentiate = exponentiate, conf.int = FALSE),
# calculate the confidence intervals, and save them in a tibble
stats::confint.default(x) %>%
tibble::as_tibble() %>%
rlang::set_names(c("conf.low", "conf.high")) )
}
mlogitfit %>%
tbl_regression(tidy_fun = my_tidy) %>%
bold_p() %>%
bold_p(t = 0.05) %>%
bold_labels() %>%
modify_header(label = "**Variable**",
estimate = "**adjusted OR**") %>%
modify_table_styling(
columns = c("ci", "estimate"),
rows = reference_row %in% TRUE,
missing_symbol = "Ref"
)