Converting Repeated Measures Mixed Model Formula From SAS To R - Stack Overflow
Converting Repeated Measures Mixed Model Formula From SAS To R - Stack Overflow
Converting Repeated Measures mixed model formula from SAS to R Ask Question
There are several questions and posts about mixed models for more complex experimental designs, so I thought this more simple model would help other
beginners in this process as well as I.
So, my question is I would like to formulate a repeated measures ancova in R from sas proc mixed procedure:
Here is the SAS output using the data created in R (below):
Below is how I formulated the model in R using 'nlme' package, but am not getting similar coefficient estimates:
Now, the output from R, which I now realize is similar to the output from lm() :
I believe I'm close as to the specification, but not sure what piece I'm missing to make the results match (within reason..). Any help would be appreciated!
UPDATE: Using the code in the answer below, the R output becomes:
> summary(model2)
Scroll to bottom for the parameter estimates look! identical to SAS.
Random effects:
Formula: ~GROUP - 1 | person
Structure: Diagonal
GROUPCONTROL GROUPTEST Residual
StdDev: 184.692 14.56864 93.28885
r sas mixedmodels
edited Aug 8 '12 at 1:23 asked Aug 5 '12 at 20:15
bahakev
1,544 4 27 31
What do you mean about not getting similar results? Do you mean that there is information that's missing, or that you're getting different estimates? If the latter, are you sure that
the input data is the same? – David Robinson Aug 5 '12 at 20:22
Hi @BenBolker! Good to see you noticing this thread. I'll be curious if you agree with my assessment below or not. I think this is trickier than the OP hoped, but it would be nice if I
was wrong. – Aaron Aug 6 '12 at 1:38
@bahakev: If you add the statistical information and ask it more in terms of what model is appropriate, this would be a great question for stats.stackexchange. – Aaron Aug 6 '12
at 1:56
2 Answers
Please try below:
Edit:
SAS/MIXED
R (a revised model2)
So, I think these covariance structures are very similar (σg1 = τg2 + σ1).
Edit 2:
Covariate estimates (SAS/MIXED):
So
TEST group diagonal element
= 125.79 + 8789.23
= 8915.02
CONTROL group diagonal element
= 33297 + 82775
= 116072
where diagonal element = σk1 + σk2.
Covariate estimates (R lme):
Random effects:
Formula: ~GROUP - 1 | person
Structure: Diagonal
GROUP1TEST GROUP2CONTROL Residual
StdDev: 14.56864 184.692 93.28885
So
where diagonal element = τg2 + σ1 + σg2.
edited Aug 8 '12 at 11:12 answered Aug 6 '12 at 0:33
Triad sou.
2,749 2 16 27
Also, since R actually parameterizes the model in terms of the correlation and the variances, it's hard to see how
your matrix matches the R code you wrote. Not that it's necessarily wrong, but it would help if you used R's
parameterization to explain. – Aaron Aug 6 '12 at 17:17
@bahakev: That would be cool! But when I ran it I couldn't see how the variance terms agreed; can you share your
results by editing the original post? – Aaron Aug 8 '12 at 1:04
Oooh, this is going to be a tricky one, and if it's even possible using standard nlme functions, is going
to take some serious study of Pinheiro/Bates.
Before you spend the time doing that though, you should make absolutely sure that this is exact model
you need. Perhaps there's something else that might fit the story of your data better. Or maybe there's
something R can do more easily that is just as good, but not quite the same.
First, here's my take on what you're doing in SAS with this line:
In contrast, here's my take on what your R code is doing:
random = ~ +1 | person,
correlation=corCompSymm(form=~day|person)
To let each group have their own correlation, I think you have to build a more complicated correlation
structure up out of two different pieces; I've never done this but I'm pretty sure I remember
Pinheiro/Bates doing it.
You might consider instead adding a random effect for person and then letting the variance be different
for the different groups with weights=varIdent(form=~1|group) (from memory, check my syntax,
please). This won't quite be the same but tells a similar story. The story in SAS is that the
measurements on some individuals are more correlated than the measurements on other individuals.
Thinking about what that means, the measurements for individuals with higher correlation will be closer
together than the measurements for individuals with lower correlation. In contrast, the story in R is that
the variability of measurements within individuals varies; thinking about that, measurements with higher
variability with have lower correlation. So they do tell similar stories, but come at it from opposite sides.
It is even possible (but I would be surprised) that these two models end up being different
parameterizations of the same thing. My intuition is that the overall measurement variability will be
different in some way. But even if they aren't the same thing, it would be worth writing out the
parameterizations just to be sure you understand them and to make sure that they are appropriately
describing the story of your data.
answered Aug 6 '12 at 1:34
Aaron
27.5k 4 50 105
A final thought though, changing the the correlation structure usually doesn't affect the estimates of the fixed effects,
so if that's what's different, there may be something else going too. – Aaron Aug 6 '12 at 1:54
Your answer sounds reasonable to me, but I really think we need to hear/see more from the OP about what the
output of each program looks like (I have access to SAS, but not conveniently) and where the key differences are ...
– Ben Bolker Aug 6 '12 at 4:01
Thanks, @BenBolker. I haven't tried running the OP's code either; I have access to SAS but not conveniently from
home. – Aaron Aug 6 '12 at 4:36