[R] Within Subject ANOVA question

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Jun 2 08:43:19 CEST 2009


tsunhin wong wrote:
> Dear R users,
> 
> I have copied for following table from an article on "Using confidence
> intervals in within-subject designs":
> 
> Subject 1sec 2sec 5sec
> 1 10 13 13 12.00
> 2 6 8 8 7.33
> 3 11 14 14 13.00
> 4 22 23 25 23.33
> 5 16 18 20 18.00
> 6 15 17 17 16.33
> 7 1 1 4 2.00
> 8 12 15 17 14.67
> 9 9 12 12 11.00
> 10 8 9 12 9.67
> 
> I rearranged the data this way:
>> subject<-factor(c(1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10))
>> condition<-factor(c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,5,5,5,5,5,5,5,5,5,5))
>> recall<-factor(c(10,6,11,22,16,15,1,12,9,8,13,8,14,23,18,17,1,15,12,9,13,8,14,25,20,17,4,17,12,12))
>> example<-cbind(subject,condition,recall)
> 
> Using ANOVA (aov), I should have DF for condition = 2, DF of subjects
> = 9, Interaction DF = 18
> And a term for mean square of interaction. (0.61)

Your data are not factors when you get to use them, hence the 1DF. It is 
the cbind() that is doing you in. Try

example <- data.frame(subject,condition,recall)

However, "recall" should _not_ be a factor.

-p

> But, I have something like below instead:
>> aov.recall <- aov(recall~condition + Error(subject/condition),data=as.data.frame(example))
>> summary(aov.recall)
> 
> Error: subject
>           Df Sum Sq Mean Sq F value Pr(>F)
> Residuals  1 12.898  12.898
> 
> Error: subject:condition
>           Df Sum Sq Mean Sq
> condition  1 34.505  34.505
> 
> Error: Within
>           Df Sum Sq Mean Sq F value Pr(>F)
> condition  1   3.22    3.22  0.1378 0.7135
> Residuals 26 607.54   23.37
> 
> The within-subject (repeated measure) anova of R seems to be a bit
> subtle for me, please point out the errors that I have made if you
> can.
> Thank you very much!
> 
> - John
> 
> ______________________________________________
> 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.


-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list