2

我试图弄清楚如何在使用 gtsummary 时添加自定义选项——例如,为 pvalues、标题等添加星号。

这是一个使用基本 mtcars 数据的可重现示例,以防更有效......

library(tidyverse)
library(gtsummary)
#> Warning: package 'gtsummary' was built under R version 4.0.3
#> #Uighur

r1 <- lm(mpg ~ wt + cyl, data = mtcars) %>% 
  tbl_regression(exponentiate = TRUE)

r2 <- lm(hp ~ wt + cyl, data = mtcars) %>% 
  tbl_regression(exponentiate = TRUE)

r3 <- lm(qsec ~ wt + cyl, data = mtcars) %>% 
  tbl_regression(exponentiate = TRUE)


tbl_merge(list(r1, r2, r3), 
          tab_spanner = c("**MPG**", "**Horsepower**", "**Seconds**"))
4

1 回答 1

2

您可以使用该add_significance_stars()功能为您的估算值添加星标。要添加标题和其他格式,请使用函数将 gtsummary 对象转换为 gtas_gt()并使用 gt 函数添加它们。

下面的例子。

library(gtsummary)
library(tidyverse)
packageVersion("gtsummary")
#> [1] '1.4.0'

# create a tibble with one row per model
tbl <-
  tibble(outcome = c("mpg", "hp", "qsec")) %>%
  rowwise() %>%
  mutate(
    tbl = 
      lm(str_glue("{outcome} ~ wt + cyl"), data = mtcars) %>%
      tbl_regression() %>%
      add_significance_stars(
        hide_se = TRUE,
        hide_ci = FALSE
      ) %>%
      list()
  ) %>%
  # pull tbl_regression() objects into single merged table
  pull(tbl) %>%
  tbl_merge(tab_spanner = c("**MPG**", "**Horsepower**", "**Seconds**")) %>%
  # add table captions
  as_gt() %>%
  gt::tab_header(title = "Table 1. Car Regression Model",
                 subtitle = "Highly Confidential")

强文本 reprex 包于 2021-04-15 创建 (v2.0.0 )

于 2020-10-26T01:53:00.370 回答