This function plots ellipses representing the hypothesis and error sumsofsquaresandproducts matrices for terms and linear hypotheses in a multivariate linear model. These include MANOVA models (all explanatory variables are factors), multivariate regression (all quantitative predictors), MANCOVA models, homogeneity of regression, as well as repeated measures designs treated from a multivariate perspective.
heplot(mod, ...) # S3 method for mlm heplot(mod, terms, hypotheses, term.labels = TRUE, hyp.labels = TRUE, err.label="Error", label.pos=NULL, variables = 1:2, error.ellipse = !add, factor.means = !add, grand.mean = !add, remove.intercept = TRUE, type = c("II", "III", "2", "3"), idata=NULL, idesign=NULL, icontrasts=c("contr.sum", "contr.poly"), imatrix=NULL, iterm=NULL, markH0=!is.null(iterm), manova, size = c("evidence", "effect.size"), level = 0.68, alpha = 0.05, segments = 60, center.pch = "+", center.cex=2, col = getOption("heplot.colors", c("red", "blue", "black", "darkgreen", "darkcyan","magenta", "brown","darkgray")), lty = 2:1, lwd = 1:2, fill=FALSE, fill.alpha=0.3, xlab, ylab, main = "", xlim, ylim, axes=TRUE, offset.axes, add = FALSE, verbose = FALSE, warn.rank = FALSE, ...)
mod  a model object of class 

terms  a logical value or character vector of terms in the model
for which to plot
hypothesis matrices; if missing or 
hypotheses  optional list of linear hypotheses for which to plot hypothesis
matrices; hypotheses are specified as for the

