residual_plot.lm {api2lm} | R Documentation |
Plot residuals of a fitted lm
object
Description
residual_plot.lm
plots the residuals of a fitted
lm
object. In general, it is intended to provide
similar functionality to plot.lm
when which = 1
, but can be used for different
types of residuals and can also plot first-order
predictor variables along the x-axis instead of only the
fitted values.
Details about the different types of
residuals are discussed in the
get_residuals
function.
Usage
## S3 method for class 'lm'
residual_plot(
model,
rtype = c("ordinary", "standardized", "studentized", "loo", "jackknife", "deleted",
"internally studentized", "externally studentized"),
xaxis = "fitted",
id_n = 3,
predictors = ~.,
smooth = stats::loess,
add_reference = TRUE,
add_smooth = TRUE,
...,
text_arglist = list(),
abline_arglist = list(),
smooth_arglist = list(),
lines_arglist = list(),
extendrange_f = 0.08
)
Arguments
model |
A fitted model object from the
|
rtype |
The residual type to plot. The default is
|
xaxis |
The variable to use on the x-axis of the
plot(s). The default is |
id_n |
The number of points to identify with labels.
The default is |
predictors |
A formula describing the first-order predictors to plot the residuals against. The default is all available first-order predictors. |
smooth |
A function with a
|
add_reference |
A logical value indicating whether a
reference line should be added. The default is
|
add_smooth |
A logical value indicating whether a
smooth should be added to each plot produced. The
default is |
... |
Additional arguments passed to the
|
text_arglist |
Additional arguments passed to the
|
abline_arglist |
A named list specifying additional
arguments passed to the |
smooth_arglist |
A named list specifying additional
arguments passed to the function provided in the
|
lines_arglist |
A named list specifying additional
arguments passed to the |
extendrange_f |
Positive number(s) specifying the
fraction by which the range of the residuals should be
extended using the |
Author(s)
Joshua French
See Also
plot
,
text
,
abline
,
lines
loess
.
Examples
lmod <- lm(Petal.Length ~ Sepal.Length + Species,
data = iris)
# similarity with built-in plot.lm functionality
residual_plot(lmod)
plot(lmod, which = 1)
# residual plot for other residual types
residual_plot(lmod, rtype = "standardized", id_n = 0)
# another residual plot with several customizations
residual_plot(lmod,
text_arglist = list(col = "blue", cex = 2),
abline_arglist = list(lwd = 2, lty = 2,
col = "brown"),
lines_arglist = list(col = "purple"),
)
# residual plot for predictors
residual_plot(lmod, xaxis = "pred", id_n = 2)
# residual plot for individual predictors
residual_plot(lmod, xaxis = "pred",
predictors = ~ Sepal.Length, id_n = 2)
residual_plot(lmod, xaxis = "pred",
predictors = ~ Species,)