tidy_smd {tidysmd} | R Documentation |
Tidy Standardized Mean Differences
Description
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
, method
, 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. Additionally, the .wts
argument supports
matched datasets where the variable supplied to .wts
is an binary variable
indicating whether the row was included in the match. If you're using
MatchIt, the helper function bind_matches()
will bind these indicators to
the original dataset, making it easier to compare across matching
specifications.
Usage
tidy_smd(
.df,
.vars,
.group,
.wts = NULL,
include_observed = TRUE,
include_unweighted = NULL,
na.rm = FALSE,
gref = 1L,
std.error = FALSE,
make_dummy_vars = FALSE
)
Arguments
.df |
A data frame |
.vars |
Variables for which to calculate SMD |
.group |
Grouping variable |
.wts |
Variables to use for weighting the SMD calculation. These can be, for instance, propensity score weights or a binary indicator signaling whether or not a participant was included in a matching algorithm. |
include_observed |
Logical. If using |
include_unweighted |
Deprecated. Please use |
na.rm |
Remove |
gref |
an integer indicating which level of |
std.error |
Logical indicator for computing standard errors using
|
make_dummy_vars |
Logical. Transform categorical variables to dummy
variables using |
Value
a tibble
Examples
tidy_smd(nhefs_weights, c(age, education, race), .group = qsmk)
tidy_smd(nhefs_weights, c(age, education), .group = qsmk, std.error = TRUE)
tidy_smd(
nhefs_weights,
c(age, race, education),
.group = qsmk,
.wts = c(w_ate, w_att, w_atm)
)