[R] Within Subject ANOVA question

Mike Lawrence Mike.Lawrence at dal.ca
Tue Jun 2 00:51:37 CEST 2009


Although you factorized subject and condition when you created them as
separate objects, this didn't survive cbind() then as.data.frame(),
thus

> example<-data.frame(cbind(subject,condition,recall))
> str(example)
'data.frame':	30 obs. of  3 variables:
 $ subject  : int  1 2 3 4 5 6 7 8 9 10 ...
 $ condition: int  1 1 1 1 1 1 1 1 1 1 ...
 $ recall   : int  6 3 7 16 12 11 1 8 5 4 ...

Use this alternative construction (note that I omit factorization of
the response variable, recall, because this shouldn't be a factor)

> 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<-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<-data.frame(subject,condition,recall)
> str(example)
'data.frame':	30 obs. of  3 variables:
 $ subject  : Factor w/ 10 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ condition: Factor w/ 3 levels "1","2","5": 1 1 1 1 1 1 1 1 1 1 ...
 $ recall   : num  10 6 11 22 16 15 1 12 9 8 ...
> aov.recall <- aov(recall~condition + Error(subject/condition),data=example)
> summary(aov.recall)

Error: subject
          Df Sum Sq Mean Sq F value Pr(>F)
Residuals  9 942.53  104.73

Error: subject:condition
          Df Sum Sq Mean Sq F value    Pr(>F)
condition  2 52.267  26.133  42.506 1.519e-07 ***
Residuals 18 11.067   0.615
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


On Mon, Jun 1, 2009 at 7:31 PM, tsunhin wong <thjwong at gmail.com> 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)
>
> 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.
>



-- 
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar

~ Certainty is folly... I think. ~




More information about the R-help mailing list