Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert a list of tbl_regression objects to a single tbl_regression object?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
    )
  )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading