aov
Fit an Analysis of Variance Model

Description

Returns an object of class "aov", "aovlist", or "maov" that contains the analysis of variance for the specified model.

Usage



aov(formula, data = NULL, projections = FALSE, qr = TRUE, 
    contrasts = NULL, ...)

## S3 method for class 'aov': print(x, intercept = FALSE, tol = .Machine$double.eps^0.5, ...) ## S3 method for class 'aovlist': print(x, ...)

Arguments

formula a formula or terms describing the model.
data a data frame in which the objects named in the formula are to be found. If data is omitted, the objects in formula should be on your current search list.
projections a logical flag: if TRUE, the result includes a projections component, which is the result of a call to the proj 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.
qr a logical flag: if TRUE, the orthogonal decomposition is returned. See lm.fit.qr for details.
contrasts a list giving contrasts for some or all of the factors appearing in the model formula. An element in the list should have the same name as the factor variable it encodes, and it should be either a contrast matrix (any full-rank matrix with as many rows as there are levels in the factor), or a function that computes such a matrix given the number of levels.
... additional arguments to be passed to the lm function; for details, see the help file for 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.

Details

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.
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).
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).
Value
an object describing the fit. There are two cases, depending on whether an Error term is included in the model formula.
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 aov.object and lm.object 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 components; instead, the entire aovlist object has call and terms attributes.
References
Books on the analysis of variance include:
Daniel, C. 1976. Applications of Statistics to Industrial Experimentation. New York, NY: Wiley.
Heiberger, R. M. 1989. Computation for the Analysis of Designed Experiments. New York, NY: John Wiley & Sons.
Hicks, C. R. 1982. Fundamental Concepts in the Design of Experiments. Third Edition. New York, NY: Holt, Rinehart and Winston.
Chambers, J. M., Freeny, A., and Heiberger, R. M. 1992. Analysis of variance; designed experiments. Statistical Models in S. Pacific Grove, CA.: Wadsworth & Brooks/Cole. Chapter 5.
Box, G. E. P., Hunter, W. G. and Hunter, J. S. 1978. Statistics for Experimenters. New York, NY: John Wiley & Sons.
Scheffe, H. 1959. The Analysis of Variance. New York, NY: John Wiley & Sons.
See Also
aov.object, summary.aov, model.tables, coef, dummy.coef, eff.aovlist, model.frame, se.aov, se.contrast, terms, Error, factor, ordered, lm, lm.object, lm.fit.qr, alias, design.table, fac.design, friedman.test, kruskal.test, model.matrix, oa.design, plot.design, plot.factor, proj, raov, varcomp.
Examples
# Fit main effects and 2-factor interactions.
cat.aov2 <- aov(Yield ~ .^2, data = Sdatasets::catalyst)
# Look at ANOVA table.
summary(cat.aov2)

gun.aov <- aov(Rounds ~ Method + Physique/Team, data = Sdatasets::gun)

# Use an attached data frame instead of the "data" argument. # (Not recommended) attach(Sdatasets::guayule) # Split plot design. aov(plants ~ variety * treatment + Error(flats)) tgaov <- aov(plants ~ variety * treatment + Error(flats), contrasts = list(treatment = contr.treatment)) detach("Sdatasets::guayule")

# Other examples. P <- ordered(rep(1:3, rep(3,3))) N <- ordered(rep(1:3,3)) Plants <- c(449, 413, 326, 409, 358, 291, 341, 278, 312) Plants <- Plants/12 cox164.df <- data.frame(Plants, P, N) cox164.aov <- aov(Plants ~ N * P, data = cox164.df, weights = rep(12,9), qr = TRUE) summary(cox164.aov) attributes(cox164.aov)

cox164.aovlist <- aov(Plants ~ N * P + Error(N/P), data = cox164.df) summary(cox164.aovlist) attributes(cox164.aovlist)

Package stats version 6.1.1-7
Package Index