This function generates the lavaan syntax for a moderated mediation model
with optional moderators on the a (x -> m), b (m -> y), and c
(x -> y) paths. Optionally, covariates can be added, with effects partialled
out from endogeneous (m, y) and exogenous (x, moderators) variables.
Usage
get_moderated_mediation_model(
x,
m,
y,
mod_a = NULL,
mod_b = NULL,
mod_c = NULL,
values_at = NULL,
cov = NULL,
adjust_exogenous = TRUE
)Arguments
- x, m, y
(character) variable name(s)
- mod_a, mod_b, mod_c
(character) variable name(s) for moderators of a (
x -> m), b (m -> y), and c (x -> y) paths (defaultNULL)- values_at
list of numeric vectors with values at which to evaluate the conditional effects; names correspond to
mod_a,mod_b, andmod_c(defaultNULL)- cov
(character) variable name(s) of control variables (default
NULL)- adjust_exogenous
(logical) adjust exogenous variables (
x, mods) for the effect of covariates incov? (defaultTRUE)
Details
This function is a more flexible alternative to the PROCESS macro (Hayes, 2022),
which does not require manual specification of a model number. Also, because
the model is estimated in the structural equation modeling framework, both
normal-theory p-values and bootstrap intervals are available for indirect effects,
and additional parameters can be computed using the := operator in lavaan.
If no moderators are specified, the model corresponds to the mediation model
provided in get_mediation_model().
If only one of the a and b paths is moderated, then indexes of moderated
mediation are computed (labelled with the i_ prefix in the output). If both
the a and b paths are moderated, indexes of moderated mediation are not
provided (similar to the PROCESS macro; see Hayes, 2022).
Currently, the number of x, m, y, and a-b-c moderator variables is limited to 9 each. This is not a statistical limitation, but instead due to how the function is written.