# [R] ANOVA: Factorial designs with a separate control

Charles C. Berry cberry at tajo.ucsd.edu
Wed Aug 15 19:29:54 CEST 2007

```
Lamac,

The ANOVA shown in 'pamph14' may not be suitable for your data.

If the replicates are separate experiments or blocks, you will need to
become familiar with the nlme package and the lme function in it. ( Your
labelling of replicates suggests that this is the case, viz. no
A==1 & B == 3 & replicate == 1 combination was found.) There is an
excellent book that serves as reference for that package (Pinheiro, J.C.,
and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.)
If this turns out to be too 'deep' for you, you will do best to find a
statistician who is well versed in linear mixed effects models to help
you.

--

However, if the replicates are independent realizations, then

> # copy Lamac's data to the clipboard first
>
> fit <- lm ( response ~ I( A==0 ) + as.factor(A)*as.factor(B), dat )
> anova( fit )

Gives you the sequential sums of squares ( your design is unbalanced hence
the 'sequential' qualifier ). If you want what Wendy Bergerud (author of
'pamph14') called the 'TREAT' sum of squares, you can add all but the
'Residuals' SS. Likewise with the df.

You can also get the TREAT ANOVA table directly by revising the formula in
lm() above. The resulting formula is very simple, and you should have some
fun - as well as strengthen your skill with formulas in R - trying to find
it. You may want to review Chapter 11 Statistical models in R in
An Introduction to R before trying this.

HTH,

Chuck

On Tue, 14 Aug 2007, lamack lamack wrote:

> Dear all, I would like to run in R the anova showed in the following
> pamphlet.
>
> http://www.for.gov.bc.ca/hre/biopamph/pamp14.pdf
>
> For A = 0 and B =0 I have de control group.
>
> Best regards.
>
> A            B       replication   response
> 0             0             1         24
> 0             0             2         27
> 0             0             3         36
> 0             0             4         28
> 0             0             5         32
> 1             1             1         43
> 1             1             2         39
> 1             1             3         32
> 1             1             4         36
> 1             1             5         50
> 1             2             1         34
> 1             2             2         35
> 1             2             3         45
> 1             2             4         37
> 1             2             5         52
> 1             3             2         34
> 1             3             3         35
> 1             3             4         58
> 1             3             5         35
> 1             4             1         26
> 1             4             2         49
> 1             4             3         44
> 1             4             4         39
> 1             4             5         37
> 1             5             1         37
> 1             5             2         32
> 1             5             3         33
> 1             5             4         37
> 1             5             5         36
> 2             1             1         43
> 2             1             2         33
> 2             1             3         33
> 2             1             4         38
> 2             1             5         41
> 2             2             1         42
> 2             2             2         45
> 2             2             3         34
> 2             2             4         29
> 2             2             5         33
> 2             3             1         33
> 2             3             2         42
> 2             3             3         30
> 2             3             4         28
> 2             3             5         40
> 2             4             1         39
> 2             4             2         33
> 2             4             3         20
> 2             4             4         29
> 2             4             5         24
> 2             5             1         37
> 2             5             2         46
> 2             5             3         33
> 2             5             4         27
> 2             5             5         34
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help