how to summarise wto multiple logistic regression models in a forest plot

Viewed 37

I want to output the results of the wonderful gtsummary package for tbl_uvregression by groups with the function "as.forest_plot" https://www.danieldsjoberg.com/bstfun/reference/as_forest_plot.html. The previous example "https://stackoverflow.com/questions/60958953/how-to-summarise-multiple-logistic-regression-models-in-a-table/60959878#60959878" works perfect and i followed their example. However, is it possible to output two groups as a forest plot?

forrest<- as_forest_plot(
  df_uv,
  col_names = c("estimate","p.value"),
   graph.pos = 2,
   boxsize = 0.3,
   title_line_color = "darkblue",
   col = forestplot::fpColors(box = "darkred",lines="black", zero = "gray50"),
   shapes_gp = forestplot::fpShapesGp(default = gpar(lineend = "square", linejoin = "mitre", lwd = 2, col = "black")),
   box = gpar(fill = "darkred", col = "black"), # only one parameter
   txt_gp = fpTxtGp(ticks=gpar(cex=0.9),xlab=gpar(cex=1.2,vjust=3.5)),
   zero=1, cex=0.9, lineheight = "auto", colgap=unit(6,"mm"),
   lwd.ci=1, ci.vertices=TRUE, ci.vertices.height = 0.4)

This gives me the "Error: x= must be class 'tbl_regression' or 'tbl_uvregression'"

Thank you very much

1 Answers

I'm unfamiliar with this package but the error at least is clear: the function is expecting a tbl_uvregression and the code you are using is putting this object in the column tbl_uv of your data.frame. This code displays one graph. I hope it helps...

library(gtsummary)
library(tidyverse)
library(bstfun)
library(forestplot)

trial_subset <-
  trial %>%
  select(trt, response, age, marker, grade) 

df_uv <-
  trial_subset %>%
  # group by trt, and nest data within group
  group_by(trt) %>%
  nest() %>%
  # build univariate logistic regression models separately within grouping variable
  mutate(
    tbl_uv = map(
      data,
      ~tbl_uvregression(
        data = .x, 
        y = response,
        method = glm, 
        method.args = list(family = binomial),
        exponentiate = TRUE
      )
    )
  )


class(df_uv$tbl_uv[[1]])

forrest <- as_forest_plot(
  df_uv$tbl_uv[[1]],
  col_names = c("estimate","p.value"),
  graph.pos = 2,
  boxsize = 0.3,
  title_line_color = "darkblue",
  col = forestplot::fpColors(box = "darkred",lines="black", zero = "gray50"),
  shapes_gp = forestplot::fpShapesGp(default = gpar(lineend = "square", linejoin = "mitre", lwd = 2, col = "black")),
  box = gpar(fill = "darkred", col = "black"), # only one parameter
  txt_gp = fpTxtGp(ticks=gpar(cex=0.9),xlab=gpar(cex=1.2,vjust=3.5)),
  zero=1, cex=0.9, lineheight = "auto", colgap=unit(6,"mm"),
  lwd.ci=1, ci.vertices=TRUE, ci.vertices.height = 0.4)

forest graph

Related