I was looking at this example: https://stats.stackexchange.com/questions/163436/r-moderated-mediation-using-the-lavaan-package to make my own moderated mediation, but I get errors and I am not finding the solution.
my model is:
model <- '
#direct effects
mem ~ c*var1 + cw*interaction +b*var2
var2 ~ a*var1+aw*interaction
#covariates
mem ~ age+sex+iq
var1 ~ age+sex+iq
var 2 ~ age+sex+iq
#indirect effect
ab := a*b
#total effect
total := c+(a*b)
#conditional effects
ab1 := a*b+aw*b
total1 := a*b+c+cw'
fit <- sem(model, data=mydata, se="robust.huber.white", test="bootstrap",bootstrap=1000)
The error message I get is:
Error in chol.default(S) :the leading minor of order 8 is not positive definite In addition: Warning message: In lav_samplestats_from_data(lavdata = NULL, DataX = dataX, DataeXo = dataeXo,: lavaan WARNING: sample covariance can not be inverted
I did scale all variables beforehand, not sure if that is the issue? Any thoughts?