1

我正在使用 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)

我正在尝试遵循并重现此小插图中的示例二 - 请参见此处

4

1 回答 1

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 包(v0.3.0)于 2020 年 10 月 21 日创建

于 2020-10-21T18:57:19.930 回答