[R-sig-ME] "varFunc" classes

Ben Bolker bbolker at gmail.com
Wed Dec 14 20:02:32 CET 2016


  I'm too lazy to see if anyone has answered this one already, so ...

On 16-12-13 03:48 AM, Dan Jackson wrote:
> Dear lme4 authors,
> 
> I am sure you are very busy so I will just ask my question very quickly. I
> was reading the book "Mixed-effects models in S and S-plus" by Pinheiro and
> Bates. On the top of page 208 of this book, there is a Table 5.1 that
> implements various "varFunc" classes. One of these classes would seem to be
> what I need for my data: varIdent - different variances per stratum. I do
> know that different subets in my data have very different variances you see,
> so I would need to include this.
> 
> However this book relates to S-plus and I am not sure if this has been
> implemented in R, in the glmer package? My data are continuous so I would
> just need this for lmer (and not glmer). If it has not been implemented is
> there any "workaround"?

  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)




> 
> Thanks in advance for any advice, Dan Jackson
> 
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>



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