[R] Fixed and random factors in aov()

Sven Garbade garbade at mip.paed.uni-muenchen.de
Fri Jul 16 10:36:53 CEST 2004


Hi, 
I'm confused about how to specify random and fixed factors in an aov()
term. I tried to reproduce a textbook example: One fixed factor (Game, 4
levels) and one random factor (Store, 12 levels), response is Points.
The random factor Store is nested in Game. I tried 

> str(kh.df)
`data.frame':	48 obs. of  4 variables:
 $ Subj  : Factor w/ 48 levels "vp1","vp10","vp11",..: 1 12 23 34 44... 
 $ Game  : Factor w/ 4 levels "S1","S2","S3",..: 1 1 1 1 1 1 1 1 ... 
 $ Store : Factor w/ 12 levels "KH1","KH10","KH11",..: 1 1 1 1 5 ... 
 $ Points: num  7 9 12 7 6 5 8 6 9 6 ...

> summary(aov(Points ~ Game + Error(Game:Store),dat=kh.df))

Error: Game:Store
          Df Sum Sq Mean Sq F value  Pr(>F)  
Game       3 391.50  130.50  5.9771 0.01934 *
Residuals  8 174.67   21.83                  
---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 

Error: Within
          Df  Sum Sq Mean Sq F value Pr(>F)
Residuals 36 149.500   4.153               
Warning message: 
Error model is singular in: aov(Points ~ Game + Error(Game:Store), dat =
kh.df) 

which gives me the correct F-statistic for the fixed factor Game and 

> summary(aov(Points ~ Game + Game:Store,dat=kh.df))
            Df Sum Sq Mean Sq F value    Pr(>F)    
Game         3 391.50  130.50 31.4247 3.707e-10 ***
Game:Store   8 174.67   21.83  5.2575 0.0002126 ***
Residuals   36 149.50    4.15                      
---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 

which calcultes the correct Game:Store F statistic but the incorrect
F value for Game (because its a fixed factor). I'm wondering about how
to specify a correct model formula for the fixed and random factors with
an appropiate Error() term.

Thanks, Sven




More information about the R-help mailing list