[R-sig-ME] Random slope/intercept without correlation in lmer

Gustaf Granath gustaf.granath at gmail.com
Mon Aug 11 23:38:53 CEST 2014


Hi
I want to model random slope and intercept without a correlation between 
the two. Is it possible to do this in lmer when the predictor is a factor?

For example, imagine that x has 2 levels (control and treatment). In 
nlme, I have been modeling uncorrelated intercept and slope like this:
lme(y ~ x, random=list(x = pdDiag(~ group)) ) where group is a random 
factor.
It gives me the random intercept and random slope (i.e. variation in 
treatment effect among groups).

In lmer, I think the corresponding model is defined as:
lmer( y ~ x + (x||rand) and I guess this gives me differences (variation 
in differences to the intercept), but it includes a covariance term.

Is it possible to reproduce the above lme() model in lmer?

I have a strong feeling that Im missing something here. Most of the 
literature on this subject (and R-list questions) deals with continuous 
variables so pls let me know if there is a good source on this topic.

Below follows a small example.

Cheers

Gustaf


set.seed(1)
treat = rep(c(0, 1), each = 5, 10)
group = rep(1:10, each = 10)
rand.int = rep( rnorm( 10, 0, 1), each = 10)
rand.slop = rep( rnorm(10, 0, 1), each = 10)
e = rnorm(100, 0, 0.5)
y = 10 + rand.int + treat + rand.slop*treat + e
treat = factor(treat)

#lmer
library(lme4)
# with correlation between intercept and slope
mod = lmer(y ~ treat + (treat|group) )
# without correlation between intercept and slope
# gives lots of error msgs
mod2 = lmer(y ~ treat + (treat||group) )
summary(mod)
summary(mod2)
# var-covar matrix
VarCorr(mod)$group
VarCorr(mod2)$group.1 #still a covariance term

#nlme
# without correlation
library(nlme)
lme.mod <- lme(y ~ treat, random=list(group = pdDiag(~ treat)) )
summary(lme.mod)
getVarCov(lme.mod)

-- 
Gustaf Granath (PhD)
Post doc
McMaster University
School of Geography & Earth Sciences



More information about the R-sig-mixed-models mailing list