[R] Why can repeated measures anova with within & between subjects design not be done if group sizes are unbalanced?

Charles C. Berry cberry at tajo.ucsd.edu
Sun Nov 4 18:28:15 CET 2007




'nowhere documented' ??

As the posting guide suggests, you could perform a search using

> RSiteSearch("repeated measures", restric="functions")


say.

That generates an inventory of functions that pertain to repeated 
measures designs.

And once you have browsed through that you might focus on


> library(nlme) # load a library with nifty mixed model stuff
> ?lme          # find out how to fit linear mixed models 
> example(lme)  # run some examples

If that is not enough to get you started, the book

J. C. Pinheiro and D. M. Bates (2000), Mixed-Effects Models in S and 
S-Plus., Springer, ISBN 0-387-98957-0

documents all the stops and whistles of the nlme library.

Chuck


On Sun, 4 Nov 2007, Gilbert G wrote:

> Dear R people:
>
> I wish to switch from SPSS to R, but there is one particular type of
> ANOVA design that cannot be done in R.  Or more likely, it can be
> done, but it is nowhere documented.
>
> The problem is typical for psychologists:
> You have a repeated measures design with different groups of subjects.
> Now, this can be done with the aov command, but the number of
> subjects in both groups must be equal (i.e., balanced design).  SPSS
> allows for unbalanced designs as well.
>
> If you are still with me, let me just give you an example of what R
> can and cannot do so far.  Imagine I have a 2x2 within subjects design
> and I have 2 groups (e.g., group healthy and patients, which is stored
> in MyGroup).  And imagine I measure reaction time RT in four
> conditions, say, in a color condition (red vs green) and in a shape
> condition (square vs circle).
>
> Now, in R you would have something like, as anybody who does balanced
> repeated measures anova's might know:
>
> aov( RT ~ color * shape * MyGroup + Error( Subjects/( color*shape) )
>
> In spss you would have something like this (of course with the data
> organized slightly differently :
>
> GLM
> x1 x2 x3 x4 BY MyGroup
> /WSFACTOR = color 2 Polynomial shape 2 Polynomial
> /METHOD = SSTYPE(3)
> /CRITERIA = ALPHA(.05)
> /WSDESIGN = color shape color*shape
> /DESIGN = VAR00001 .
>
> Ok, the question is.  If the group sizes are different (say 10 people
> in one group and 12 people in the other group) R is going to give the
> wrong answer.  Of course that is not R's fault.
>
> BUT MY QUESTION IS: HOW TO GET THE UNBALANCED REPEATED MEASURES ANOVA RIGHT?
>
> Thanks for the answer!
>
> ______________________________________________
> R-help at r-project.org 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.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list