[R] Analysis of Varience question.
Douglas Bates
bates at stat.wisc.edu
Wed Sep 12 19:38:59 CEST 2001
Shawn Way <sway at tanox.com> writes:
> I'm trying to use R for some of the analysis shown in Box, Hunter and Hunter
> (1979, I believe) using the aov function.
1978 actually
> I'm using the first example in
> chapter 6, where they are determining the analysis of varience between 4
> treatments.
>
> In this example, the are determineing the analysis between and within
> treatments, which I can get by
>
> aov(response~treatment+Error(treatment))
>
> Where response is the response data (numeric) and treatment is the treatment
> type (Factor).
In this case you could use
aov(response ~ treatment)
> In the next example, they determine the analysis of varience of the grand
> average with these parameters, ie something like
> response~average(response)+treatment+Error(treatment)
> Giving the sum of the squares, the degrees of freedowm, etc.
> Is this possible with the current setup of R?
Yes but bear in mind that Box, Hunter and Hunter are providing that
example for pedagogical reasons, not because one would usually form
the analysis of variance table in that way.
Analysis of variance tables in R do not give the contribution of the
constant although the underlying model does, by default, include a
constant. To get the constant into the analysis of variance table you
must introduce an explicit constant term into the model and exclude
the implicit constant term. The following transcript shows this
> BHH6 <- data.frame(diet = rep(LETTERS[1:4], c(4, 6, 6, 8)),
+ Time = c(62,60,63,59,63,67,71,64,65,66,68,66,71,67,68,68,
+ 56,62,60,61,63,64,63,59))
> aov(Time ~ diet, data = BHH6) # default representation of aov model
Call:
aov(formula = Time ~ diet, data = BHH6)
Terms:
diet Residuals
Sum of Squares 228 112
Deg. of Freedom 3 20
Residual standard error: 2.366432
Estimated effects may be unbalanced
> summary(aov(Time ~ diet, data = BHH6)) # an ANOVA table
Df Sum Sq Mean Sq F value Pr(>F)
diet 3 228.0 76.0 13.571 4.658e-05 ***
Residuals 20 112.0 5.6
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
> BHH6$const <- rep(1, nrow(BHH6)) # add a constant column to the data frame
> summary(aov(Time ~ const + diet - 1, data = BHH6))
Df Sum Sq Mean Sq F value Pr(>F)
const 1 98304 98304 17554.286 < 2.2e-16 ***
diet 3 228 76 13.571 4.658e-05 ***
Residuals 20 112 6
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
Notice that the last call to aov uses a formula with "- 1" in it
to remove the implicit constant term from the model.
Box, Hunter and Hunter (or BH^2, as we know it) is a great book but
the computational methods described there are rather dated. The
book was published nearly 25 years ago and at that time it had been
around in the form of class notes for many, many years. Bill Hunter
used to joke that the book had reached the age of majority (i.e. was
21 years old) before it was published.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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