"aov"
,
"aovlist"
, or
"maov"
that contains the analysis of variance for the specified model.
aov(formula, data=<<see below>>, projections=F, qr=F, contrasts=NULL, ...)
data
is omitted, the objects in
formula
should be on your current search list.
TRUE
, the result includes a
projections
component, which is the result of a call to the
function.
Setting
projections=TRUE
adds substantially to the size of the returned object, as it includes a matrix with as many rows as observations and as many columns as there are terms in the model.
If you plan to use projections, however, it is more efficient to compute them during the fit rather than by calling
proj
later.
TRUE
, the orthogonal decomposition is returned. See
for details.
lm
. Two possibilities are
na.action
, which is a function that filters missing values from the data frame, and
subset
, which is a vector that selects observations (rows) from the data to include in the analysis.
If there is no
Error
term in the model, the computed object is of class
"aov"
.
If there is no
Error
term and the formula includes multiple responses, the returned object is of class
"maov"
.
Both of these inherit from the class of linear models,
"lm"
and
"mlm"
, respectively.
See the
and
help files for complete details.
If the model formula includes an
Error
term, the object returned by
aov
has class
"aovlist"
.
An object of this class is a list of
aov
objects in the form described in the
aov.object
help file.
Each element in the list represents one stratum of the model.
The individual
aov
objects do not have
call
or
terms
components; instead, the entire
aovlist
object has
call
and
terms
attributes.
The
aov
function fits analysis of variance models, typically from designed experiments.
Usually, the variables on the right side of the tilde operator (
~
) in the formula are of class
"factor"
or
"ordered"
.
That is, the predictor variables are usually categorical in this type of analysis, though numerical variables are also allowed.
The order in which variables appear in the formula is undoubtedly important for the interpretation of the model (see below).
Use the
summary
function on the output from
aov
to see the ANOVA table for the model. You can also use the
model.tables
function to see tables of means, effects, factorial effects, or residuals for the model.
Formulas. A plus sign (
+
) separates terms in the model formula. You specify interactions with colons.
For example, the term
A:B
is the interaction between the factors
A
and
B
.
The
*
operator provides the interaction plus the main effects. Thus,
A*B*C
expands to three main effects (
A+B+C
), three two-factor interactions (
A:B
,
B:C
, and
A:C
) and one three-factor interaction (
A:B:C
).
Terms may be subtracted from the model if they are specified elsewhere in the formula.
For example,
A*B*C - B:C
contains only two two-factor interactions.
The term
B%in%A
means that
B
is nested within
A
, and the term
A/B
expands to
A + B%in%A
.
The precedence of these operators follows the usual S Language precedence. See the chapter "Specifying Models in S-PLUS" in the Guide to Statistics for additional details.
Unbalanced Models.
If effects are not orthogonal, then the order that the terms appear in the model formula is significant.
For example, if the data are unbalanced, a model with
A*B
will give sums of squares that are different than those computed by a model including
B*A
.
The
aov
function produces sequential sums of squares by default (Type I sums of squares in the notation of SAS GLM).
You can use the
ssType3
function to compute Type III sums of squares.
Multiple Strata. The formula may optionally specify special blocking or error structure if it includes a term that calls the
Error
function.
For example, the formula
response ~ time*concentration + Error(blocks)
defines an error stratum for the model according to the factor variable
blocks
.
The resulting model includes two error strata,
blocks
and
Within
.
In the case of multiple error strata,
aov
fits a separate model for each stratum.
The response is projected onto each term in the error model, and these projections are used to fit separate models.
There can be only one
Error
term in a formula.
However, there may be more than one term inside the error function.
For example, the error term for a split-plot design would be
Error(plots)
while the term for a split-split-plot would be
Error(plots + subplots)
.
The order of the terms inside of
Error
is important. See Heiberger (1989) for more information on error strata.
Repeated Measures. Using an error stratum is also the way to produce a univariate analysis of a repeated measures design. For example, the appropriate error term for a design in which
subject
is the repeated measure would be
Error(subject)
.
Books on the analysis of variance include:
Box, G.E.P., Hunter, W.G. and Hunter, J.S. (1978). Statistics for Experimenters. New York: Wiley.
Daniel, C. (1976). Applications of Statistics to Industrial Experimentation. New York: Wiley.
Heiberger, R.M. (1989). Computation for the Analysis of Designed Experiments. New York: Wiley.
Hicks, C.R. (1982). Fundamental Concepts in the Design of Experiments (3rd Edition). New York: Holt, Rinehart and Winston.
Scheffe, H. (1959). The Analysis of Variance. New York: Wiley.
# Fit main effects and 2-factor interactions. cat.aov2 <- aov(Yield ~ .^2, data=catalyst) # Look at ANOVA table. summary(cat.aov2) gun.aov <- aov(Rounds ~ Method + Physique/Team, data=gun) # Use an attached data frame instead of the "data" argument. attach(guayule) # Split plot design. aov(plants ~ variety * treatment + Error(flats)) tgaov <- aov(plants ~ variety * treatment + Error(flats), contrasts = list(treatment = contr.treatment)) detach("guayule")