Plot the residuals of a regression model.
| object | The model object.
 | 
| which | Which plots do draw.  Default is 1:4. 1Model plot.  What gets plotted here depends on the model class.
For example, forearthmodels this is a model selection plot.
Nothing will be displayed for some models.
For details, please see the
plotres vignette.
 2Cumulative distribution of abs residuals
 3Residuals vs fitted
 4QQ plot
 5Abs residuals vs fitted
 6Sqrt abs residuals vs fitted
 7Abs residuals vs log fitted
 8Cube root of the squared residuals vs log fitted
 9Log abs residuals vs log fitted
 
 | 
| info | Default is FALSE.
UseTRUEto print extra information as follows: i) Display the distribution of the residuals along the bottom of the plot.
 ii) Display the training R-Squared.
 iii) Display the Spearman Rank Correlation of the absolute residuals
with the fitted values.
Actually, correlation is measured against the absolute values
of whatever is on the horizontal
axis — by default this is the fitted response, but may be something
else if the versusargument is used. iv) In the Cumulative Distribution plot (which=2),
display additional information on the quantiles. v) Only for which=5or9.
Regress the absolute residuals against the fitted values
and display the regression slope.
Robust linear regression is used viarlmin the MASS package. vi) Add various annotations to the other plots.
 
 | 
| versus | What do we plot the residuals against?  One of:
 1Default. Plot the residuals versus the fitted values
(or the log values whenwhich=7to9).
 2Residuals versus observation number,
after observations have been sorted on the fitted value.
Same asversus=1, except that the residuals are spaced
uniformly along the horizontal axis.
 3Residuals versus the response.
 4Residuals versus the hat leverages.
 "b:"Residuals versus the basis functions.
Currently only supported forearth,mda::mars, andgam::gammodels.
A optionalregexcan follow the"b:"to specify a subset of the
terms, e.g.versus="b:wind"will plot terms with"wind"in
their name.
 Else a character vector specifying which predictors to plot against.
Example 1:
 versus=""plots against all predictors (since the
regexversus=""matches anything).Example 2:
 versus=c("wind", "vis")plots predictors
withwindorvisin their name.Example 3:
 versus=c("wind|vis")equivalent to the above.Note: These are
 regexs.
Thusversus="wind"will match all variables that have"wind"in their names. Use"^wind$"to match only the variable named"wind".
 
 | 
| standardize | Default is FALSE.
UseTRUEto standardize the residuals.
Only supported for some models, an error message will be issued otherwise.Each residual is divided by by
 se_i * sqrt(1 - h_ii),
wherese_iis the standard error of prediction
andh_iiis the leverage (the diagonal entry of the hat matrix).
When the variance model holds, the standardized residuals are
homoscedastic with unity variance.The leverages are obtained using
 hatvalues.
(Forearthmodels the leverages are
for the linear regression of the response on the basis matrixbx.)
A standardized residual with a leverage of 1 is plotted as a star on the axis.This argument applies to all plots where the residuals are used
(including the cumulative distribution and QQ plots, and to
annotations displayed by the
 infoargument). | 
| delever | Default is FALSE.
UseTRUEto “de-lever” the residuals.
Only supported for some models, an error message will be issued otherwise.Each residual is divided by
 sqrt(1 - h_ii).
See thestandardizeargument for details. | 
| level | Draw estimated confidence or prediction interval bands at the given
level, if the model supports them.Default is
 0, bands not plotted.
Else a fraction, for examplelevel=0.90.
Example:     mod <- lm(log(Volume)~log(Girth), data=trees)
    plotres(mod, level=.90)You can modify the color of the bands with level.shadeandlevel.shade2.See also “Prediction intervals” in the
plotmo vignette
(but note that
 plotmoneeds prediction intervals on new
data, whereasplotresrequires only that the model supports
prediction intervals on the training data). | 
| id.n | The largest id.nresiduals will be labeled in the plot.
Default is3.
Special valuesTRUEand-1or mean all.If
 id.nis negative (but not-1)
theid.nmost positive and most negative
residuals will be labeled in the plot.A current implementation restriction is that
 id.nis ignored
when there are more than ten thousand cases. | 
| labels.id | Residual labels.
Only used if id.n > 0.
Default is the case names, or the case numbers if the cases are unnamed. | 
| smooth.col | Color of the smooth line through the residual points.
Default is 2, red. Usesmooth.col=0for no smooth line.You can adjust the amount of smoothing with
 smooth.f.
