[R] can I get same results using lme and gls?
toby909 at gmail.com
toby909 at gmail.com
Mon May 21 20:30:01 CEST 2007
Douglas Bates wrote:
> On 5/20/07, toby909 at gmail.com <toby909 at gmail.com> wrote:
>>I was wondering how to get the same results with gls and lme. In my lme, the
>>design matrix for the random effects is (should be) a identity matrix and
>>therefore G should add up with R to produce the R matrix that gls would report
>>(V=ZGZ'+R). Added complexity is that I have 3 levels, so I have R, G and say H
>>(V=WHW'+ZGZ'+R). The lme is giving me the correct results, I am having trouble
>>finding the right corresponding specification for the gls.
> Thanks for including a reproducible example. However, I'm a bit at a
> loss as to why you would want to try to create a gls model that fits a
> mixed-effects model that has random effects for intercept and slope at
> two nested levels. I don't think that corCompSymm will do what you
> want but, to tell the truth, I have difficulty in thinking of the
> model in that form. I much prefer the mixed-effects form.
Thanks for your response. I was too vague, sorry. I think I want to fit a gls
model at the lowest level and a mixed effects model with random effects for
intercept and slope the the highest level.
I dont know if I express that right:
would know how to do using GLS: V=R, R is a "double"block diagonal matrix
would also know how to do w/LME: V=WHW'+ZGZ'+R, R is diagonal
wanted: V=WHW'+R, R is block diagonal.
This is just for my learning purposes to replicate a textbookexample. This
example has 3 levels. The lowest are 2, possibly more, multivatiate measurements
(not longitudinal, just to measures, math score and language score in the
example, ie unstructured covariance matrix). These are nested within individuals
and the individuals are nested within schools. For the lowest level I would
choose a gls model for the higher level I would want a lme model both at the
Thanks for your thought.
>>Thanks for your help.
>>dta1 = reshape(dtaa, list(c("V10","V12")), "score", direction="long",
>>colnames(dta1) = "schoolNR"
>>dta2 = dta1[order(dta1$id),]
>>timef = factor(dta2$time)
>>summary(mdl1l <- lme(score~timef-1, dta2, ~timef-1|schoolNR/id,,,,"ML"))
>>summary(mdl1g <- gls(score~timef-1, dta2, corCompSymm(, ~timef|schoolNR/id),
>>R-help at stat.math.ethz.ch mailing list
>>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>and provide commented, minimal, self-contained, reproducible code.
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help