Creates a plot of residuals against the sequence/order of observations to visually assess independence and detect autocorrelation. Optionally overlays results from the Durbin–Watson test and labels outliers.
Usage
lm_plot.ac(
mdl,
opt = list(),
parm = list(),
df = lm_plot.df(mdl),
plts = list()
)
Arguments
- mdl
A fitted model object (typically from
lm
).- opt
List of options, where
pval.DW
(logical, default = FALSE) indicates whether to include Durbin-Watson p-value on the plot.- parm
A list of plotting parameters, usually from
lm_plot.parms()
.- df
Data frame with augmented model data. Defaults to
lm_plot.df(mdl)
.- plts
A list of ggplot objects to which this plot will be added.
Value
A list containing:
mdl
Fitted model object,opt
Options used, includingpval.DW
,parm
Parameter list with Durbin-Watson test results added,df
Data frame used for plotting,plts
List of ggplot objects, including the$ac
element.
Details
Points are colored and shaped according to whether they are residual outliers
(as determined by Tukey's boxplot rule). The function can label points using
ggrepel if parm$pts$id$outl
or parm$pts$id$reg
are set to TRUE
.
Examples
if (FALSE) { # \dontrun{
fit <- lm(mpg ~ wt + hp, data = mtcars)
lm_plot.ac(fit)
} # }