# Specify a nested model with and without correlated slope and intercept?

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?

• 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? – Patrick Coulombe Feb 2 '16 at 16:23
• 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? – 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():
library(lme4)

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).