term.labels  logical value or character vector of names for the terms to be
plotted. If 
hyp.labels  logical value or character vector of names for the hypotheses to
be plotted. If 
err.label  Label for the error ellipse 
label.pos  Label position, a vector of integers (in 
variables  indices or names of the two response variables to be plotted;
defaults to 
error.ellipse  if 
factor.means  logical value or character vector of names of
factors for which the means
are to be plotted, or 
grand.mean  if 
remove.intercept  if 
type  ``type'' of sumofsquaresandproducts matrices to compute; one of

idata  an optional data frame giving a factor or factors defining the
intrasubject model for multivariate repeatedmeasures data.
See Friendly (2010) and Details of 
idesign  a onesided model formula using the ``data'' in idata and specifying the intrasubject design for repeated measure models. 
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 c("contr.sum", "contr.poly"). 
imatrix  In lieu of 
iterm  For repeated measures designs, you must specify one intrasubject term
(a character string) to select the SSPE (E) matrix used in the HE plot.
Hypothesis terms plotted include the 
markH0  A logical value (or else a list of arguments to 
manova  optional 
size  how to scale the hypothesis ellipse relative to the error
ellipse; if 
level  equivalent coverage of ellipse for normallydistributed
errors, defaults to 
alpha  signficance level for Roy's greatestroot test statistic; if

segments  number of line segments composing each ellipse; defaults to

center.pch  character to use in plotting the centroid of the data;
defaults to 
center.cex  size of character to use in plotting the centroid of the data;
defaults to 
col  a color or vector of colors to use in plotting ellipses; the first
color is used for the error ellipse; the remaining colors  recycled
as necessary  are used for the hypothesis ellipses.
A single color can be given, in which case it is used for all ellipses.
For convenience, the default colors for all heplots produced in a given session can be changed
by assigning a color vector via 
lty  vector of line types to use for plotting the ellipses; the first is
used for the error ellipse, the rest  possibly recycled  for
the hypothesis ellipses; a single line type can be given. Defaults to

lwd  vector of line widths to use for plotting the ellipses; the first is
used for the error ellipse, the rest  possibly recycled  for
the hypothesis ellipses; a single line width can be given. Defaults to

fill  A logical vector indicating whether each ellipse should be filled or not. The first value is used for the error ellipse, the rest  possibly recycled  for the hypothesis ellipses; a single fill value can be given. Defaults to FALSE for backward compatibility. See Details below. 
fill.alpha  Alpha transparency for filled ellipses, a numeric scalar or vector of values
within 
xlab  xaxis label; defaults to name of the x variable. 
ylab  yaxis label; defaults to name of the y variable. 
main  main plot label; defaults to 
xlim  xaxis limits; if absent, will be computed from the data. 
ylim  yaxis limits; if absent, will be computed from the data. 
axes  Whether to draw the x, y axes; defaults to 
offset.axes  proportion to extend the axes in each direction if computed from the data; optional. 
add  if 
verbose  if 
warn.rank  if 
…  arguments to pass down to 
The heplot
function plots a representation of the covariance ellipses
for hypothesized model terms and linear hypotheses (H) and the corresponding
error (E) matrices for two response variables in a multivariate linear model (mlm).
The plot helps to visualize the nature and dimensionality
response variation on the two variables jointly
in relation to error variation that is summarized in the various multivariate
test statistics (Wilks' Lambda, Pillai trace, HotellingLawley trace, Roy maximum
root). Roy's maximum root test has a particularly simple visual interpretation,
exploited in the size="evidence"
version of the plot. See the description of
argument alpha
.
For a 1 df hypothesis term (a quantitative regressor, a single contrast or parameter test), the H matrix has rank 1 (one nonzero latent root of \(H E^{1}\)) and the H "ellipse" collapses to a degenerate line.
Typically, you fit a mlm with mymlm < lm(cbind(y1, y2, y3, ...) ~ modelterms)
,
and plot some or all of the modelterms
with heplot(mymlm, ...)
.
Arbitrary linear hypotheses related to the terms in the model (e.g., contrasts of
an effect) can be included in the plot using the hypotheses
argument.
See linearHypothesis
for details.
For repeated measure designs, where the response variables correspond to one or
more variates observed under a withinsubject design, betweensubject effects
and withinsubject effects must be plotted separately, because the error terms
(E matrices) differ. When you specify an intrasubject term (iterm
),
the analysis and HE plots
amount to analysis of the matrix Y of responses postmultiplied by a matrix
M determined by the intrasubject design for that term. See Friendly (2010)
or the vignette("repeated")
in this package for an extended discussion and
examples.
The related candisc
package provides functions for
visualizing a multivariate linear model in a lowdimensional view via a
generalized canonical discriminant analyses. heplot.candisc
and heplot3d.candisc
provide a lowrank 2D (or 3D) view of the effects for
a given term in the space of maximum discrimination.
When an element of fill
is TRUE
, the ellipse outline is drawn using the corresponding
color in col
, and the interior is filled with a transparent version of this color specified
in fill.alpha
. To produce filled (nondegenerate) ellipses without the bounding outline, use
a value of lty=0
in the corresponding position.
The function invisibly returns an object of class "heplot"
, with
coordinates for the various hypothesis ellipses and the error ellipse, and
the limits of the horizontal and vertical axes. These may be useful for
adding additional annotations to the plot, using standard plotting functions.
(No methods for manipulating these objects are currently available.)
The components are:
a list containing the coordinates of each ellipse for the hypothesis terms
a matrix containing the coordinates for the error ellipse
x,y coordinates of the centroid
xaxis limits
yaxis limits
the radius for the unit circles used to generate the ellipses
Friendly, M. (2006). Data Ellipses, HE Plots and ReducedRank Displays for Multivariate Linear Models: SAS Software and Examples Journal of Statistical Software, 17(6), 142. http://www.jstatsoft.org/v17/i06/
Friendly, M. (2007). HE plots for Multivariate General Linear Models. Journal of Computational and Graphical Statistics, 16(2) 421444. http://datavis.ca/papers/jcgsheplots.pdf
Friendly, Michael (2010). HE Plots for Repeated Measures Designs. Journal of Statistical Software, 37(4), 140. URL http://www.jstatsoft.org/v37/i04/.
Fox, J., Friendly, M. & Weisberg, S. (2013). Hypothesis Tests for Multivariate Linear Models Using the car Package. The R Journal, 5(1), https://journal.rproject.org/archive/20131/foxfriendlyweisberg.pdf.
Friendly, M. & Sigal, M. (2014) Recent Advances in Visualizing Multivariate Linear Models. Revista Colombiana de Estadistica, 37, 261283, http://ref.scielo.org/6gq33g.
Anova
, linearHypothesis
for details on
testing MLMs.
heplot1d
, heplot3d
, pairs.mlm
, mark.H0
for other
HE plot functions. coefplot.mlm
for plotting confidence ellipses for parameters
in MLMs.
trans.colors
for calculation of transparent colors.
label.ellipse
for labeling positions in plotting H and E ellipses.
candisc
, heplot.candisc
for reducedrank views of mlm
s
in canonical space.
## iris data contrasts(iris$Species)<matrix(c(0,1,1, 2, 1, 1), 3,2) contrasts(iris$Species)#> [,1] [,2] #> setosa 0 2 #> versicolor 1 1 #> virginica 1 1iris.mod < lm(cbind(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) ~ Species, data=iris) hyp < list("V:V"="Species1","S:VV"="Species2") heplot(iris.mod, hypotheses=hyp)# compare with effectsize scaling heplot(iris.mod, hypotheses=hyp, size="effect", add=TRUE)# try filled ellipses heplot(iris.mod, hypotheses=hyp, fill=TRUE, fill.alpha=0.2, col=c("red", "blue"))heplot(iris.mod, hypotheses=hyp, fill=TRUE, col=c("red", "blue"), lty=c(0,0,1,1))# vary label position and fill.alpha heplot(iris.mod, hypotheses=hyp, fill=TRUE, fill.alpha=c(0.3,0.1), col=c("red", "blue"), lty=c(0,0,1,1), label.pos=0:3)hep <heplot(iris.mod, variables=c(1,3), hypotheses=hyp)str(hep)#> List of 6 #> $ H :List of 3 #> ..$ Species: num [1:61, 1:2] 9.66 9.68 9.66 9.6 9.5 ... #> .. .. attr(*, "dimnames")=List of 2 #> .. .. ..$ : NULL #> .. .. ..$ : chr [1:2] "Sepal.Length" "Petal.Length" #> ..$ V:V : num [1:61, 1:2] 7.41 7.4 7.38 7.33 7.27 ... #> .. .. attr(*, "dimnames")=List of 2 #> .. .. ..$ : NULL #> .. .. ..$ : chr [1:2] "Sepal.Length" "Petal.Length" #> ..$ S:VV : num [1:61, 1:2] 9.33 9.31 9.25 9.16 9.03 ... #> .. .. attr(*, "dimnames")=List of 2 #> .. .. ..$ : NULL #> .. .. ..$ : chr [1:2] "Sepal.Length" "Petal.Length" #> $ E : num [1:61, 1:2] 6.62 6.62 6.61 6.59 6.56 ... #> .. attr(*, "dimnames")=List of 2 #> .. ..$ : NULL #> .. ..$ : chr [1:2] "Sepal.Length" "Petal.Length" #> $ center: Named num [1:2] 5.84 3.76 #> .. attr(*, "names")= chr [1:2] "Sepal.Length" "Petal.Length" #> $ xlim : Named num [1:2] 2.01 9.68 #> .. attr(*, "names")= chr [1:2] "Sepal.Length" "Sepal.Length" #> $ ylim : Named num [1:2] 6.33 13.84 #> .. attr(*, "names")= chr [1:2] "Petal.Length" "Petal.Length" #> $ radius: num 1.52 #>  attr(*, "class")= chr "heplot"# all pairs pairs(iris.mod, hypotheses=hyp, hyp.labels=FALSE)## Pottery data, from car package data(Pottery) pottery.mod < lm(cbind(Al, Fe, Mg, Ca, Na) ~ Site, data=Pottery) heplot(pottery.mod)heplot(pottery.mod, terms=FALSE, add=TRUE, col="blue", hypotheses=list(c("SiteCaldicot = 0", "SiteIsleThorns=0")), hyp.labels="Sites Caldicot and Isle Thorns")## Rohwer data, multivariate multiple regression/ANCOVA # ANCOVA, assuming equal slopes rohwer.mod < lm(cbind(SAT, PPVT, Raven) ~ SES + n + s + ns + na + ss, data=Rohwer) Anova(rohwer.mod)#> #> Type II MANOVA Tests: Pillai test statistic #> Df test stat approx F num Df den Df Pr(>F) #> SES 1 0.37853 12.1818 3 60 2.507e06 *** #> n 1 0.04030 0.8400 3 60 0.477330 #> s 1 0.09271 2.0437 3 60 0.117307 #> ns 1 0.19283 4.7779 3 60 0.004729 ** #> na 1 0.23134 6.0194 3 60 0.001181 ** #> ss 1 0.04990 1.0504 3 60 0.376988 #>  #> Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1col < c("red", "black", "blue", "cyan", "magenta", "brown", "gray") heplot(rohwer.mod, col=col)# Add ellipse to test all 5 regressors heplot(rohwer.mod, hypotheses=list("Regr" = c("n", "s", "ns", "na", "ss")), col=col, fill=TRUE)# View all pairs pairs(rohwer.mod, hypotheses=list("Regr" = c("n", "s", "ns", "na", "ss")))# or 3D plot col < c("pink", "black", "blue", "cyan", "magenta", "brown", "gray") heplot3d(rohwer.mod, hypotheses=list("Regr" = c("n", "s", "ns", "na", "ss")), col=col)