如何从列表列表中获取多个回归模型到 gtsummary table?
How to get multiple regression models from a list of lists to a gtsummary table?
鉴于以下情况,如何将 out
中的两个模型转换为 gtsummary
table?
library(dplyr)
library(purrr)
m.1.1 <- "cyl"
m.1.2 <- paste(c(m.1.1, "disp"), collapse = " + ")
out <- map(dplyr::lst(m.1.1, m.1.2),
~ lm(data = mtcars, formula = as.formula(paste0("mpg ~ ", .x))))
我想我想使用 tbl_regression
和 tbl_merge
,但是——我的代码基于 的答案——我无法让它工作。
你是对的,你可以用tbl_regression()
和tbl_merge()
来准备table。示例如下!
library(gtsummary)
library(tidyverse)
tbl <-
c("cyl", "cyl + disp") %>% # vector of covariates
map(
~ paste("mpg", .x, sep = " ~ ") %>% # build character formula
as.formula() %>% # convert to proper formula
lm(data = mtcars) %>% # build linear regression model
tbl_regression() # display table with gtsummary
) %>%
# merge tables into single table
tbl_merge(
tab_spanner = c("**Univariate**", "**Multivariable**")
)
由 reprex package (v2.0.1)
创建于 2021-10-11
鉴于以下情况,如何将 out
中的两个模型转换为 gtsummary
table?
library(dplyr)
library(purrr)
m.1.1 <- "cyl"
m.1.2 <- paste(c(m.1.1, "disp"), collapse = " + ")
out <- map(dplyr::lst(m.1.1, m.1.2),
~ lm(data = mtcars, formula = as.formula(paste0("mpg ~ ", .x))))
我想我想使用 tbl_regression
和 tbl_merge
,但是——我的代码基于
你是对的,你可以用tbl_regression()
和tbl_merge()
来准备table。示例如下!
library(gtsummary)
library(tidyverse)
tbl <-
c("cyl", "cyl + disp") %>% # vector of covariates
map(
~ paste("mpg", .x, sep = " ~ ") %>% # build character formula
as.formula() %>% # convert to proper formula
lm(data = mtcars) %>% # build linear regression model
tbl_regression() # display table with gtsummary
) %>%
# merge tables into single table
tbl_merge(
tab_spanner = c("**Univariate**", "**Multivariable**")
)