Skip to contents

Goal

This technical appendix describes how cond_indirect() from the package manymome (Cheung & Cheung, 2024) works internally to extract the parameters and compute a conditional indirect effect.

cond_indirect()

OK
Monte Carlo CI
Bootstrap CI
CI not requested
No
Yes
No
Yes
lavaan
Yes
No
Yes
No
lm
Yes
No
Yes
No
No
Yes
Monte Carlo CI
Bootstrap CI
CI not requested
Failed
Yes
No
Form CI and store in boot_ci
Use mapply on indirect_i
to generate bootstrap estimates
Form CI and store in mc_ci
Use mapply on indirect_i
to generate Monte Carlo estimates
Call m2ptable() to convert
fit to lm_est, a lavaan-like object
est supplied?
Extract est from lm_est
implied_stats supplied?
Extract implied_stats from lm_est
Extract data from lm_est
to set fit_data
est supplied?
Call lavaan::parameterEstimates()
to set est
implied_stats supplied?
Call lav_implied_all()
to set implied_stats
Call lavaan::lavInspect()
to set fit_data
boot_out supplied?
Call do_boot() and
store results in boot_out
mc_out supplied?
Call do_mc() and
store results in mc_out
Start
Call check_path() to check the path
Confidence interval (CI) requested?
fit_type?
prods supplied?
Call indirect_i() with
get_prods_only = TRUE
to set prods
get_prods_only TRUE?
Call indirect_i() to estimate
the (conditional) indirect effect
using fit, wvalues, est, and implied_stats
Confidence interval (CI) requested?
Return the results
Error: No path from x to y
Quit and return prods

Workflow of manymome::cond_indirect()

cond_indirect_effects()

Yes
Monte Carlo CI
Bootstrap CI
CI not requested
No
Yes
No
Yes
Yes
No
No
Call do_boot() and
store results in boot_out
boot_out supplied?
Call do_mc() and
store results in mc_out
mc_out supplied?
Start
wlevels supplied?
Confidence interval (CI) requested?
Call cond_indirect() to get prods,
product term(s) along the path, if any
Call cond_indirect() for each row of wlevels
to compute the conditional indirect effects
output_type == 'data.frame'?
Pack the results in a data frame and
retrun a cond_indirect_effects-class object
Return a list of the outputs of cond_indirect()
Error: wlevels is required.

Workflow of manymome::cond_indirect_effects()

indirect_i()

Main workflow

OK
Failed
Failed
OK
Yes
No
Yes
No
Not NULL
NULL
Either or both TRUE
Both FALSE
Compute the scaling factor(s) for x and/or y
Call lav_implied_all(fit() to
compute the implied statistics
Scale the indirect effect
Compute the change(s) in effect(s) (b_cond)
due to wvalues along the path
Update bs
Set b_cond to NAs
wvalues NULL?
Create the string representation (b_cond_str)
of the computation of effect
Compute the (raw) indirect effect (b_all)
Call get_prod() to
get all product terms
along the path(s), if any.
Update prods by est
Start
If est is NULL,
get est from fit
Call check_path() to check the path
Call get_b() to get
coefficient(s) from x to y (bs)
Error: No path from x to y
Error: Path between
a latent variable and
an observed variable.
prods supplied?
get_prods_only TRUE?
Quit and return prods
standardized_x or standardized_y TRUE?
Pack and return the results as
an indirect-class object

Workflow of manymome::indirect_i()

For Call get_prod(), see the workflow of Creating prods.

prods not supplied

Creating prods

No
No
Yes
No
Yes
Yes
No
Yes
Start
From 'Call get_prod()' in the main workflow
chk_lv all TRUE?
(All variables in the path are latent)
Is data supplied?
Is fit supplied?
Extract data from fit
Is fit supplied?
Use mapply() on get_prod
to find
the product term(s), if any,
using fit and data
Use mapply() on get_prod
to find
the product term(s), if any,
using est and data
Set prods and
return to 'Call get_prod()' in the main workflow
Use mapply() on all paths
to find
the product term(s), if any,
using operator

Workflow of manymome::indirect_i(): Creating prods

Notes

Latent variables

If all variables along a path are latent variables, product term(s) must be identified by their names because raw scores are not available.

Default uses "_x_". For example, f1_x_f2 is the product term between f1 and f2.

Extracting Point Estimates and Variance-Covariance Matrix

When the point estimates or variance-covariance matrix of the point estimates are needed, they will be extracted internally using functions developed for the fit object, which can be a lavaan-class object, a list of the outputs from stats::lm(), or a lavaan.mi-class object generated by fitting a model to several datasets using multiple imputation.

Reference

Cheung, S. F., & Cheung, S.-H. (2024). manymome: An R package for computing the indirect effects, conditional effects, and conditional indirect effects, standardized or unstandardized, and their bootstrap confidence intervals, in many (though not all) models. Behavior Research Methods, 56(5), 4862–4882. https://doi.org/10.3758/s13428-023-02224-z