[R] ANOVA for nested design
Jinsong Zhao
jszhao at yeah.net
Fri May 15 17:20:22 CEST 2015
Hi there,
The following is a simple design. A and B are factors with their levels
randomly selected. In other words, A and B are random.
The data is recorded in "abc", as:
> dput(abc)
structure(list(water = c(12.1, 12.1, 12.8, 12.8, 14.4, 14.4,
14.7, 14.5, 23.1, 23.4, 28.1, 28.8), A = structure(c(1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("1", "2",
"3"), class = "factor"), B = structure(c(1L, 1L, 2L, 2L, 3L,
3L, 4L, 4L, 5L, 5L, 6L, 6L), .Label = c("1", "2", "3", "4", "5",
"6"), class = "factor")), .Names = c("water", "A", "B"), row.names = c(NA,
-12L), class = "data.frame")
I run ems from afex package:
> ems(n ~ A*B, nested="A/B", random="AB")
VarianceComponent
Effect e B A
A 1 n nb
B 1 n
e 1
attr(,"terms")
[1] n a b
So, the ANOVA for this design is something like:
> summary(aov(water ~ A + Error(B), abc))
Error: B
Df Sum Sq Mean Sq F value Pr(>F)
A 2 416.8 208.39 22.68 0.0155 *
Residuals 3 27.6 9.19
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
Residuals 6 0.31 0.05167
> summary(aov(water ~ B + Error(A), abc))
Error: A
Df Sum Sq Mean Sq
B 2 416.8 208.4
Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
B 3 27.57 9.190 177.9 2.99e-06 ***
Residuals 6 0.31 0.052
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
Is it possible to write the above two aov(...) into one aov(...)?
Any suggestions will be really appreciated. Thanks in advance.
Best regards,
Jinsong
More information about the R-help
mailing list