Anova Tables for Various Statistical Models
Description
Calculates typeII or typeIII analysisofvariance tables for
model objects produced by lm
, glm
, multinom
(in the nnet package), polr
(in the MASS
package), coxph
(in the survival package),
coxme
(in the coxme pckage),
svyglm
and svycoxph
(in the survey package), rlm
(in the MASS package),
lmer
(in the lme4 package),
lme
(in the nlme package),
clm
and clmm
(in the ordinal package), and (by the default method) for most
models with a linear predictor and asymptotically normal coefficients (see details below). For linear
models, Ftests are calculated; for generalized linear models,
likelihoodratio chisquare, Wald chisquare, or Ftests are calculated;
for multinomial logit and proportionalodds logit models, likelihoodratio
tests are calculated. Various test statistics are provided for multivariate
linear models produced by lm
or manova
. Partiallikelihoodratio tests
or Wald tests are provided for Cox models. Wald chisquare tests are provided for fixed effects in
linear and generalized linear mixedeffects models. Wald chisquare or F tests are provided
in the default case.
Usage
Anova(mod, ...)
Manova(mod, ...)
## S3 method for class 'lm'
Anova(mod, error, type=c("II","III", 2, 3),
white.adjust=c(FALSE, TRUE, "hc3", "hc0", "hc1", "hc2", "hc4"),
vcov.=NULL, singular.ok, ...)
## S3 method for class 'aov'
Anova(mod, ...)
## S3 method for class 'glm'
Anova(mod, type=c("II","III", 2, 3),
test.statistic=c("LR", "Wald", "F"),
error, error.estimate=c("pearson", "dispersion", "deviance"),
vcov.=vcov(mod, complete=TRUE), singular.ok, ...)
## S3 method for class 'multinom'
Anova(mod, type = c("II","III", 2, 3), ...)
## S3 method for class 'polr'
Anova(mod, type = c("II","III", 2, 3), ...)
## S3 method for class 'mlm'
Anova(mod, type=c("II","III", 2, 3), SSPE, error.df,
idata, idesign, icontrasts=c("contr.sum", "contr.poly"), imatrix,
test.statistic=c("Pillai", "Wilks", "HotellingLawley", "Roy"),...)
## S3 method for class 'manova'
Anova(mod, ...)
## S3 method for class 'mlm'
Manova(mod, ...)
## S3 method for class 'Anova.mlm'
print(x, ...)
## S3 method for class 'Anova.mlm'
summary(object, test.statistic, univariate=object$repeated,
multivariate=TRUE, p.adjust.method, ...)
## S3 method for class 'summary.Anova.mlm'
print(x, digits = getOption("digits"),
SSP=TRUE, SSPE=SSP, ... )
## S3 method for class 'univaov'
print(x, digits = max(getOption("digits")  2L, 3L),
style=c("wide", "long"),
by=c("response", "term"),
...)
## S3 method for class 'univaov'
as.data.frame(x, row.names, optional, by=c("response", "term"), ...)
## S3 method for class 'coxph'
Anova(mod, type=c("II", "III", 2, 3),
test.statistic=c("LR", "Wald"), ...)
## S3 method for class 'coxme'
Anova(mod, type=c("II", "III", 2, 3),
test.statistic=c("Wald", "LR"), ...)
## S3 method for class 'lme'
Anova(mod, type=c("II","III", 2, 3),
vcov.=vcov(mod, complete=FALSE), singular.ok, ...)
## S3 method for class 'mer'
Anova(mod, type=c("II", "III", 2, 3),
test.statistic=c("Chisq", "F"), vcov.=vcov(mod, complete=FALSE), singular.ok, ...)
## S3 method for class 'merMod'
Anova(mod, type=c("II", "III", 2, 3),
test.statistic=c("Chisq", "F"), vcov.=vcov(mod, complete=FALSE), singular.ok, ...)
## S3 method for class 'svyglm'
Anova(mod, ...)
## S3 method for class 'svycoxph'
Anova(mod, type=c("II", "III", 2, 3),
test.statistic="Wald", ...)
## S3 method for class 'rlm'
Anova(mod, ...)
## S3 method for class 'clm'
Anova(mod, ...)
## S3 method for class 'clmm'
Anova(mod, ...)
## Default S3 method:
Anova(mod, type=c("II", "III", 2, 3),
test.statistic=c("Chisq", "F"), vcov.=vcov(mod, complete=FALSE),
singular.ok, error.df, ...)
Arguments
mod 

