total_indirect_effect: Total Indirect Effect Between Two Variables

View source: R/total_indirect_effect_list.R

total_indirect_effectR Documentation

Total Indirect Effect Between Two Variables

Description

Compute the total indirect effect between two variables in the paths estimated by many_indirect_effects().

Usage

total_indirect_effect(object, x, y)

Arguments

object

The output of many_indirect_effects(), or a list of indirect-class objects.

x

Character. The name of the x variable. All paths starting from x will be included. Can be omitted if all paths have the same x.

y

Character. The name of the y variable. All paths ending at y will be included. Can be omitted if all paths have the same y.

Details

It extracts the indirect-class objects of relevant paths and then add the indirect effects together using the + operator.

Value

An indirect-class object.

See Also

many_indirect_effects()

Examples


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")



manymome documentation built on Oct. 4, 2024, 5:10 p.m.