[R] (robust) mixed-effects model with covariate

Spencer Graves spencer.graves at pdf.com
Thu Aug 3 08:19:10 CEST 2006


	  What do you get from the following:

	  max(with(df1, table(Subj, Time)))?

	  With cases like this, "lme" gives an answer with a bogus distinction 
between variance components for "time" and "residuals".  I don't know 
about "aov" or "JMP", but I know that "varcomp" in S-Plus also produces 
garbage answers in such cases as well.

	  With mixed models, there seem to be many ways to specify models with 
random effects that are not estimable.  Some some standard software 
(like "varcomp" in S-Plus or "lme") does not (adequately?) test for 
these situations, with the result that the algorithm sometimes returns 
answers that are not correct, at least with the distinction between 
"time" and "residual".

	  I don't know if this applies to your example since it is not self 
contained.

	  Your code raises other question.  For example, what is the class of 
"Time" in "df1"?  Might it be treated differently between "aov" and 
"lme"?  How many levels does "Group" have, etc.?

	  Hope this helps.
	  Spencer Graves
p.s.  If you'd like more help from this listserve, please submit another 
post that includes commented, minimal, self-contained, reproducible 
code, as suggested in  the posting guide 
"www.R-project.org/posting-guide.html".

Giuseppe Pagnoni wrote:
> Dear Thilo,
> 
> many thanks for your reply.  I realized that there was an error in my 
> formula which should have been:
> 
> aov(y ~ Group * (Time + Age) + Error (Subj/Time), data=df1)
> 
> or alternatively:
> 
> lme(RVP.A ~ Group*(Time+Age), random = ~ 1|Subj/Time,data=df1)
> 
> but I get different results in each case, and different still from the 
> results of another stat program (JMP).
> The problem is that I am not sure which one (if one indeed is) correct!
> 
> Also, in the model you proposed:
> 
> lme(y~Group*Time, random ~ age | Subj, data = df1)
> 
> it appears that age is not between the effects of interests, so I do not 
> get an estimate of the significance of the Age or the Age*Group effect.
> 
> I have Pinheiro & Bates, and I read the first chapter but it didn't seem 
> to provide an example analogous to my case.  Also, it looks like it 
> would take me some months to study the book thoroughly and frankly that 
> seems a bit excessive for such a (apparently?) simple problem....  I was 
> hoping somebody would magically provide the correct syntax :-)  !
> 
> thanks again anyway for your help
> 
> best regards
> 
>    giuseppe
> 
> 
> 
> Thilo Kellermann wrote:
>> On Monday 24 July 2006 20:16, Giuseppe Pagnoni wrote:
>>   
>>> Dear all,
>>>
>>> First of all I apologize if you received this twice: I was checking the
>>> archive and I noticed that the text was scrubbed from the message,
>>> probably due to some setting in my e-mail program.
>>>
>>>
>>> I am unsure about how to specify a model in R and I thought of asking
>>> some advice to the list. I have two groups ("Group"= A, B) of subjects,
>>> with each subject undertaking a test before and after a certain
>>> treatment ("Time"= pre, post). Additionally, I want to enter
>>> the age of the subject as a covariate (the performance on the test is
>>> affected by age), and I also want to allow different slopes for the
>>> effect of age in the two groups of subjects (age might affect the
>>> performance of the two groups differentially).
>>>
>>> Is the right model to use something like the following?
>>>
>>> aov (y ~ Group*Time + Group*Age + Error(Subj/Group), data=df1 )
>>>
>>> (If I enter that command, within summary, I get the following:
>>> Error() model is singular in: aov(y ~ Group * Time + Group * Age +
>>> Error(Subj/Group), data = df1))
>>>
>>>     
>> try:
>> aov(y~Group*Time*Age + Error(Subj*Time*Age), data = df1)
>> which specifies an ANOVA (but not with mixed effects) with three main effects 
>> and all interaction terms plus an error term that is independent between 
>> groups (!) and relates to within subjects variability.
>>
>> For a "real" mixed effects analysis you should use the (n)lme function from 
>> the nlme package and one possible model could look like this:
>>
>> lme(y~Group*Time, random ~ age | Subj, data = df1)
>>
>> but the exact specification depends on your assumptions, in which it is 
>> possible to specify two or three models and compare their fits with anova(). 
>> For more information on mixed effects you should consult:
>> Jose C. Pinheiro & Douglas M. Bates (2000) Mixed-Effects Models in S and 
>> S-PLUS. Springer, New York.
>>
>> Good luck,
>> Thilo
>>
>>   
>>> As a second question: I have an outlier in one of the two groups. The
>>> outlier is not due to a measurement error but simply to the performance
>>> of the subject (possibly related to his medical history, but I have no
>>> way to determine that with certainty). This subject is
>>> signaled to be an outlier within its group: averaging the pre and post
>>> values for the performance of the subjects in his group, the Grubbs test
>>> yields a probability of 0.002 for the subject to be an outlier (the
>>> subject is marked as a significant outlier also if I
>>> perform the test separately on the pre and the post data).
>>>
>>> If I remove this subject from its group, I get significant effects of
>>> Group and Group X Age (not using the R formula above, but another stat
>>> software), but if I leave the subject in those effects disappear. Since
>>> I understand that removing outliers is always worrysome, I would like to
>>> know if it is possible in R to estimate a model similar to that outlined
>>> above but in a resistant/robust fashion, and what would be the actual
>>> syntax to do that. I will very much appreciate any help or suggestion
>>> about this.
>>>
>>> thanks in advance and best regards
>>>
>>> giuseppe
>>>     
>>   
> 
>



More information about the R-help mailing list