0

I would like to create a table one of baseline characteristics, stratified by an exposure, that shows SMDs between the exposure groups for every level of the categorical variables. Currently, adding SMDs via add_difference only gives an overall SMD for the variable as shown with Grade below.

library(gtsummary)
#> Warning: package 'gtsummary' was built under R version 4.2.3

tbl <- 
  trial %>%
  select(trt, age, response, grade) %>%
  tbl_summary(by = trt, missing = "no") %>%
  add_difference(everything() ~ "smd")

tbl

table

I cannot figure out how to make them as a custom function within gtsummary. Alternatively, bal.tab() from the cobalt package calculates them by level, but I also can't figure out how to add them to my tbl_summary from that package.

I appreciate any help!

  • The best way to do this is to use dummy variable coding for, in the example above, the grade column. Then you'll get the SMD for each level. – Daniel D. Sjoberg Aug 30 '23 at 02:54

0 Answers0