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
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!