SMD for categorical variable using tbl_summary

1.1k views Asked by At

The gtsummary::tbl_summary functionality is wonderful and I am looking for a way to add SMD for categorical variables. The tableone function provided smd for all types of covariates including character. I tried adding SMD to tbl_summary by add_stat with effsize::cohen.d or effsize::cohen.d. but both worked for numeric covariates and not for character. Any guidance is appreciated. Thanks

1

There are 1 answers

1
Daniel D. Sjoberg On

Use the add_difference() function with method "smd" to get the standardized mean differences. Review this page for a list of all available methods https://www.danieldsjoberg.com/gtsummary/reference/tests.html

library(gtsummary)
#> #Uighur
packageVersion("gtsummary")
#> [1] '1.5.2'

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

enter image description here Created on 2022-03-03 by the reprex package (v2.0.1)