I am trying to add significance stars to a gtsummary table that combines multiple models, but I’m getting an error that I don’t know how to resolve.
library(gtsummary)
library(tidyverse)
# Create a list of tbl_regression objects
models <- c("disp", "disp + hp") %>%
map(
~ paste("vs", .x, sep = " ~ ") %>%
as.formula() %>%
glm(data = mtcars,
family = binomial(link = "logit")) %>%
tbl_regression(exponentiate = TRUE))
# Try to add significance stars
models %>%
add_significance_stars(
pattern = "{estimate}{stars}",
thresholds = c(0.001, 0.01, 0.05),
hide_ci = TRUE,
hide_p = TRUE,
hide_se = FALSE
)
#> Error: Error in argument 'x='. Expecting object of class 'tbl_regression', or 'tbl_uvregression'
It seems that the list models is not an object of class tbl_regression, and therefore cannot be passed to add_significance_stars(). How can I fix this problem?
>Solution :
Your models object is a list of gtsummary tables. Hence, as you did when you created the tables you have to use map to loop over the list to add significance stars to each table:
library(gtsummary)
library(tidyverse)
models %>%
map(
~ add_significance_stars(.x,
pattern = "{estimate}{stars}",
thresholds = c(0.001, 0.01, 0.05),
hide_ci = TRUE,
hide_p = TRUE,
hide_se = FALSE
)
)