Skip to content
Prev 19064 / 20628 Next

lmer code for multiple random slopes

I second Phillip's point.  The example below works as expected (gets 
a singular fit, but there are 6 covariance parameters as expected). 
Based on what you've told us so far, the most plausible explanation is 
that one or both of your covariates (x and/or z) are factors 
(categorical) rather than numeric.

   Ben Bolker



===========
set.seed(101)
dd <- data.frame(x=rnorm(500),z=rnorm(500),
                  g=factor(sample(1:6,size=500,replace=TRUE)))
form <- y ~ x + z + (x+z|g)
dd$y <- simulate(form[-2],
                  newdata=dd,
                  newparams=list(beta=rep(0,3),
                                 theta=rep(1,6),
                                 sigma=1))[[1]]


library(lme4)
m1 <- lmer(form, data=dd)
VarCorr(m1)
On 2/16/21 8:18 AM, Phillip Alday wrote: