Hi there,
I've fitted a multi-group mediation model with three parallel mediators and three covariates.
The model successfully converged and provides a summary just fine.
However, when I attempt to simulate the data using simulateData or using sim in the package simsem, I get the following error:
Error in lavaanify(model = model, meanstructure = meanstructure, int.ov.free = int.ov.free, :
lavaan ERROR: wrong number of arguments in modifier (M1YDirectA,M1YDirectB,M1YDirectC,M1YDirectD) of element Y~M1
However, the number of modifiers I've included is equal to the number of groups I have, which is 4.
I saw a previous post where someone had the same issue and the suggestion was to try it as a multilevel model. Is there a different way to do this or perhaps my construction of the model is incorrect? I constructed the model in two different ways because I am unsure about whether each indirect and total effect needed to have all four modifiers.
Thank you for your help!
Version 1
See below:
modelH2a <- '
##DIRECT EFFECT
Y ~ c(M1YDirectA, M1YDirectB, M1YDirectC, M1YDirectD)*M1 + c(M2YDirectA, M2YDirectB, M2YDirectC, M2YDirectD)*M2 + c(M3YDirectA, M3YDirectB, M3YDirectC, M3YDirectD)*M3 + c(X1YDirectA, X1YDirectB, X1YDirectC, X1YDirectD)*X1 + c(X2YDirectA, X2YDirectB, X2YDirectC, X2YDirectD)*X2 + c(X3YDirectA, X3YDirectB, X3YDirectC, X3YDirectD)*X3 + c(X4YDirectA, X4YDirectB, X4YDirectC, X4YDirectD)*X4
##MEDIATORS
M1 ~ c(X1M1a, X1M1b, X1M1c, X1M1d)*X1 + c(X2M1a, X2M1b, X2M1c, X2M1d)*X2 + c(X3M1a, X3M1b, X3M1c, X3M1d)*X3 + c(X4M1a, X4M1b, X4M1c, X4M1d)*X4
M2 ~ c(X1M2a, X1M2b, X1M2c, X1M2d)*X1 + c(X2M2a, X2M2b, X2M2c, X2M2d)*X2 + c(X3M2a, X3M2b, X3M2c, X3M2d)*X3 + c(X4M2a, X4M2b, X4M2c, X4M2d)*X4
M3 ~ c(X1M3a, X1M3b, X1M3c, X1M3d)*X1 + c(X2M3a, X2M3b, X2M3c, X2M3d)*X2 + c(X3M3a, X3M3b, X3M3c, X3M3d)*X3 + c(X4M3a, X4M3b, X4M3c, X4M3d)*X4
##INDIRECT EFFECTS
###X1 -> Y via M1, M2, M3
abX1M1a := (X1M1a*M1YDirectA)
abX1M1b := (X1M1b*M1YDirectB)
abX1M1c := (X1M1c*M1YDirectC)
abX1M1d := (X1M1d*M1YDirectD)
abX1M2a := (X1M2a*M2YDirectA)
abX1M2b := (X1M2b*M2YDirectB)
abX1M2c := (X1M2c*M2YDirectC)
abX1M2d := (X1M2d*M2YDirectD)
abX1M3a := (X1M3a*M3YDirectA)
abX1M3b := (X1M3b*M3YDirectB)
abX1M3c := (X1M3c*M3YDirectC)
abX1M3d := (X1M3d*M3YDirectD)
##TOTAL EFFECTS
totalX1A := X1YDirectA + (X1M1a*M1YDirectA) + (X1M2a*M2YDirectA) + (X1M3a*M3YDirectA)
totalX1B := X1YDirectB + (X1M1b*M1YDirectB) + (X1M2b*M2YDirectB) + (X1M3b*M3YDirectB)
totalX1C := X1YDirectC + (X1M1c*M1YDirectC) + (X1M2c*M2YDirectC) + (X1M3c*M3YDirectC)
totalX1D := X1YDirectD + (X1M1d*M1YDirectD) + (X1M2d*M2YDirectD) + (X1M3d*M3YDirectD)'
Version 2
modelH2c <- '
##DIRECT EFFECT
Y ~ c(M1YDirectA, M1YDirectB, M1YDirectC, M1YDirectD)*M1 + c(M2YDirectA, M2YDirectB, M2YDirectC, M2YDirectD)*M2 + c(M3YDirectA, M3YDirectB, M3YDirectC, M3YDirectD)*M3 + c(X1YDirectA, X1YDirectB, X1YDirectC, X1YDirectD)*X1 + c(X2YDirectA, X2YDirectB, X2YDirectC, X2YDirectD)*X2 + c(X3YDirectA, X3YDirectB, X3YDirectC, X3YDirectD)*X3 + c(X4YDirectA, X4YDirectB, X4YDirectC, X4YDirectD)*X4
##MEDIATORS
M1 ~ c(X1M1a, X1M1b, X1M1c, X1M1d)*X1 + c(X2M1a, X2M1b, X2M1c, X2M1d)*X2 + c(X3M1a, X3M1b, X3M1c, X3M1d)*X3 + c(X4M1a, X4M1b, X4M1c, X4M1d)*X4
M2 ~ c(X1M2a, X1M2b, X1M2c, X1M2d)*X1 + c(X2M2a, X2M2b, X2M2c, X2M2d)*X2 + c(X3M2a, X3M2b, X3M2c, X3M2d)*X3 + c(X4M2a, X4M2b, X4M2c, X4M2d)*X4
M3 ~ c(X1M3a, X1M3b, X1M3c, X1M3d)*X1 + c(X2M3a, X2M3b, X2M3c, X2M3d)*X2 + c(X3M3a, X3M3b, X3M3c, X3M3d)*X3 + c(X4M3a, X4M3b, X4M3c, X4M3d)*X4
##INDIRECT EFFECTS
###X1 -> Y via M1, M2, M3
abM1 := (c(X1M1a, X1M1b, X1M1c, X1M1d)*X1) * (c(M1YDirectA, M1YDirectB, M1YDirectC, M1YDirectD)*M1)
abM2 := (c(X1M2a, X1M2b, X1M2c, X1M2d)*X1) * (c(M2YDirectA, M2YDirectB, M2YDirectC, M2YDirectD)*M2)
abM3 := (c(X1M3a, X1M3b, X1M3c, X1M3d)*X1) * (c(M3YDirectA, M3YDirectB, M3YDirectC, M3YDirectD)*M3)
##TOTAL EFFECTS
totalX1 := (c(X1YDirectA, X1YDirectB, X1YDirectC, X1YDirectD)*X1) + abM1 + abM2 + abM3'