resplot: Residual Plot

Description Usage Arguments Details Author(s) References See Also Examples

View source: R/resplot.R

Description

Plot the fitted values vs the studentized or standardized residuals for a glm or lm object.

Usage

1
2
resplot(model, zoom = NULL, highlight.outliers = FALSE, 
  residuals = c("student","standard"))

Arguments

model

a regression model with any number of predictors. Must be a glm or lm object.

zoom

what range of residuals you wish to show in your plot. By default, zoom is NULL, and the residual plot will show all residuals. If you set zoom to a numeric value > 0, resplot will only show residuals which are at most that many standard deviations away from 0.

highlight.outliers

logical. If FALSE (the default), outliers will not be highlighted. If TRUE, every residual which is more than 3 standard deviations from 0 will be circled in red.

residuals

which type of residuals to use. Studentized residuals are used by default, but can be specified with "student", "rstudent", or "studentized". Standardized residuals can be specified with "standard", "rstandard", or "standardized"

Details

A residual plot shows the fitted values of the response variable on the x-axis and the studentized or standardized residuals on the y-axis. It can be used to check for correlated residuals or non-constant variance of the residuals, both of which would violate the residual assumptions of a linear model. It can also be used to check for outliers, as a value below -3 or above 3 would indicate a residual which is more than 3 standard deviations from the mean of 0.

Author(s)

Jonathan Schwartz

References

Montgomery, D. C., Peck, E. A., Vining, G. G. (2013), Introduction to Linear Regression Analysis, Hoboken, NJ: John Wiley & Sons, Inc.

See Also

plot, abline, lm, glm, predict, rstudent, rstandard

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
##plot a residual plot to check the model assumptions for a linear
##model of iris petal length as a predicted by iris petal width
model<-lm(iris$Petal.Length~iris$Petal.Width)
resplot(model)

##highlight the one outlier
resplot(model,highlight.outliers=TRUE)

##zoom in to only show the residuals between -1 and 1
resplot(model,zoom=1)

Example output



handyplots documentation built on May 2, 2019, 6:12 a.m.