Learn R Programming

lessR (version 2.6)

ANOVA: Analysis of Variance

Description

Abbreviation: av, av.brief

Analysis of variance from the R aov function plus graphics and effect sizes. Permitted designs are one-way between groups, two-way between groups and randomized blocks with one treatment factor with one observation for each treatment and block combination.

Usage

ANOVA(my.formula, dframe=mydata, brief=FALSE, digits.d=NULL, 
         rb.points=TRUE, pdf=FALSE, pdf.width=5, pdf.height=5, ...)

av(...)

av.brief(..., brief=TRUE)

Arguments

my.formula
Standard R formula for specifying a model.
dframe
The default name of the data frame that contains the data for analysis is mydata, otherwise explicitly specify.
brief
Extent of displayed results.
digits.d
For the Basic Analysis, it provides the number of decimal digits. For the rest of the output, it is a suggestion only.
rb.points
For a randomized block design, a plot of the fitted value for each cell is obtained as well as the individual data values. Set to FALSE to suppress the data values.
pdf
Indicator as to if the graphic files should be saved as pdf files instead of directed to the standard graphics windows.
pdf.width
Width of the pdf file in inches.
pdf.height
Height of the pdf file in inches.
...
Other parameter values for R function lm which provides the core computations.

Details

OVERVIEW The one-way ANOVA with Tukey HSD and plot based on the R functions aov, TukeyHSD, and provides summary statistics for each level. Two-factor ANOVA also provides an interaction plot of the means with interaction.plot as well as a table of means and other summary statistics. The two-factor analysis can be between groups or a randomized blocked design. Residuals are displayed by default. Tukey HSD comparisons and residuals are not displayed if brief=TRUE.

MODEL SPECIFICATION In the following specifications, Y is the response variable, X is a treatment variable and Blocks is the blocking variable. The distinction between the one-way randomized blocks and the two-way between groups models is not the variable names, but rather the delimiter between the variable names. Use * to indicate a two-way crossed between groups design and + for a randomized blocks design. one-way between groups: ANOVA(Y ~ X) one-way randomized blocks: ANOVA(Y ~ X + Blocks) two-way between groups: ANOVA(Y ~ X1 * X2) For more complex designs, use the standard R function aov upon which ANOVA depends.

BALANCED DESIGN The design for the two-factor analyses must be balanced. A check is performed and processing ceases if not balanced. For unbalanced designs, consider the function lmer in the lme4 package.

DECIMAL DIGITS The number of decimal digits displayed on the output is, by default, the maximum number of decimal digits for all the data values of the response variable. Or, this value can be explicitly specified with the digits.d parameter.

See Also

aov, TukeyHSD, interaction.plot

Examples

Run this code
# create simulated data, no population mean difference
# X has two values only, Y is numeric
# put into a data frame
n <- 12
X <- sample(c("Group1","Group2","Group3"), size=n, replace=TRUE)
Y <- round(rnorm(n=n, mean=50, sd=10), 2)
mydata <- data.frame(X,Y)

# analyze data with formula version
# variable names and levels of X are automatically obtained from data
# although data frame not attached, reference variable names directly
ANOVA(Y ~ X)
# short name
av(Y ~ X)

# variable of interest is in a data frame which is not the default mydata
# access the data frame in the lessR dat.twogroup data set
# although data not attached, access the variables directly by their name
data(dataGroups2)
ANOVA(ShipTime ~ Supplier, dframe=dataGroups2)

# two-factor between-groups ANOVA with replications and interaction
ANOVA(breaks ~ wool * tension, dframe=warpbreaks)

# randomized blocks design with the second term the blocking factor
ANOVA(breaks ~ wool + tension, dframe=warpbreaks)

Run the code above in your browser using DataLab