I have a psychotherapy data set that has a nested structure - patients nested within therapists. I'm interested in fitting a model that predicts patients' outcome (a level 1 patient variable) from the length of treatment. In 'lmer' it would be something like this:

mod1 <- lmer(effect.size ~ Tx.length + (1|Therapist), data = data)

I am interested in allowing the intercept and slope to correlate in one model but not in the other. I'm interested in whether the random intercept X slope correlation is different from zero.

Do I need to use 'lavaan' to fit this model? Are there straightforward ways to specify the nesting of patients within therapists?

  • $\begingroup$ I don't understand the reason you give for wanting to use lavaan over lmer. You can't estimate the two models (one where the intercept and slope are correlated and one where they're not) with lmer? $\endgroup$ – Patrick Coulombe Feb 2 '16 at 16:23
  • 1
    $\begingroup$ Thanks, Patrick. I'd much prefer lmer if possible. How does one coerce the random intercept X slope correlation to zero in lmer? And then can you simply compare the models using anova( ) as in other instances of nested models? $\endgroup$ – arrrrRgh Feb 2 '16 at 16:47

You specify in the comments that your actual interest is just in running models that do and don't include a correlation between the random intercept and slope, using lmer() if possible and lavaan if needed. You can make random effects independent (not correlated) with lme4::lmer():

fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
fm2 <- lmer(Reaction ~ Days + (0 + Days | Subject) + (1 | Subject), sleepstudy)
fm3 <- lmer(Reaction ~ Days + (Days || Subject), sleepstudy)

In this example (using the sleepstudy dataset in the lme4 package), fm1 allows a correlation between the random slope and intercept, since they're specified together. The second model, fm2, is very similar, but it specifies the random effects separately, which tells lme4 that they should be independent (fm3 will work exactly the same as fm2, just written in shorthand).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.