| indirect_i | R Documentation |
It computes an indirect effect, optionally conditional on the value(s) of moderator(s) if present.
indirect_i(
x,
y,
m = NULL,
fit = NULL,
est = NULL,
implied_stats = NULL,
wvalues = NULL,
standardized_x = FALSE,
standardized_y = FALSE,
computation_digits = 5,
prods = NULL,
get_prods_only = FALSE,
data = NULL,
expand = TRUE,
warn = TRUE,
allow_mixing_lav_and_obs = TRUE,
group = NULL,
est_vcov = NULL,
df_residual = NULL,
skip_indicators = TRUE
)
x |
Character. The name of the predictor at the start of the path. |
y |
Character. The name of the outcome variable at the end of the path. |
m |
A vector of the variable
names of the mediator(s). The path
goes from the first mediator
successively to the last mediator. If
|
fit |
The fit object. Currently
only supports lavaan::lavaan
objects. Support for lists of |
est |
The output of
|
implied_stats |
Implied means,
variances, and covariances of
observed variables and latent
variables (if any), of the form of
the output of |
wvalues |
A numeric vector of
named elements. The names are the
variable names of the moderators, and
the values are the values to which
the moderators will be set to.
Default is |
standardized_x |
Logical.
Whether |
standardized_y |
Logical.
Whether |
computation_digits |
The number of digits in storing the computation in text. Default is 3. |
prods |
The product terms found. For internal use. |
get_prods_only |
IF |
data |
Data frame (optional). If supplied, it will be used to identify the product terms. For internal use. |
expand |
Whether products of
more than two terms will be searched.
|
warn |
If |
allow_mixing_lav_and_obs |
If
|
group |
Either the group number
as appeared in the |
est_vcov |
A list of
variance-covariance matrix of
estimates, one for each response
variable ( |
df_residual |
A numeric
vector of the residual degrees of
freedom for the model of each
response variable ( |
skip_indicators |
Whether
observed indicators are skipped from
the search for product terms. Default
is |
This function is a low-level
function called by
indirect_effect(),
cond_indirect_effects(), and
cond_indirect(), which call this
function multiple times if a bootstrap
confidence interval is requested.
This function usually should not be used directly. It is exported for advanced users and developers
It returns an
indirect-class object. This class
has the following methods:
coef.indirect(),
print.indirect(). The
confint.indirect() method is used
only when called by cond_indirect()
or cond_indirect_effects().
indirect_effect(),
cond_indirect_effects(), and
cond_indirect(), the high level
functions that should usually be
used.
library(lavaan)
dat <- modmed_x1m3w4y1
mod <-
"
m1 ~ a1 * x + b1 * w1 + d1 * x:w1
m2 ~ a2 * m1 + b2 * w2 + d2 * m1:w2
m3 ~ a3 * m2 + b3 * w3 + d3 * m2:w3
y ~ a4 * m3 + b4 * w4 + d4 * m3:w4
"
fit <- sem(mod, dat, meanstructure = TRUE,
fixed.x = FALSE, se = "none", baseline = FALSE)
est <- parameterEstimates(fit)
wvalues <- c(w1 = 5, w2 = 4, w3 = 2, w4 = 3)
# Compute the conditional indirect effect by indirect_i()
indirect_1 <- indirect_i(x = "x", y = "y", m = c("m1", "m2", "m3"), fit = fit,
wvalues = wvalues)
# Manually compute the conditional indirect effect
indirect_2 <- (est[est$label == "a1", "est"] +
wvalues["w1"] * est[est$label == "d1", "est"]) *
(est[est$label == "a2", "est"] +
wvalues["w2"] * est[est$label == "d2", "est"]) *
(est[est$label == "a3", "est"] +
wvalues["w3"] * est[est$label == "d3", "est"]) *
(est[est$label == "a4", "est"] +
wvalues["w4"] * est[est$label == "d4", "est"])
# They should be the same
coef(indirect_1)
indirect_2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.