`R/compute_indirect_effect_for.R`

`compute_indirect_effect_for.Rd`

When computing a moderated mediation, one assesses whether an indirect
effect changes according a moderator value (Muller et al., 2005).
`mdt_moderated`

makes it easy to assess moderated mediation, but it does
not allow accessing the indirect effect for a specific moderator values.
`compute_indirect_effect_for`

fills this gap.

```
compute_indirect_effect_for(
mediation_model,
Mod = 0,
times = 5000,
level = 0.05
)
```

- mediation_model
A moderated mediation model fitted with

`mdt_moderated`

.- Mod
The moderator value for which to compute the indirect effect. Must be a numeric value, defaults to

`0`

.- times
Number of simulations to use to compute the Monte Carlo indirect effect confidence interval. Must be numeric, defaults to

`5000`

.- level
Alpha threshold to use for the indirect effect's confidence interval. Defaults to

`.05`

.

The approach used by `compute_indirect_effect_for`

is similar to the
approach used for simple slope analyses. Specifically, it will fit a new
moderated mediation model, but with a data set with a different variable
coding. Behind the scenes, `compute_indirect_effect_for`

adjusts the
moderator variable coding, so that the value we want to compute the
indirect effect for is now `0`

.

Once done, a new moderated mediation model is applied using the new data set. Because of the new coding, and because of how one interprets coefficients in a linear regression, \(a \times b\) is now the indirect effect we wanted to compute (see the Models section).

Thanks to the returned values of \(a\) and bb (\(b_51\)
and \(b_64\), see the Models section), it is now easy to compute
\(a \times b\). `compute_indirect_effect_for`

uses the same
approach than the `add_index`

function. A Monte Carlo simulation is used
to compute the indirect effect index (MacKinnon et al., 2004).

In a moderated mediation model, three models are used.
`compute_indirect_effect_for`

uses the same model specification as
`mdt_moderated`

:

\(Y_i = b_{40} + \mathbf{b_{41}} X_i + b_{42} Mo_i + \mathbf{b_{43}} XMo_i \)

\(M_i = b_{50} + \mathbf{b_{51}} X_i + b_{52} Mo_i + \mathbf{b_{53} XMo_i}\)

\(Y_i = b_{60} + \mathbf{c'_{61}} X_i + b_{62} Mo_i + \mathbf{b_{63} Xmo_i} + \mathbf{b_{64} Me_i} + \mathbf{b_{65} MeMo_i}\)

with \(Y_i\), the outcome value for the *i*th observation,
\(X_i\), the predictor value for the *i*th observation,
\(Mo_i\), the moderator value for the *i*th observation, and
\(M_i\), the mediator value for the *i*th observation.

Coefficients associated with \(a\), \(a \times Mod\), \(b\), \(b \times Mod\), \(c\), \(c \times Mod\), \(c'\), and \(c' \times Mod\), paths are respectively \(b_{51}\), \(b_{53}\), \(b_{64}\), \(b_{65}\), \(b_{41}\), \(b_{43}\), \(b_{61}\), and \(b_{63}\) (see Muller et al., 2005).

MacKinnon, D. P., Lockwood, C. M., & Williams, J. (2004). Confidence Limits
for the Indirect Effect: Distribution of the Product and Resampling
Methods. *Multivariate Behavioral Research*, *39*(1), 99-128. doi:
10.1207/s15327906mbr3901_4

Muller, D., Judd, C. M., & Yzerbyt, V. Y. (2005). When moderation
is mediated and mediation is moderated. *Journal of Personality and
Social Psychology*, *89*(6), 852-863. doi: 10.1037/0022-3514.89.6.852

```
# compute an indirect effect index for a specific value in a moderated
# mediation.
data(ho_et_al)
ho_et_al$condition_c <- build_contrast(ho_et_al$condition,
"Low discrimination",
"High discrimination")
ho_et_al <- standardize_variable(ho_et_al, c(linkedfate, sdo))
moderated_mediation_model <- mdt_moderated(data = ho_et_al,
DV = hypodescent,
IV = condition_c,
M = linkedfate,
Mod = sdo)
compute_indirect_effect_for(moderated_mediation_model, Mod = 0)
#> - type: Conditional simple mediation index (Mod = 0)
#> - point estimate: 0.0916
#> - confidence interval:
#> - method: Monte Carlo (5000 iterations)
#> - level: 0.05
#> - CI: [0.0421; 0.147]
```