# How to specify uncorrelated random slopes in lmer() syntax?

I am currently fitting a mixed effects model to some experimental data as follows:

model <- lmer(Y ~ X + M + (1+X+M|Subject), data=mydata)


The meaning of the variables is not so important here, but $X$ is the predictor of interest while $M$ is a (suspected) mediating variable. All variables are continuous and measured within-subjects. Now the question concerns the random slopes in this model. The above syntax specifies fully correlated random effects. However, I would like to remove the correlation between the two random slopes ($X$ and $M$) without removing the correlation between the random slopes and the random intercept.

Initially, I attempted the following code:

model <- lmer(Y ~ X + M + (1+X|Subject) + (1+M|Subject), data=mydata)


This does produce uncorrelated random slopes but lmer() now estimates a random subject intercept both for $X$ and $M$. I am not sure this is correct (or what I require), because I am now forced to introduce an extra variance parameter (simply for removing another one). Is there any way to specify a single subject intercept and uncorrelated random slopes for $X$ and $M$?

• Perhaps lmer(Y ~ X + M + (1+X|Subject) + (0+M|Subject), data=mydata) Commented Jun 18, 2013 at 16:42
• Almost, but now the random M slope is uncorrelated with the random subject intercept. Only the two slopes should be uncorrelated. All other correlations are allowed. Commented Jun 18, 2013 at 22:05
• The solution is given here: stackoverflow.com/a/35401176 Commented Jan 11, 2018 at 9:49

I think what you want is not directly achievable. The best seems to be your second option (i.e., two random intercepts but no slopes).

Depending on the number of levels in X and M, this should decrease the number of parameters overall. As in the following example:

require(lme4)

# use data with two within variables:
data(obk.long, package = "afex")

# the full model
m1 <- lmer(value ~ phase + hour + (phase + hour|id), data = obk.long)
print(m1, corr = FALSE)
# has correlations between the slopes.

# the alternative model with two intercepts:
m2 <- lmer(value ~ phase + hour + (hour|id) + (phase|id), data = obk.long)
print(m2, corr = FALSE)
# has no correlations between the slopes but two intercepts:

# m2 has overall less parameters (29 vs 36):
anova(m1, m2)


I realize this is an old question, but does || address your issue?

model <- lmer(Y ~ X + M + (1+X+M||Subject), data=mydata)

• This does not achieve what OP was asking about. Commented Dec 21, 2017 at 22:38
• Where does it fall short? Commented Dec 22, 2017 at 2:13
• "I would like to remove the correlation between the two random slopes (X and M) without removing the correlation between the random slopes and the random intercept." If you think your syntax achieves this then please explain how. Commented Dec 22, 2017 at 7:47