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

Jonathan Baron baron at psych.upenn.edu
Mon Nov 5 13:37:27 CET 2007


On 11/04/07 16:34, 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).

At the risk of getting in trouble, let me suggest another approach.
Compute the relevant terms for each subject, then do a t test
comparing your two groups.  The t test does not assume equal sized
groups.  Yuelin Li, in our "Notes on the use of R ..." shows how to
use a t test to check a design very similar to what you suggest:
http://www.psych.upenn.edu/~baron/rpsych/rpsych.html (section 6.10, I
think, perhaps elsewhere too).

You can do this either with a loop or with the lmList() function in
the lme4 package (which is not discussed yet in our "Notes...").

For example, with a loop, you would compute
CS[i] <- RTredsquare[i] - RTbluesquare[i] - RTredcircle[i] +
 RTbluecircle[i]
and then do t.test(CS ~ Group) to see if your two groups differ in the
interaction effect.  It is easier with lmList.  You don't need the
loop.

I do think that nlme is going to replace a lot of standard approaches
in psychology.  (I am almost to the point of understanding it.)  But I
don't think it is necessary for the kind of design you describe.

Jon
-- 
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron



More information about the R-help mailing list