[R] anova question
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Fri Mar 3 23:04:23 CET 2000
Ulf Mehlig <umehlig at uni-bremen.de> writes:
> I have a probably very naive question about the R anova/aov functions:
> I've found in several text books with descriptions of anova procedures
> that, in nested anova (specifying the model "X~A/B", B being a factor
> specifying treatments, and A groups of samples within each treatment),
> the mean square for "among treatments" is divided by the mean square
> "within treatment among sample groups"; R seems to divide by the
> residual mean square. So, in the following (silly) example I would
> have expected a F value of 1.496/0.785=1.905732:
>
> > test <- data.frame(x=rnorm(12*5), a=rep(1:12,rep(5,12)), b=rep(1:5,rep(12,5)))
> > summary(aov(x ~ factor(a)/factor(b), data=test))
> Df Sum Sq Mean Sq F value Pr(>F)
> factor(a) 11 16.456 1.496 1.8357 0.07647 .
> factor(a):factor(b) 4 3.142 0.785 0.9638 0.43689
> Residuals 44 35.859 0.815
>
> As I am certainly misunderstanding something, I would appreciate a
> hint, and maybe a literature recommendation!
>
> Many thanks,
> Ulf
Um,
If B is the treatment you want B/A, I believe?
I don't think the data frame looks like I think you think it looks:
x a b
1 0.9421894166 1 1
2 -0.6615090815 1 1
3 0.6659020398 1 1
4 0.6384607529 1 1
5 0.2785534174 1 1
6 -0.5093066357 2 1
7 -0.1765458342 2 1
8 -0.0003846756 2 1
9 -0.5523574783 2 1
10 1.4351543109 2 1
11 0.2338159511 3 1
12 0.2701585951 3 1
13 0.3781168982 3 2
I think you expected this:
> test <- data.frame(x=rnorm(12*5), a=rep(1:12,5), b=rep(1:5,rep(12,5)))
> summary(aov(x ~ factor(b)/factor(a), data=test))
Df Sum Sq Mean Sq
factor(b) 4 5.367 1.342
factor(b):factor(a) 55 56.619 1.029
I.e the b:a effect leaves no DF for residuals. So you remove the term
and use that SS for residual.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list