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. Huang [[alternative HTML version deleted]]
huang min <minhuangr <at> gmail.com> writes:> I would like to extract the variance components estimation in lme function > like > > a.fit<-lme(distance~age, data=aaa, random=~day/subject) >Try VarCor(a.fit) Using lme for the type of problems you have is just fine; in many respects, lme4 currently is a welcome complement rather than a replacement of nlme/lme. Dieter
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
Hi, Thanks for all. I now know how to extract the \sigma's. For the unbalanced model y_{ijk}=x\beta+\alpha_i+\beta_{ij}+e_{ijk} i=1,2,\dots,a, j=1,2,\dots,b_i, k=1,2,\dots,n_{ij} How can I extract the variance matrix $V$? The variance for the ith group is also of help. Suppose the ith group has totally 10 observations. b_i=4, n_{i1}=1,n_{i2}=3,n_{i3}=2 and n_{i4}=1. $V_i=\sigma_a^2 J_{10}+\sigma_b^2 diag(J_1,J_3,J_2, J_1)+\sigma_e^2 I_{10}$, where I is the identity matrix and J_d is the matrix of 1's with dimention d \by d. J_d reduces to 1 if d=1. I only know how to extract the design matrix for the fixed effect by model.matrix(lme.fit2). How to deal with the parts for the random effects? Thank you. Huang On Fri, Aug 29, 2008 at 11:30 AM, huang min <minhuangr@gmail.com> wrote:> 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. > > Huang >[[alternative HTML version deleted]]