Learn R Programming

HH (version 3.1-47)

ancova: Compute and plot oneway analysis of covariance

Description

Compute and plot oneway analysis of covariance. The result object is an ancova object which consists of an ordinary aov object with an additional trellis attribute. The trellis attribute is a trellis object consisting of a series of plots of y ~ x. The left set of panels is conditioned on the levels of the factor groups. The right panel is a superpose of all the groups.

Usage

ancova(formula, data.in = NULL, ...,
       x, groups, transpose = FALSE,
       display.plot.command = FALSE,
       superpose.level.name = "superpose",
       ignore.groups = FALSE, ignore.groups.name = "ignore.groups",
       blocks, blocks.pch = letters[seq(levels(blocks))],
       layout, between, main,
       pch=trellis.par.get()$superpose.symbol$pch)

panel.ancova(x, y, subscripts, groups, transpose = FALSE, ..., coef, contrasts, classes, ignore.groups, blocks, blocks.pch, blocks.cex, pch)

## The following are ancova methods for generic functions. # S3 method for ancova anova(object, ...)

# S3 method for ancova predict(object, ...)

# S3 method for ancova print(x, ...) ## prints the anova(x) and the trellis attribute

# S3 method for ancova model.frame(formula, ...)

# S3 method for ancova summary(object, ...)

# S3 method for ancova plot(x, y, ...) ## standard lm plot. y is always ignored.

# S3 method for ancova coef(object, ...)

Arguments

formula

A formula specifying the model.

data.in

A data frame in which the variables specified in the formula will be found. If missing, the variables are searched for in the standard way.

Arguments to be passed to aov, such as subset or na.action.

x

Covariate in ancova, needed for plotting when the formula does not include x. "aov" object in print.ancova, to match the argument of the print generic function. Variable to plotted in "panel.ancova".

groups

Factor. Needed for plotting when the formula does not include groups after the conditioning bar "|".

transpose

S-Plus: The axes in each panel of the plot are transposed. The analysis is identical, just the axes displaying it have been interchanged. R: no effect.

display.plot.command

The default setting is usually what the user wants. The alternate value TRUE prints on the console the command that draws the graph. This is strictly for debugging the ancova command.

superpose.level.name

Name used in strip label for superposed panel.

ignore.groups

When TRUE, an additional panel showing all groups together with a common regression line is displayed.

ignore.groups.name

Name used in strip label for ignore.groups panel.

pch

Plotting character for groups.

blocks

Additional factor used to label points in the panels.

blocks.pch

Alternate set of labels used when a blocks factor is specified.

blocks.cex

Alternate set of cex used when a blocks factor is specified.

layout

The layout of multiple panels. The default is a single row. See details.

between

Space between the panels for the individual group levels and the superpose panel including all groups.

main

Character with a main header title to be done on the top of each page.

y,subscripts

In "panel.ancova",

object

An "aov"

coef, contrasts, classes

Internal variables used to communicate between ancova and panel.ancova. They keep track of the constant or different slopes and intercepts in each panel of the plot.

Value

The result object is an ancova object which consists of an ordinary aov object with an additional trellis attribute. The default print method is to print both the anova of the object and the trellis attribute.

Details

The ancova function does two things. It passes its arguments directly to the aov function and returns the entire aov object. It also rearranges the data and formula in its argument and passes that to the xyplot function. The trellis attribute is a trellis object consisting of a series of plots of y ~ x. The left set of panels is conditioned on the levels of the factor groups. The right panel is a superpose of all the groups.

References

Heiberger, Richard M. and Holland, Burt (2015). Statistical Analysis and Data Display: An Intermediate Course with Examples in R. Second Edition. Springer-Verlag, New York. https://link.springer.com/us/book/9781493921218

See Also

ancova-class aov xyplot. See ancovaplot for a newer set of functions that keep the graph and the aov object separate.

Examples

Run this code
# NOT RUN {
data(hotdog)

## y ~ x                     ## constant line across all groups
ancova(Sodium ~ Calories,     data=hotdog, groups=Type)

## y ~ a                     ## different horizontal line in each group
ancova(Sodium ~            Type, data=hotdog, x=Calories)

## This is the usual usage
## y ~ x + a  or  y ~ a + x  ## constant slope, different intercepts
ancova(Sodium ~ Calories + Type, data=hotdog)
ancova(Sodium ~ Type + Calories, data=hotdog)

## y ~ x * a  or  y ~ a * x  ## different slopes, and different intercepts
ancova(Sodium ~ Calories * Type, data=hotdog)
ancova(Sodium ~ Type * Calories, data=hotdog)

## y ~ a * x ## save the object and print the trellis graph
hotdog.ancova <- ancova(Sodium ~ Type * Calories, data=hotdog)
attr(hotdog.ancova, "trellis")


## label points in the panels by the value of the block factor
data(apple)
ancova(yield ~ treat + pre, data=apple, blocks=block)

## Please see
##      demo("ancova")
## for a composite graph illustrating the four models listed above.
# }

Run the code above in your browser using DataLab