library(lavaan)
data(data_serial_parallel)
mod <-
"
m11 ~ x + c1 + c2
m12 ~ m11 + x + c1 + c2
m2 ~ x + c1 + c2
y ~ m12 + m2 + m11 + x + c1 + c2
"
fit <- sem(mod, data_serial_parallel,
fixed.x = FALSE)
# All indirect paths, control variables excluded
paths <- all_indirect_paths(fit,
exclude = c("c1", "c2"))
paths
# Indirect effect estimates
out <- many_indirect_effects(paths,
fit = fit)
out
# Total indirect effect from x to y
total_indirect_effect(out,
x = "x",
y = "y")
Run the code above in your browser using DataLab