[R] Fixed and random factors in aov()
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.ac.be
Fri Jul 16 10:52:29 CEST 2004
Hi Sven,
I think that you could also use `lme', i.e., something like:
library(nlme)
lme1 <- lme(Points~Game, random=~1|Store, data=kh.df)
lme2 <- lme(Points~Game, random=~1|Store/Game, data=kh.df)
anova(lme1)
anova(lme2)
anova(lme1, lme2)
I hope this helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Doctoral Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Sven Garbade" <garbade at mip.paed.uni-muenchen.de>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, July 16, 2004 10:36 AM
Subject: [R] Fixed and random factors in aov()
> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list