title: moderated mediation with lavaan
body: <p>I was looking at this example:
  <a href="https://stats.stackexchange.com/questions/163436/r-moderated-mediation-using-the-lavaan-package">https://stats.stackexchange.com/questions/163436/r-moderated-mediation-using-the-lavaan-package</a> to make my own moderated mediation, but I get errors and I am not finding the solution.</p>
  
  <p>my model is:</p>
  
  <pre><code>model &lt;- '
  #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 &lt;- sem(model, data=mydata, se="robust.huber.white", test="bootstrap",bootstrap=1000)
  </code></pre>
  
  <p>The error message I get is: </p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>I did scale all variables beforehand, not sure if that is the issue?
  Any thoughts?</p>