plot.manylm {mvabund} | R Documentation |
Four plots (selectable by which
) are currently available: a plot
of residuals against fitted values, a Normal Q-Q plot,
a Scale-Location plot of sqrt{| residuals |} against fitted values,
a plot of Cook's distances versus row labels.
By default, all of them are provided.
The function is not yet available for manyglm object
## S3 method for class 'manylm': plot( x, which=1:4, caption=c("Residuals vs Fitted", "Normal Q-Q", "Scale-Location", "Cook's distance"), overlay=TRUE, n.vars=12, var.subset=NULL, panel=if (add.smooth) panel.smooth else points, sub.caption=NULL, main="", ask, ..., col=palette(rainbow(n.vars+1))[2:(n.vars+1)], id.n=if (overlay) 0 else 3, labels.id=rownames(as.matrix(residuals(x))), cex.id=0.75, qqline=TRUE, cook.levels=c(0.5, 1), add.smooth= if(!is.null(getOption("add.smooth"))) {getOption("add.smooth")} else TRUE, label.pos=c(4, 2), cex.caption=1, asp=1, legend.pos= if(length(col)==1) "none" else "nextplot", mfrow= if (overlay) { length(which)+(legend.pos=="nextplot")} else if (write.plot=="show") c(min(n.vars,3),length(which)) else length(which), mfcol=NULL, write.plot="show", filename="plot.mvabund", keep.window=if(is.null(c(mfrow,mfcol))) TRUE else FALSE, studentized= TRUE) ## S3 method for class 'manyglm': plot( x, which=1:4, caption=c("Residuals vs Fitted", "Normal Q-Q", "Scale-Location", "Cook's distance"), overlay=TRUE, n.vars=12, var.subset=NULL, panel=if (add.smooth) panel.smooth else points, sub.caption=NULL, main="", ask, ..., col=palette(rainbow(n.vars+1))[2:(n.vars+1)], id.n= if (overlay) 0 else 3, labels.id=rownames(as.matrix(residuals(x))), cex.id=0.75, qqline=TRUE, cook.levels=c(0.5, 1), add.smooth= if( !is.null(getOption("add.smooth")) ) {getOption("add.smooth")} else TRUE, label.pos = c(4, 2), cex.caption = 1, asp = 1, legend.pos= if(length(col)==1) "none" else "nextplot", mfrow= if(overlay) { length(which)+(legend.pos=="nextplot")} else if(write.plot=="show") c(min(n.vars,3) ,length(which)) else length(which), mfcol=NULL, write.plot="show", filename="plot.mvabund", keep.window=if(is.null(c(mfrow,mfcol))) TRUE else FALSE, studentized=TRUE)
x |
manylm object or manyglm object, typically the
result of a call to manylm or manyglm . |
which |
if a subset of the plots is required, specify a subset of
the numbers 1:4 . |
caption |
captions to appear above the plots |
overlay |
logical, whether or not the different variables should be overlaid on a single plot. |
n.vars |
the number of variables to include in the plot. |
var.subset |
the variables to include in the plot. |
panel |
panel function. The useful alternative to
points , panel.smooth can be chosen
by add.smooth = TRUE . |
sub.caption |
common title—above figures if there are multiple;
used as sub (s.title ) otherwise. If NULL ,
as by default, a possible shortened version of
deparse(x$call) is used. |
main |
title to each plot—in addition to the above
caption . |
ask |
logical; if TRUE , the user is asked before
each plot, see par(ask=.) . |
... |
other parameters to be passed through to plotting functions. |
col |
a character or integer value or vector of plotting colors, different plotting colors can be used for every variable. |
id.n |
number of points to be labelled in each plot, starting with the most extreme. |
labels.id |
vector of labels, from which the labels for extreme
points will be chosen. NULL uses observation numbers. |
cex.id |
magnification of point labels. |
qqline |
logical indicating if a qqline() should be
added to the normal Q-Q plot. |
cook.levels |
levels of Cook's distance at which to draw contours. |
add.smooth |
logical indicating if a smoother should be added to
most plots; see also panel above. |
label.pos |
positioning of labels, for the left half and right half of the graph respectively, for plots 1-3. |
cex.caption |
controls the size of caption . |
asp |
the y/x aspect ratio. If the y/x aspect ratio should not be used
for scaling the plot, use asp = NA .
For the Scale-Location plot (which=3 ) and the plot of
Cooks Distance (which=4 ), asp is not used! |
legend.pos |
if applicable (see overlay) the position of the legend, this can either be specified as a pair of coordinates or as a keyword specifying the position, e.g. "center", or as keywords "none" or "nextplot". |
mfrow |
a pair containing either the number of rows and columns per window
or the prefered number of plots per window, the order of drawing is by column;
if mfcol is passed, mfrow is ignored. If mfrow = NULL & mfcol = NULL, the plots will be drawn on the current window if one is open. |
mfcol |
like MFROW, but the order of drawing is by row. |
write.plot |
can be "show" (default): plot is shown, or "eps", "postscript", "pdf", "jpeg", "bmp", "png" to save the plot in this format, plot is then not shown. |
filename |
character, pathname where the file should be stored. Default location is R's working directory. |
keep.window |
logical, if TRUE and write.plot=="show" , the specifications of mfrow,
mfcol, oma and the size of the winodow are kept,
if FALSE the old values will be restored, which usually means that any plot following this
function will be drawn on a new window. |
studentized |
logical indicating whether studentized or standardized residuals should be used for plot 2 and 3. |
plot.manylm
is used to check the linear model assumptions that are made
when fitting a model via manylm
. Similarly, plot.manyglm
checks
the generalised linear model assumptions made when using manyglm
.
You should check the residual vs fits plot for no pattern (hence no suggestion
of failure of key linearity and mean-variance assumptions). For manylm fits of
small datasets, it is desirable that residuals on the normal Q-Q plot be close
to a straight line, although in practice the most important thing is to make
sure there are no big outliers and no suggestion of strong skew in the data.
Some technical details on usage of this function:
sub.caption
- by default the function call - is shown as
a subtitle (under the x-axis title) on each plot when plots are on
separate pages, or as a subtitle in the outer margin (if any) when
there are multiple plots per page.
The ‘Scale-Location’ plot, also called ‘Spread-Location’ or ‘S-L’ plot, takes the square root of the absolute residuals in order to diminish skewness (sqrt{| E |} is much less skewed than | E | for Gaussian zero-mean E).
If studentized=FALSE
the ‘S-L’, the Q-Q, and the Residual-Leverage
plot, use standardized residuals which have identical variance
(under the hypothesis) otherwise studentized residuals are used.
If mfcol
is passed, mfrow
is ignored. If mfrow=NULL
and mfcol=NULL
, par("mfrow") is used.
Unlike other plotting functions plot.manylm
and plot.manyglm
respectively do not have a subset argument, the subset needs to be specified
in the manylm
or respectively manyglm
function.
For all arguments that are formally located after the position of ...
,
positional matching does not work.
For restrictions on filename
see R's help on eps/pdf/jpeg.
Note that keep.window
will be ignored if write.plot
is
not show
.
Ulrike Naumann and David Warton <David.Warton@unsw.edu.au>.
require(graphics) data(spider) spiddat <- mvabund(spider$abund) X <- spider$x ## plot the diagnostics for the linear fit of the spider data spidlm <- manylm(spiddat~X) plot(spidlm,which=1:2,col.main="red",cex=3,overlay=FALSE) plot(spidlm,which=1:4,col.main="red",cex=3,overlay=TRUE)