I answer my own question.
I was disturbed by the syntax of the SAS code for "proc mixed", which uses
the same procedure for mixed or non mixed effect model. Moreover, the type
of variance-covariance structure is indicate by one parameter.
R is more intuitive and supple : there is two different functions (gls and
lme), and two parameters (one for variance structure, one for correlation
structure). I needed too much time to understand this.
My mistake.
david
2008/6/25 David Hajage <[EMAIL PROTECTED]>:
> I would like to make clear that the SAS "unstructured" correlation matrix
> in the second model was :
> Estimated R Correlation Matrix for id 1
>
> 1 1. 0.8575 0.6984 0.4657 0.3165
> 2 0.8575 1. 0.8557 0.5670 0.4039
> 3 0.6984 0.8557 1. 0.8717 0.7551
> 4 0.4657 0.5670 0.8717 1. 0.9333
> 5 0.3165 0.4039 0.7551 0.9333 1.
>
> which seems to be equal to :
>
> > cov2cor(cov(datares))
> [,1] [,2] [,3] [,4] [,5]
> [1,] 1.000 0.8574841 0.6984365 0.4657120 0.3165061
> [2,] 0.8574841 1.000 0.8557224 0.5670489 0.4038805
> [3,] 0.6984365 0.8557224 1.000 0.8716642 0.7550925
> [4,] 0.4657120 0.5670489 0.8716642 1.000 0.9333166
> [5,] 0.3165061 0.4038805 0.7550925 0.9333166 1.000
>
> but not to :
>
> > cov2cor(extract.lme.cov(fm2,rats)[1:5, 1:5]) # corClasses in fm2 :
> corSymm
> 1 2 3 4 5
> 1 1.000 0.9153199 0.8424135 0.6222813 0.2125583
> 2 0.9153199 1.000 0.9344902 0.6960017 0.3115286
> 3 0.8424135 0.9344902 1.000 0.8709635 0.5573176
> 4 0.6222813 0.6960017 0.8709635 1.000 0.8218556
> 5 0.2125583 0.3115286 0.5573176 0.8218556 1.000
>
>
> 2008/6/25 David Hajage <[EMAIL PROTECTED]>:
>
> Hello R users,
>>
>> I'm student and I'm actually having a lecture introducing repeated mesures
>> analysis. Unfortunately, all examples use SAS system...
>>
>> I'm working with lme function (package "nlme"), and I'm using
>> extract.lme.cov (package "mgcv") to extract covariance structure of models.
>>
>> One example is about weight evolution of rats (3 treatment groups) :
>>
>> > summary(rats)
>>id trt y s
>> 1 : 5 1:50 Min. : 46.0 0:27
>> 10 : 5 2:50 1st Qu.: 71.0 1:27
>> 11 : 5 3:35 Median :100.0 2:27
>> 12 : 5 Mean :100.8 3:27
>> 13 : 5 3rd Qu.:122.5 4:27
>> 14 : 5 Max. :189.0
>> (Other):105
>>
>> id : subjects
>> trt : treatment groups (1, 2 or 3)
>> y : weights
>> s : weeks (Week 0 to Week 4)
>>
>> There are 5 mesearements of weight (on week 0, 1, 2, 3 and 4) for each
>> rat.
>>
>> I first fit a model with a compound symmetry correlation structure :
>>
>> > library(nlme)
>> > library(mgcv)
>> > fm1 <- lme(y ~ as.factor(s) * as.factor(trt), data = rats, random = ~
>> 1|id, correlation = corCompSymm())
>> > summary(fm1)
>> ...
>> Fixed effects: y ~ as.factor(s) * as.factor(trt)
>> Value Std.Error DF t-value p-value
>> (Intercept)54.0 3.469019 96 15.56636 0.
>> as.factor(s)1 24.5 3.125974 96 7.83756 0.
>> as.factor(s)2 52.0 3.125974 96 16.63481 0.
>> as.factor(s)3 76.1 3.125974 96 24.34441 0.
>> as.factor(s)4 106.6 3.125974 96 34.10137 0.
>> as.factor(trt)2 0.7 4.905934 24 0.14268 0.8877
>> as.factor(trt)3 1.57143 5.406076 24 0.29068 0.7738
>> as.factor(s)1:as.factor(trt)2 -2.9 4.420795 96 -0.65599 0.5134
>> as.factor(s)2:as.factor(trt)2 -10.9 4.420795 96 -2.46562 0.0155
>> as.factor(s)3:as.factor(trt)2 -22.6 4.420795 96 -5.11220 0.
>> as.factor(s)4:as.factor(trt)2 -37.3 4.420795 96 -8.43740 0.
>> as.factor(s)1:as.factor(trt)3 -4.21429 4.871479 96 -0.86509 0.3891
>> as.factor(s)2:as.factor(trt)3 -2.71429 4.871479 96 -0.55718 0.5787
>> as.factor(s)3:as.factor(trt)3 1.04286 4.871479 96 0.21407 0.8309
>> as.factor(s)4:as.factor(trt)3 0.68571 4.871479 96 0.14076 0.8884
>> ...
>>
>> > extract.lme.cov(fm1,rats)[1:5, 1:5]
>> 1 2 3 4 5
>> 1 120.34095 71.48238 71.48238 71.48238 71.48238
>> 2 71.48238 120.34095 71.48238 71.48238 71.48238
>> 3 71.48238 71.48238 120.34095 71.48238 71.48238
>> 4 71.48238 71.48238 71.48238 120.34095 71.48238
>> 5 71.48238 71.48238 71.48238 71.48238 120.34095
>>
>> As you can see, I obtain exactly the same solutions for fixed parameters
>> and estimated covariance matrix in SAS :
>> proc mixed data = rat ;
>> class id trt s ;
>> format trt ftrt. s fs. ;
>> model y = trt s trt * s / solution ddfm = satterth ;
>> repeated s / type = cs subject = id r rcorr;
>> run ;
>>
>>