[R-sig-ME] using weights=varIdent in lme: how to change reference level of grouping factor?

Ben Bolker bbolker at gmail.com
Sun Jul 14 00:44:41 CEST 2013


Emma Knight <emma_knight at ...> writes:

>  I am fitting a model using the lme function. I am using
> weights=varIdent to fit a variance model with different variances
> for each level of a stratification variable.Can someone please tell
> me how to chance the reference level of the stratification variable?
> I have tried changing the reference level of the factor, and tried
> re-ordering the data frame so that the first observation has the
> level that I want to use as the reference level, but neither have
> worked.  Emma

  Good question. I would have guessed that re-ordering the factor
would do the trick, but I guess not.

library(nlme)
fm1 <- lme(distance ~ age, random =~age|Subject,
     weights=varIdent(form=~1|Sex),data=Orthodont)
fm1$modelStruct$varStruct
## Variance function structure of class varIdent representing
##    Male   Female 
## 1.000000 0.404098 

Orth2 <- transform(Orthodont,
      Sex=factor(Sex,levels=c("Female","Male")))
fm2 <- update(fm1,data=Orth2)
summary(model.frame(fm2))
fm2$modelStruct$varStruct
## Variance function structure of class varIdent representing
##    Male   Female 
## 1.000000 0.404098 

  I have spent some time delving through the guts of lme()
but haven't figured it out yet.  I'm somewhat baffled,
as the default order of factor() should be Female, Male in
any case, so I don't see where the order could be getting
messed up.



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