[R] extract variance components

Mark Lyman mark.lyman at atk.com
Fri Aug 29 15:39:58 CEST 2008


huang min <minhuangr <at> gmail.com> writes:

> 
> HI,
> 
> I would like to extract the variance components estimation in lme function
> like
> 
> a.fit<-lme(distance~age, data=aaa, random=~day/subject)
> 
> There should be three variances \sigma_day, \sigma_{day %in% subject } and
> \sigma_e.
> 
> I can extract the \sigma_e using something like a.fit$var. However, I cannot
> manage to extract the first two variance components. I can only see the
> results in summary(a.fit).
> 
> I have some problem in the lme4 package and hence use the nlme package. The
> example data also has some problem so I just list the function here using
> some imaginary data set. Thank you.
> 


You probably want to try one of these

> fm1 <- lme(distance ~ age, data = Orthodont, subset = Sex == "Female")
> getVarCov(fm1)
Random effects variance covariance matrix
            (Intercept)       age
(Intercept)     3.55020 -0.107490
age            -0.10749  0.025898
  Standard Deviations: 1.8842 0.16093 
> diag(getVarCov(fm1))
(Intercept)         age 
 3.55015248  0.02589773 
> VarCorr(fm1)
Subject = pdSymm(age) 
            Variance   StdDev    Corr  
(Intercept) 3.55015248 1.8841848 (Intr)
age         0.02589773 0.1609277 -0.354
Residual    0.44659098 0.6682746       
> VarCorr(fm1)[,1]
 (Intercept)          age     Residual 
"3.55015248" "0.02589773" "0.44659098" 
> as.numeric(VarCorr(fm1)[,1])
[1] 3.55015248 0.02589773 0.44659098

Mark



More information about the R-help mailing list