Skip to content

R-sig-mixed-models mailing list submissions: Crossed Random Factors Mediation

1 message · b@sii@m@iy m@iii@g oii u@ibe@ch

#
Dear colleagues

I would like to calculate a multilevel mediation using a linear multilevel model with crossed random factors. The code for the model is as follows:

### R-Code:

model <- lmer(outcome ~ condition + rating + (1|id) + (1|stimulusid), data = dat, REML = TRUE)


I am not aware of any mediation package in R that can compute mediation with crossed random factors. Also, Lavaan does not support models with crossed random factors. Therefore, I aimed to implement the indirect effect test with BootMer by myself. I would like to use the semi-parametric bootstrapping. This is my attempt so far:

### R-Code:
function_indirect_effect <- function(x) {
                                                                 fixef(x)[2]*fixef(x)[3]
}

boots <- bootMer(model,
               FUN = function_indirect_effect,
               use.u = FALSE,
type = "parametric",
nsim = 1000)

boots <- bootMer(model,
               FUN = function_indirect_effect,
               use.u = TRUE,
type = "semiparametric",
nsim = 1000)

However, the semi-parametric bootstrapping does not work, and only NAs are produced (?Warning: some bootstrap runs failed (1000/1000)?).
The problem is probably the simulation of the random effects (?use.u = TRUE?), since parametric bootstrapping doesn't work in this case either.


Does anyone have a hint what this could be due to and how I could fix the? Or does anyone know another way/package to compute and test the indirect effect?

Thanks for your time and kind regards,
Basil Maly