lavaan: moderated mediation

1,242 views
Skip to first unread message

Heidi Jacobs

unread,
Aug 18, 2016, 12:44:32 AM8/18/16
to lavaan

Hi all, 

I was looking at this example: http://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?


Thanks!

Terrence Jorgensen

unread,
Aug 18, 2016, 9:10:05 AM8/18/16
to lavaan

I did scale all variables beforehand, not sure if that is the issue? Any thoughts?

If "scaling" was a linear transformation, that wouldn't have anything to do with it.  The error message is about the input data.  Try fitting the model without bootstrapping to see if the error occurs for your original data or just one of the bootstrap samples.  If it happens with your original data, you may need to provide at least a portion of it that reproduces the error.

Given that you are requesting robust SEs, I'm not sure why you are requesting the Bollen-Stine bootstrap for the chi-squared test statistic.  If your data are not normal and you are willing to use robust SEs, why not use a robust-correction for the chi-squared test as well?  

Terrence D. Jorgensen
Postdoctoral Researcher, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Heidi Jacobs

unread,
Aug 18, 2016, 11:51:23 AM8/18/16
to lavaan
Dear Terence,

Thank you! Yes, the scaling was linear.
After staring at the screen for some more time, I discovered a typo in one of my variable names, pfew.
I actually used the robust estimation because my data is not normal distributed and wanted to avoid influence of outliers. Then I wanted to bootstrap my results.
I was not aware there are different ways to bootstrap the data. Can I do: test=robust and then ask for a certain number of iterations?

Many thanks for your help!
Heidi

Terrence Jorgensen

unread,
Aug 19, 2016, 6:52:45 AM8/19/16
to lavaan
Then I wanted to bootstrap my results.

Which results?  And why?  You can just fit the model with estimator = "MLR" to get robust SEs and test statistic.  If you want to bootstrap either, you can do it afterward using the bootstrapLavaan() function, which has details on the help page.

?bootstrapLavaan

Heidi Jacobs

unread,
Aug 20, 2016, 10:18:55 AM8/20/16
to lavaan
Thank you! I want to bootstrap all the standard errors and get a more reliable confidence interval. Wouldn't that be a good check of the robustness of my findings? 

Terrence Jorgensen

unread,
Aug 22, 2016, 7:45:20 AM8/22/16
to lavaan
I want to bootstrap all the standard errors and get a more reliable confidence interval. Wouldn't that be a good check of the robustness of my findings? 

I think that's what Kris and Andy recommend in many of their mediation articles, and I typically trust their advice.  But I don't think the evidence supports bootstrapping as the best method for testing an indirect effect.  Even bias-corrected bootstrap CIs do not have nominal coverage rates (i.e., a 95% interval will only capture the true parameter in 90% or so of replications).  Bootstrapping requires large sample sizes to work well (so that the sample deviates from the population very little, making it a good proxy of the population).  If your sample size is large enough for bootstrapping to perform well, then your parameter estimates are normally distributed, even the distribution of indirect effects (products of normally distributed parameters) have approximately normal sampling distributions when large samples are taken.  So the Sobel test (delta method of calculating SEs, which is lavaan's default behavior) for testing indirect effects will work very well (Type I error rates closer to nominal), and it is more efficient that bootstrapping (should translate to higher power when a null hypothesis is false).  But you can read this article to make your own decision (and perhaps convince reviewers of your decision, if necessary):

Heidi Jacobs

unread,
Aug 22, 2016, 9:17:32 AM8/22/16
to lavaan
I was indeed reading Preacher & Hayes and Andy Field :) And before discovering Lavaan, I used Process in SPSS. But I like the ease and flexibility of lava an.
Thank you for the reference! I will dig some more into this. My sample size is not big (n =127), in our field this is a nice dataset (neuroimaging), but most likely not enough for bootstrapping then.
Many thanks!
Heidi
Reply all
Reply to author
Forward
0 new messages