我正在使用 gtsummary 包来列出我的回归结果。
困难的是,我尝试使用以下函数为我的表提供一个跨越标题modify_spanning_header(starts_with("stat_") ~ "**美国各州多年来的逻辑回归**")
.
当我将此函数与下面的代码一起使用时,我得到以下响应:
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 .
最佳答案
您遇到的问题是您选择了以“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于2020年10月21日创建(v0.3.0)
关于r - gtsummary 回归表的生成 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64469429/