This gets passed asftolowess.
The default is2/3.
Lower values make the line more wiggly. | 
| grid.col | Default is 0, no grid.
Else add a backgroundgridof the specified color to the degree1 plots.
The special valuegrid.col=TRUEis treated as"lightgray". | 
| jitter | Default is 0, no jitter.
Passed asfactortojitterto jitter the plotted points horizontally and vertically.
Useful for discrete variables and responses, where the residual points
tend to be overlaid. | 
| do.par | One of NULL,FALSE,TRUE, or2, as follows: do.par=NULL(default). Same asdo.par=FALSEif the
number of plots is one; else the same asTRUE.
 do.par=FALSE. Use the currentparsettings.
You can pass additional graphics parameters in the “...” argument.
 do.par=TRUE. Start a new page and callparas
appropriate to display multiple plots on the same page.
This automatically sets parameters likemfrowandmar.
You can pass additional graphics parameters in the “...” argument.
 do.par=2.  Likedo.par=TRUEbut don't restore theparsettings to their original state whenplotresexits, so you can add something to the plot.
 
 | 
| caption | Overall caption.  By default create the caption automatically.
Use caption=""for no caption.
(Usemainto set the title of an individual plot.) | 
| trace | Default is 0.
 trace=1(orTRUE) for a summary trace (shows howpredictand friends
are invoked for the model).
 trace=2for detailed tracing.
 | 
| npoints | Number of points to be plotted.
A sample of npointsis taken; the sample includes the biggest
twenty or so residuals.The default is 3000 (not all, to avoid overplotting on large models).
Use
 npoints=TRUEor-1for all points. | 
| center | Default is TRUE, meaning center the horizontal axis in the residuals plot,
so asymmetry in the residual distribution is more obvious.
 | 
| type | Type parameter passed first to residualsand
if that fails topredict.
For allowed values see theresidualsandpredictmethods for
yourobject(such asresiduals.rpartorpredict.earth).
By default,plotrestries to automatically select a suitable
value for the model in question (usually"response"),
but this will not always be correct.
Usetrace=1to see thetypeargument passed toresidualsandpredict. | 
| nresponse | Which column to use when residualsorpredictreturns
multiple columns.
This can be a column index or column name
(which may be abbreviated, partial matching is used). | 
| object.name | The name of the objectfor error and trace messages.
Used internally byplot.earth.
 
 | 
| ... | Dot arguments are passed to the plot functions.
Dot argument names, whether prefixed or not, should be specified in full
and not abbreviated.
 “Prefixed” arguments are passed directly to the associated function.
For example the prefixed argument pt.col="pink"passescol="pink"topoints(), overriding the globalcolsetting.
The prefixes recognized byplotresare: 
 | residuals. | passed to residuals |  
 | predict. | passed to predict(predictis called if the call toresidualsfails) |  
 | w1. | sent to the model-dependent plot for which=1e.g.w1.col=2 |  
 | pt. | modify the displayed points
e.g. pt.col=as.numeric(survived)+2orpt.cex=.8. |  
 | smooth. | modify the  smooth line e.g. smooth.col=0orsmooth.f=.5. |  
 | level. | modify the interval bands, e.g. level.shade="gray"orlevel.shade2="lightblue" |  
 | legend. | modify the displayed legende.g.legend.cex=.9 |  
 | cum. | modify the Cumulative Distribution plot
(arguments for plot.stepfun) |  
 | qq. | modify the QQ plot, e.g. qq.pch=1 |  
 | qqline | modify the qqlinein the QQ plot, e.g.qqline.col=0 |  
 | label. | modify the point labels, e.g. label.cex=.9orlabel.font=2 |  
 | cook. | modify the Cook's Distance annotations.
This affects only the leverage plot
( versus=3) forlmmodels withstandardize=TRUE.
e.g.cook.levels=c(.5, .8, 1)orcook.col=2. |  
 | caption. | modify the overall caption (see the captionargument)
e.g.caption.col=2. |  
 | par. | arguments for par(only necessary if aparargument name clashes
with aplotresargument) |  The cexargument is relative, so
specifyingcex=1is the same as not specifyingcex. For backwards compatibility, some dot
arguments are supported but not explicitly documented.
 | 
In general this function won't work on models that don't save the call
and data with the model in a standard way.
It uses the same underlying mechanism to access the model data as
plotmo.
For further discussion please see “Accessing the model
data” in the plotmo vignette
(also available here).
Package authors may want to look at
Guidelines for S3 Regression Models
(also available here).