Mathematic operators for 'indirect'-class object, the output of indirect_effect() and cond_indirect().

## Usage

# S3 method for indirect
+(e1, e2)

# S3 method for indirect
-(e1, e2)

## Arguments

e1

An 'indirect'-class object.

e2

An 'indirect'-class object.

## Value

An 'indirect'-class object with a list of effects stored. See indirect_effect() on details for this class.

## Details

For now, only + operator and - operator are supported. These operators can be used to estimate and test a function of effects between the same pair of variables but along different paths.

For example, they can be used to compute and test the total effects along different paths. They can also be used to compute and test the difference between the effects along two paths.

The operators will check whether an operation is valid. An operation is not valid if

1. the two paths do not start from the same variable,

2. the two paths do not end at the same variable, (c) a path appears in both objects,

3. moderators are involved but they are not set to the same values in both objects, and

4. bootstrap estimates stored in boot_out, if any, are not identical.

5. Monte Carlo simulated estimates stored in mc_out, if any, are not identical.

indirect_effect() and cond_indirect()

## Examples

library(lavaan)
dat <- modmed_x1m3w4y1
mod <-
"
m1 ~ a1 * x  + d1 * w1 + e1 * x:w1
m2 ~ m1 + a2 * x
y  ~ b1 * m1 + b2 * m2 + cp * x
"
fit <- sem(mod, dat,
meanstructure = TRUE, fixed.x = FALSE,
se = "none", baseline = FALSE)
est <- parameterEstimates(fit)
hi_w1 <- mean(dat$w1) + sd(dat$w1)

# Examples for cond_indirect():

# Conditional effect from x to m1 when w1 is 1 SD above mean
out1 <- cond_indirect(x = "x", y = "y", m = c("m1", "m2"),
wvalues = c(w1 = hi_w1), fit = fit)
out2 <- cond_indirect(x = "x", y = "y", m = c("m2"),
wvalues = c(w1 = hi_w1), fit = fit)
out3 <- cond_indirect(x = "x", y = "y",
wvalues = c(w1 = hi_w1), fit = fit)

out12 <- out1 + out2
out12
#>
#> == Conditional Indirect Effect   ==
#>
#>  Path:                x -> m1 -> m2 -> y
#>  Path:                x -> m2 -> y
#>  Moderators:          w1
#>  Function of Effects: 0.082
#>  When:                w1 = 1.228
#>
#> Computation of the Function of Effects:
#>  (x->m1->m2->y)
#> +(x->m2->y)
#>
out123 <- out1 + out2 + out3
out123
#>
#> == Conditional Indirect Effect   ==
#>
#>  Path:                x -> m1 -> m2 -> y
#>  Path:                x -> m2 -> y
#>  Path:                x -> y
#>  Moderators:          w1
#>  Function of Effects: 0.394
#>  When:                w1 = 1.228
#>
#> Computation of the Function of Effects:
#>  ((x->m1->m2->y)
#> +(x->m2->y))
#> +(x->y)
#>
coef(out1) + coef(out2) + coef(out3)
#>     y~x
#> 0.39405