gtsummary 回归 table 的跨越 header
Spanning header for gtsummary regression table
我正在使用 gtsummary 包来列出我的回归结果。
我很困难地尝试使用以下函数 modify_spanning_header(starts_with("stat_") ~ "**Logistic regression for years in US states**")
.
为我的 table 提供一个跨度 header
当我将此函数与下面的代码一起使用时,我得到以下响应:
Error: Can't join on `x$column` x `y$column` because of incompatible types.
ℹ `x$column` is of type <character>>.
ℹ `y$column` is of type <integer>>.
知道这是什么吗?包含虚拟数据和包的完整代码如下:
# load packages
library(gtsummary)
# dummy data
crime <-data.frame(State = sample(c("SF", "AR", "NYC","MN"),13000,replace = TRUE),
Year = sample(as.factor(c(1990, 2000)),13000, replace = TRUE)
)
# logistic model with visual
glm(Year ~ State, data = crime, family = binomial) %>%
tbl_regression(exponentiate = TRUE)
我正在尝试遵循并重现此小插图中的示例二 - 请参阅 here。
您遇到的这个问题是您 select 处理所有以 "stat_"
开头的列。但是在 tbl_regression()
table 中,没有以 "stat_"
开头的列。使用辅助函数 show_header_names()
打印当前列名称及其 headers。这将帮助您找到 select 相应的列。示例如下。
# load packages
library(gtsummary)
# dummy data
crime <-data.frame(State = sample(c("SF", "AR", "NYC","MN"),13000,replace = TRUE),
Year = sample(as.factor(c(1990, 2000)),13000, replace = TRUE)
)
# logistic model with visual
tbl <-
glm(Year ~ State, data = crime, family = binomial) %>%
tbl_regression(exponentiate = TRUE)
show_header_names(tbl)
#>
#>
#> Column Name Column Header
#> ------------ -------------------
#> label **Characteristic**
#> estimate **OR**
#> ci **95% CI**
#> p.value **p-value**
#> i As a usage guide, the code below re-creates the current column headers.
#> modify_header(update = list(
#> label ~ "**Characteristic**",
#> estimate ~ "**OR**",
#> ci ~ "**95% CI**",
#> p.value ~ "**p-value**"
#> ))
# adding header here
tbl %>%
modify_spanning_header(
c(estimate, ci, p.value) ~
"**Logistic regression for years in US states**")
由 reprex package (v0.3.0)
于 2020-10-21 创建
我正在使用 gtsummary 包来列出我的回归结果。
我很困难地尝试使用以下函数 modify_spanning_header(starts_with("stat_") ~ "**Logistic regression for years in US states**")
.
当我将此函数与下面的代码一起使用时,我得到以下响应:
Error: Can't join on `x$column` x `y$column` because of incompatible types.
ℹ `x$column` is of type <character>>.
ℹ `y$column` is of type <integer>>.
知道这是什么吗?包含虚拟数据和包的完整代码如下:
# load packages
library(gtsummary)
# dummy data
crime <-data.frame(State = sample(c("SF", "AR", "NYC","MN"),13000,replace = TRUE),
Year = sample(as.factor(c(1990, 2000)),13000, replace = TRUE)
)
# logistic model with visual
glm(Year ~ State, data = crime, family = binomial) %>%
tbl_regression(exponentiate = TRUE)
我正在尝试遵循并重现此小插图中的示例二 - 请参阅 here。
您遇到的这个问题是您 select 处理所有以 "stat_"
开头的列。但是在 tbl_regression()
table 中,没有以 "stat_"
开头的列。使用辅助函数 show_header_names()
打印当前列名称及其 headers。这将帮助您找到 select 相应的列。示例如下。
# load packages
library(gtsummary)
# dummy data
crime <-data.frame(State = sample(c("SF", "AR", "NYC","MN"),13000,replace = TRUE),
Year = sample(as.factor(c(1990, 2000)),13000, replace = TRUE)
)
# logistic model with visual
tbl <-
glm(Year ~ State, data = crime, family = binomial) %>%
tbl_regression(exponentiate = TRUE)
show_header_names(tbl)
#>
#>
#> Column Name Column Header
#> ------------ -------------------
#> label **Characteristic**
#> estimate **OR**
#> ci **95% CI**
#> p.value **p-value**
#> i As a usage guide, the code below re-creates the current column headers.
#> modify_header(update = list(
#> label ~ "**Characteristic**",
#> estimate ~ "**OR**",
#> ci ~ "**95% CI**",
#> p.value ~ "**p-value**"
#> ))
# adding header here
tbl %>%
modify_spanning_header(
c(estimate, ci, p.value) ~
"**Logistic regression for years in US states**")
由 reprex package (v0.3.0)
于 2020-10-21 创建