tidy_smd()
calculates the standardized mean difference (SMD) for variables
in a dataset between groups. Optionally, you may also calculate weighted
SMDs. tidy_smd()
wraps smd::smd()
, returning a tidy dataframe with the
columns variable
, weights
, and smd
, as well as fourth column the
contains the level of .group
the SMD represents. You may also supply
multiple weights to calculate multiple weighted SMDs, useful when comparing
different types of weights.
tidy_smd( .df, .vars, .group, .wts = NULL, include_unweighted = TRUE, na.rm = FALSE, gref = 1L, std.error = FALSE )
.df | A data frame |
---|---|
.vars | Variables for which to calculate SMD |
.group | Grouping variable |
.wts | Variables to use for weighting the SMD calculation |
include_unweighted | Logical. If using |
na.rm | Remove |
gref | an integer indicating which level of |
std.error | Logical indicator for computing standard errors using
|
a tibble
#> # A tibble: 3 × 4 #> variable weights qsmk smd #> <chr> <chr> <chr> <dbl> #> 1 age unweighted 1 -0.282 #> 2 education unweighted 1 0.196 #> 3 race unweighted 1 0.177#> # A tibble: 2 × 5 #> variable weights qsmk smd std.error #> <chr> <chr> <chr> <dbl> <dbl> #> 1 age unweighted 1 -0.282 0.0580 #> 2 education unweighted 1 0.196 0.0579#> # A tibble: 12 × 4 #> variable weights qsmk smd #> <chr> <chr> <chr> <dbl> #> 1 age unweighted 1 -0.282 #> 2 race unweighted 1 0.177 #> 3 education unweighted 1 0.196 #> 4 age w_ate 1 -0.00585 #> 5 race w_ate 1 0.00664 #> 6 education w_ate 1 0.0347 #> 7 age w_att 1 -0.0120 #> 8 race w_att 1 0.00365 #> 9 education w_att 1 0.0267 #> 10 age w_atm 1 -0.00184 #> 11 race w_atm 1 0.00113 #> 12 education w_atm 1 0.00934