error 
for a linear model, an 
type 
type of test, 
singular.ok 
defaults to 
test.statistic 
for a generalized linear model, whether to calculate

error.estimate 
for Ftests for a generalized linear model, base the
dispersion estimate on the Pearson residuals ( 
white.adjust 
if not 
SSPE 
For 
SSP 
if 
error.df 
The degrees of freedom for error; if For the 
idata 
an optional data frame giving a factor or factors defining the intrasubject model for multivariate repeatedmeasures data. See Details for an explanation of the intrasubject design and for further explanation of the other arguments relating to intrasubject factors. 
idesign 
a onesided model formula using the “data” in 
icontrasts 
names of contrastgenerating functions to be applied by default
to factors and ordered factors, respectively, in the withinsubject
“data”; the contrasts must produce an intrasubject model
matrix in which different terms are orthogonal. The default is

imatrix 
as an alternative to specifying 
x , object

object of class 
multivariate , univariate

compute and print multivariate and univariate tests for a repeatedmeasures
ANOVA or multivariate linear model; the default is 
p.adjust.method 
if given for a multivariate linear model when univariate tests are requested, the
univariate tests are corrected for simultaneous inference by term; if specified, should be one of the methods
recognized by 
digits 
minimum number of significant digits to print. 
style 
for printing univariate tests if requested for a multivariate linear model; one of 
by 
if univariate tests are printed in 
row.names , optional

not used. 
vcov. 
in the Note that arguments supplied to 
... 
do not use. 
Details
The designations "typeII" and "typeIII" are borrowed from SAS, but the definitions used here do not correspond precisely to those employed by SAS. TypeII tests are calculated according to the principle of marginality, testing each term after all others, except ignoring the term's higherorder relatives; socalled typeIII tests violate marginality, testing each term in the model after all of the others. This definition of TypeII tests corresponds to the tests produced by SAS for analysisofvariance models, where all of the predictors are factors, but not more generally (i.e., when there are quantitative predictors). Be very careful in formulating the model for typeIII tests, or the hypotheses tested will not make sense.
As implemented here, typeII Wald tests are a generalization of the linear hypotheses used to generate these tests in linear models.
For tests for linear models, multivariate linear models, and Wald tests for generalized linear models,
Cox models, mixedeffects models, generalized linear models fit to survey data, and in the default case,
Anova
finds the test statistics without refitting the model. The svyglm
method simply
calls the default
method and therefore can take the same arguments.
The standard R anova
function calculates sequential ("typeI") tests.
These rarely test interesting hypotheses in unbalanced designs.
A MANOVA for a multivariate linear model (i.e., an object of
class "mlm"
or "manova"
) can optionally include an
intrasubject repeatedmeasures design.
If the intrasubject design is absent (the default), the multivariate
tests concern all of the response variables.
To specify a repeatedmeasures design, a data frame is provided defining the repeatedmeasures factor or
factors
via idata
, with default contrasts given by the icontrasts
argument. An intrasubject modelmatrix is generated from the formula
specified by the idesign
argument; columns of the model matrix
corresponding to different terms in the intrasubject model must be orthogonal
(as is insured by the default contrasts). Note that the contrasts given in
icontrasts
can be overridden by assigning specific contrasts to the
factors in idata
. As an alternative, the withinsubjects model matrix
can be specified directly via the imatrix
argument.
Manova
is essentially a synonym for Anova
for multivariate linear models.
If univariate tests are requested for the summary
of a multivariate linear model, the object returned
contains a univaov
component of "univaov"
; print
and as.data.frame
methods are
provided for the "univaov"
class.
For the default method to work, the model object must contain a standard
terms
element, and must respond to the vcov
, coef
, and model.matrix
functions.
If any of these requirements is missing, then it may be possible to supply it reasonably simply (e.g., by
writing a missing vcov
method for the class of the model object).
Value
An object of class "anova"
, or "Anova.mlm"
, which usually is printed.
For objects of class "Anova.mlm"
, there is also a summary
method,
which provides much more detail than the print
method about the MANOVA, including
traditional mixedmodel univariate Ftests with GreenhouseGeisser and HuynhFeldt
corrections.
Warning
Be careful of typeIII tests: For a traditional multifactor ANOVA model with interactions, for example, these tests will normally only be sensible when using contrasts that, for different terms, are
orthogonal in the rowbasis of the model, such as those produced by contr.sum
, contr.poly
, or contr.helmert
, but not by the default
contr.treatment
. In a model that contains factors, numeric covariates, and interactions, maineffect tests for factors will be for differences over the origin. In contrast (pun intended),
typeII tests are invariant with respect to (fullrank) contrast coding. If you don't understand this issue, then you probably shouldn't use Anova
for typeIII tests.
Author(s)
John Fox [email protected]; the code for the Mauchly test and GreenhouseGeisser and HuynhFeldt
corrections for nonspericity in repeatedmeasures ANOVA are adapted from the functions
stats:::stats:::mauchly.test.SSD
and stats:::sphericity
by R Core; summary.Anova.mlm
and print.summary.Anova.mlm
incorporates code contributed by Gabriel BaudBovy.
References
Fox, J. (2016) Applied Regression Analysis and Generalized Linear Models, Third Edition. Sage.
Fox, J. and Weisberg, S. (2019) An R Companion to Applied Regression, Third Edition, Sage.
Hand, D. J., and Taylor, C. C. (1987) Multivariate Analysis of Variance and Repeated Measures: A Practical Approach for Behavioural Scientists. Chapman and Hall.
O'Brien, R. G., and Kaiser, M. K. (1985) MANOVA method for analyzing repeated measures designs: An extensive primer. Psychological Bulletin 97, 316–333.
See Also
linearHypothesis
, anova
anova.lm
, anova.glm
,
anova.mlm
, anova.coxph
, svyglm
.
Examples
## TwoWay Anova
mod < lm(conformity ~ fcategory*partner.status, data=Moore,
contrasts=list(fcategory=contr.sum, partner.status=contr.sum))
Anova(mod)
Anova(mod, type=3) # note use of contr.sum in call to lm()
## use of vcov.; the following are equivalent:
Anova(mod, white.adjust = TRUE)
Anova(mod, vcov. = hccm) # vcov. is a function, type = "hc3" is the default
Anova(mod, vcov. = hccm(mod, type = "hc3")) # vcov. is a matrix
Anova(mod, vcov. = function(m) hccm(m, type = "hc3")) # passing type as an argument
## OneWay MANOVA
## See ?Pottery for a description of the data set used in this example.
summary(Anova(lm(cbind(Al, Fe, Mg, Ca, Na) ~ Site, data=Pottery)))
## MANOVA for a randomized block design (example courtesy of Michael Friendly:
## See ?Soils for description of the data set)
soils.mod < lm(cbind(pH,N,Dens,P,Ca,Mg,K,Na,Conduc) ~ Block + Contour*Depth,
data=Soils)
Manova(soils.mod)
summary(Anova(soils.mod), univariate=TRUE, multivariate=FALSE,
p.adjust.method=TRUE)
## a multivariate linear model for repeatedmeasures data
## See ?OBrienKaiser for a description of the data set used in this example.
phase < factor(rep(c("pretest", "posttest", "followup"), c(5, 5, 5)),
levels=c("pretest", "posttest", "followup"))
hour < ordered(rep(1:5, 3))
idata < data.frame(phase, hour)
idata
mod.ok < lm(cbind(pre.1, pre.2, pre.3, pre.4, pre.5,
post.1, post.2, post.3, post.4, post.5,
fup.1, fup.2, fup.3, fup.4, fup.5) ~ treatment*gender,
data=OBrienKaiser)
(av.ok < Anova(mod.ok, idata=idata, idesign=~phase*hour))
summary(av.ok, multivariate=FALSE)
## A "doubly multivariate" design with two distinct repeatedmeasures variables
## (example courtesy of Michael Friendly)
## See ?WeightLoss for a description of the dataset.
imatrix < matrix(c(
1,0,1, 1, 0, 0,
1,0, 0,2, 0, 0,
1,0, 1, 1, 0, 0,
0,1, 0, 0,1, 1,
0,1, 0, 0, 0,2,
0,1, 0, 0, 1, 1), 6, 6, byrow=TRUE)
colnames(imatrix) < c("WL", "SE", "WL.L", "WL.Q", "SE.L", "SE.Q")
rownames(imatrix) < colnames(WeightLoss)[1]
(imatrix < list(measure=imatrix[,1:2], month=imatrix[,3:6]))
contrasts(WeightLoss$group) < matrix(c(2,1,1, 0,1,1), ncol=2)
(wl.mod<lm(cbind(wl1, wl2, wl3, se1, se2, se3)~group, data=WeightLoss))
Anova(wl.mod, imatrix=imatrix, test="Roy")
## mixedeffects models examples:
## Not run: # loads nlme package
library(nlme)
example(lme)
Anova(fm2)
## End(Not run)
## Not run: # loads lme4 package
library(lme4)
example(glmer)
Anova(gm1)
## End(Not run)