我正在使用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。
答案 0 :(得分:1)
您遇到的此问题是您选择了所有以"stat_"
开头的列。但是在tbl_regression()
表中,没有以"stat_"
开头的列。使用辅助函数show_header_names()
可以打印当前列名及其标题。这将有助于指导您选择适当的列。下面的示例。
# 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创建