[R] lme and aov

Gang Chen gangchen at mail.nih.gov
Fri Aug 3 22:22:09 CEST 2007


Thanks a lot for clarification! I just started to learn programming  
in R for a week, and wanted to try a simple mixed design of balanced  
ANOVA with a between-subject factor
(Grp) and a within-subject factor (Rsp), but I'm not sure whether I'm  
modeling the data correctly with either of the command lines.

Here is the result. Any help would be highly appreciated.

 > fit.lme <- lme(Beta ~ Grp*Rsp, random = ~1|Subj, Model);
 > summary(fit.lme)
Linear mixed-effects model fit by REML
Data: Model
       AIC      BIC    logLik
   233.732 251.9454 -108.8660

Random effects:
Formula: ~1 | Subj
         (Intercept)  Residual
StdDev:    1.800246 0.3779612

Fixed effects: Beta ~ Grp * Rsp
                  Value Std.Error DF    t-value p-value
(Intercept)  1.1551502 0.5101839 36  2.2641837  0.0297
GrpB        -1.1561248 0.7215090 36 -1.6023706  0.1178
GrpC        -1.2345321 0.7215090 36 -1.7110417  0.0957
RspB        -0.0563077 0.1482486 36 -0.3798196  0.7063
GrpB:RspB   -0.3739339 0.2096551 36 -1.7835665  0.0829
GrpC:RspB    0.3452539 0.2096551 36  1.6467705  0.1083
Correlation:
           (Intr) GrpB   GrpC   RspB   GrB:RB
GrpB      -0.707
GrpC      -0.707  0.500
RspB      -0.145  0.103  0.103
GrpB:RspB  0.103 -0.145 -0.073 -0.707
GrpC:RspB  0.103 -0.073 -0.145 -0.707  0.500

Standardized Within-Group Residuals:
         Min          Q1         Med          Q3         Max
-1.72266114 -0.41242552  0.02994094  0.41348767  1.72323563

Number of Observations: 78
Number of Groups: 39

 > fit.aov <- aov(Beta ~ Rsp*Grp+Error(Subj/Rsp)+Grp, Model);
 > fit.aov

Call:
aov(formula = Beta ~ Rsp * Grp + Error(Subj/Rsp) + Grp, data = Model)

Grand Mean: 0.3253307

Stratum 1: Subj

Terms:
                      Grp
Sum of Squares  5.191404
Deg. of Freedom        1

1 out of 2 effects not estimable
Estimated effects are balanced

Stratum 2: Subj:Rsp

Terms:
                          Rsp
Sum of Squares  7.060585e-05
Deg. of Freedom            1

2 out of 3 effects not estimable
Estimated effects are balanced

Stratum 3: Within

Terms:
                       Rsp       Grp   Rsp:Grp Residuals
Sum of Squares    0.33428  36.96518   1.50105 227.49594
Deg. of Freedom         1         2         2        70

Residual standard error: 1.802760
Estimated effects may be unbalanced



Thanks,
Gang



On Aug 3, 2007, at 4:09 PM, Doran, Harold wrote:

> Gang:
>
> I think what Peter is asking for is for you to put some of your output
> in an email. If the values of the fixed effects are the same across
> models, but the F-tests are different, then there is a whole other
> thread we will point you to for an explanation. (I don't presume to
> speak for other people, btw, and I'm happy to stand corrected)
>
>> -----Original Message-----
>> From: r-help-bounces at stat.math.ethz.ch
>> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Gang Chen
>> Sent: Friday, August 03, 2007 4:01 PM
>> To: Peter Dalgaard
>> Cc: r-help at stat.math.ethz.ch
>> Subject: Re: [R] lme and aov
>>
>> Thanks for the response!
>>
>> It is indeed a balanced design. The results are different in
>> the sense all the F tests for main effects are not the same.
>> Do you mean that a random interaction is modeled in the aov
>> command? If so, what would be an equivalent command of aov to
>> the one with lme?
>>
>> Thanks,
>> Gang
>>
>> On Aug 3, 2007, at 3:52 PM, Peter Dalgaard wrote:
>>
>>> Gang Chen wrote:
>>>> I have a mixed balanced ANOVA design with a
>> between-subject factor
>>>> (Grp) and a within-subject factor (Rsp). When I tried the
>> following
>>>> two commands which I thought are equivalent,
>>>>
>>>>> fit.lme <- lme(Beta ~ Grp*Rsp, random = ~1|Subj, Model);  >
>>>> fit.aov <- aov(Beta ~ Rsp*Grp+Error(Subj/Rsp)+Grp, Model);
>>>> 	
>>>> I got totally different results. What did I do wrong?
>>>>
>>>>
>>> Except for not telling us what your data are and what you mean by
>>> "totally different"?
>>>
>>> One model has a random interaction between Subj and Rsp, the other
>>> does not. This may make a difference, unless the
>> interaction term is
>>> aliased with the residual error.
>>>
>>> If your data are unbalanced, aov is not guaranteed to give
>> meaningful
>>> results.
>>>
>>>    -pd
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> 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 mailing list