Skip to content
Prev 15109 / 20628 Next

"varFunc" classes

I'm too lazy to see if anyone has answered this one already, so ...
On 16-12-13 03:48 AM, Dan Jackson wrote:
It has been implemented in R, but in the nlme package rather than the
lme4 package (which contains lmer and glmer).

   Historical note: nlme is the package associated with Pinheiro and
Bates's 2000 book. R's first "stable beta" version (according to
Wikipedia) was released in 2000.  Doug Bates has been involved in R
since the beginning (or almost?).

  If you need to do this in lme4::lmer, you can do it in a sort of
clunky way by setting up dummy variables for group differences and
adding an individual-level random effect, e.g.


data(Orthodont,package="nlme")

O2 <- transform(Orthodont,
                obs=seq(nrow(Orthodont))) ## observation-level variance


## since Female var < Male var, we have to use a dummy for Male
## to add extra variance for males (won't work the other way because
## we can't have a negative variance)

m1 <-lmer(distance ~ age + (age|Subject) +
         (0+dummy(Sex,"Male")|obs),
     control=lmerControl(check.nobs.vs.nlev="ignore",
                         check.nobs.vs.nRE="ignore"),
     O2)

library(nlme)
m2 <- lme(distance~age,random=~age|Subject,
          data=Orthodont,
          weights=varIdent(form=~1|Sex))
summary(m2)

all.equal(c(logLik(m1)),c(logLik(m2)))
all.equal(c(fixef(m1)),c(fixef(m2)),tolerance=1e-6)