Indirect and Total Effects
lavEffects.Rd‘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.
Usage
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", ...)Arguments
- object
An object of class
lavaan.- effects
Character vector. One or more of
"total","indirect"and"direct". The default isc("total", "indirect"). The order of the elements does not matter; effects are always reported in the order total, indirect, direct.- se_def
Character (or
NULL). The method used to compute standard errors (and confidence intervals) for the effects. If"monte_carlo", the Monte Carlo method is used: parameters are drawn from a multivariate normal distribution with mean the parameter estimates and covariance matrix the estimated covariance matrix of the parameters, and the effects are recomputed for each draw (percentile confidence intervals). If"delta", the delta method is used (based on a numerical Jacobian of the effects with respect to the free parameters; symmetric normal-theory confidence intervals). If"bootstrap", the bootstrap draws that are stored in the fitted object (when the model was fitted withse = "bootstrap") are used to compute bootstrap standard errors and bootstrap percentile confidence intervals. If"none", no standard errors are computed.If
se_def = NULL(the default), the choice is inherited from the fitted object: if the model was fitted withse = "bootstrap"(and bootstrap draws are available), the bootstrap method is used; else if the model was fitted withse_def = "monte.carlo", the Monte Carlo method is used; otherwise the Monte Carlo method is used as the default. An explicit value always overrides this inheritance.- level
Numeric. The confidence level for the confidence intervals.
- monte_carlo
List (or
NULL). Settings for the Monte Carlo method (only used whense_def = "monte.carlo"), with elementsR(the number of Monte Carlo draws) andseed(the random seed). IfNULL(the default), themonte_carlosettings that were used when the model was fitted are inherited (which themselves default tolist(R = 20000L, seed = NULL)). The state of the global random number generator is saved and restored, so the seed used here does not affect the user's random number stream.- boot_ci_type
Character. Only used when
se_def = "bootstrap". The type of bootstrap confidence interval, as inparameterEstimates:"norm"(normal-theory using the bootstrap bias and standard error),"basic"(basic bootstrap),"perc"(the default; percentile method),"bca.simple"(bias-corrected percentile method, without the acceleration term) or"bca"(the adjusted bootstrap percentile method, with both bias and acceleration correction).- zstat
Logical. If
TRUE, an extra column is added with the \(z\)-statistic for each effect (the ratio of the estimate to its standard error).- pvalue
Logical. If
TRUE, an extra column is added with the (two-sided) p-value, computed using the standard normal distribution.- ci
Logical. If
TRUE(the default), two extra columns (ci.lowerandci.upper) are added with the lower and upper bounds of the confidence interval. IfFALSE, the confidence interval bounds are not shown.- standardized
Logical, character vector, or vector of (observed) variable names, behaving as in
parameterEstimates. IfTRUE, standardized effects are added as extra columns (point estimates only):std.lv(only the latent variables are standardized),std.all(both observed and latent variables are standardized) and, if there are exogenous observed variables andfixed.x = TRUE,std.nox(likestd.all, but the exogenous observed variables are not standardized). A character vector selects specific types (a subset of"std.lv","std.all","std.nox"); a vector of observed variable names standardizes only those observed variables (plus the latent variables), and the result is reported in astd.usercolumn. The standardized effect of \(j\) on \(i\) equals the unstandardized effect times the ratio of the model-implied standard deviations \(sd_j / sd_i\).- cov_std
Logical. See
parameterEstimates. (Has no influence on the standardized regression-type effects reported here.)- add_class
Logical. If
TRUE, the result (whenoutput = "data.frame") is given the classc("lavaan.effects", "lavaan.data.frame", "data.frame"), so that a dedicated print method is used.- output
Character. If
"data.frame"(the default), the result is a (classed) data.frame with one row per effect. If"list", the result is a list of matrices (one per effect type, and one per block in the multilevel/multigroup case), where element \([i,j]\) contains the effect of variable \(j\) on variable \(i\).- ...
Only old names of arguments - with dots - are allowed here.
Details
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.
Value
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\).
Examples
# 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)
#>
#> Effects:
#>
#> Standard errors Monte Carlo
#> Monte Carlo draws 20000
#> Confidence level 0.95
#>
#> Total Effects:
#> Estimate Std.Err z-value P(>|z|) ci_lower ci_upper
#> Y ~ M 0.408 0.053 7.762 0.000 0.305 0.511
#> Y ~ X 0.533 0.059 9.036 0.000 0.417 0.649
#> M ~ X 0.521 0.060 8.749 0.000 0.405 0.638
#>
#> Indirect Effects:
#> Estimate Std.Err z-value P(>|z|) ci_lower ci_upper
#> Y ~ X 0.213 0.037 5.795 0.000 0.146 0.289
#>
# all effects, using the delta method
lavEffects(fit, effects = c("total", "indirect", "direct"), se_def = "delta")
#>
#> Effects:
#>
#> Standard errors Delta
#> Confidence level 0.95
#>
#> Total Effects:
#> Estimate Std.Err z-value P(>|z|) ci_lower ci_upper
#> Y ~ M 0.408 0.053 7.764 0.000 0.305 0.511
#> Y ~ X 0.533 0.059 9.001 0.000 0.417 0.649
#> M ~ X 0.521 0.059 8.772 0.000 0.404 0.637
#>
#> Indirect Effects:
#> Estimate Std.Err z-value P(>|z|) ci_lower ci_upper
#> Y ~ X 0.213 0.037 5.814 0.000 0.141 0.284
#>
#> Direct Effects:
#> Estimate Std.Err z-value P(>|z|) ci_lower ci_upper
#> Y ~ M 0.408 0.053 7.764 0.000 0.305 0.511
#> Y ~ X 0.321 0.061 5.291 0.000 0.202 0.440
#> M ~ X 0.521 0.059 8.772 0.000 0.404 0.637
#>
# add standardized (total and indirect) effects
lavEffects(fit, se_def = "delta", standardized = TRUE)
#>
#> Effects:
#>
#> Standard errors Delta
#> Confidence level 0.95
#>
#> Total Effects:
#> Estimate Std.Err z-value P(>|z|) ci_lower ci_upper std.lv
#> Y ~ M 0.408 0.053 7.764 0.000 0.305 0.511 0.408
#> Y ~ X 0.533 0.059 9.001 0.000 0.417 0.649 0.533
#> M ~ X 0.521 0.059 8.772 0.000 0.404 0.637 0.521
#> std.all std.nox
#> Y ~ M 0.407 0.407
#> Y ~ X 0.461 0.460
#> M ~ X 0.452 0.451
#>
#> Indirect Effects:
#> Estimate Std.Err z-value P(>|z|) ci_lower ci_upper std.lv
#> Y ~ X 0.213 0.037 5.814 0.000 0.141 0.284 0.213
#> std.all std.nox
#> Y ~ X 0.184 0.183
#>