| lavEffects | R Documentation |
‘lavEffects’ computes various ‘effects’ that are functions of the estimated model parameters of a fitted lavaan object. In this version, the focus is on the classic (LISREL-style) total, indirect and direct effects among the variables that appear in the structural part of the model (that is, the variables that are involved in a regression). Both observed and latent variables are supported.
This avoids the need to pre-specify all indirect (and total) effects manually
in the model syntax (using the := operator), which can be tedious when
there are many of them.
lavEffects(object, effects = c("total", "indirect"),
se_def = NULL, level = 0.95, monte_carlo = NULL,
boot_ci_type = "perc", zstat = TRUE, pvalue = TRUE, ci = TRUE,
standardized = FALSE, cov_std = TRUE,
add_class = TRUE, output = "data.frame", ...)
object |
An object of class |
effects |
Character vector. One or more of |
se_def |
Character (or If |
level |
Numeric. The confidence level for the confidence intervals. |
monte_carlo |
List (or |
boot_ci_type |
Character. Only used when |
zstat |
Logical. If |
pvalue |
Logical. If |
ci |
Logical. If |
standardized |
Logical, character vector, or vector of (observed) variable
names, behaving as in |
cov_std |
Logical. See |
add_class |
Logical. If |
output |
Character. If |
... |
Only old names of arguments - with dots - are allowed here. |
All effects are derived from the reduced-form matrix
(I - B)^{-1}, where B is the matrix of (direct) regression
coefficients among the structural variables (the beta matrix in the
LISREL representation that lavaan uses internally). Writing B[i,j] for the
direct effect of variable j on variable i, we have:
the direct effect of j on i equals B[i,j];
the total effect of j on i equals
\left((I - B)^{-1} - I\right)[i,j];
the indirect effect of j on i equals the total
effect minus the direct effect.
Only effects that are structurally non-zero (that is, for which a directed path
from j to i exists) are reported. For indirect effects, this means
that at least one path of length two or more must exist.
The delta and Monte Carlo methods only require the parameter estimates and the
estimated covariance matrix of the parameters. The delta method produces
(symmetric) normal-theory confidence intervals; the Monte Carlo method produces
percentile-based confidence intervals, which need not be symmetric around the
point estimate. The Monte Carlo method typically behaves better than the delta
method for effects that are products of parameters (such as indirect effects),
in particular in smaller samples. When the model was fitted with
se = "bootstrap", the bootstrap draws are reused to obtain bootstrap
standard errors and bootstrap percentile confidence intervals (this requires
no additional model fitting).
Models fitted with conditional_x = TRUE are also supported: in that
case the structural model is eta = B eta + Gamma x + zeta, where the
exogenous covariates x are stored in the gamma matrix. The effects
of these covariates on the endogenous variables are then computed as
(I - B)^{-1} Gamma (total), Gamma (direct) and
((I - B)^{-1} - I) Gamma (indirect), and reported alongside the effects
among the beta variables.
If output = "data.frame" (the default), a data.frame (of class
lavaan.effects) with the following columns: effect (the type of
effect: total, indirect or direct), lhs (the outcome variable),
op (always "~"), rhs (the predictor variable), and,
depending on the arguments, group/level/block,
est, se, z, pvalue, ci.lower,
ci.upper and (if standardized is requested) one or more of
std.lv, std.all, std.nox and std.user. The effect
in a given row is the effect of rhs on lhs.
If output = "list", a (possibly nested) list of matrices, where element
[i,j] contains the effect of variable j on variable i.
parameterEstimates, standardizedSolution.
# a simple mediation model
set.seed(1234)
X <- rnorm(300)
M <- 0.5 * X + rnorm(300)
Y <- 0.4 * M + 0.3 * X + rnorm(300)
Data <- data.frame(X = X, Y = Y, M = M)
model <- ' # direct effect
Y ~ c*X
# mediator
M ~ a*X
Y ~ b*M
'
fit <- sem(model, data = Data)
# total and indirect effects, with Monte Carlo standard errors
lavEffects(fit)
# all effects, using the delta method
lavEffects(fit, effects = c("total", "indirect", "direct"), se_def = "delta")
# add standardized (total and indirect) effects
lavEffects(fit, se_def = "delta", standardized = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.