Six regression diagnostic plots for a fit smoothing spline (fit by ss
), smooth model (fit by sm
), or generalized smooth model (fit by gsm
).
diagnostic.plots(x, which = c(1, 2, 3, 5),
caption = list("Residuals vs Fitted",
"Normal Q-Q", "Scale-Location",
"Cook's distance", "Residuals vs Leverage",
"Cook's dist vs Variance ratio"),
panel = if (add.smooth) function(x, y, ...)
panel.smooth(x, y, iter = iter.smooth, ...)
else points,
sub.caption = NULL, main = "",
ask = prod(par("mfcol")) < length(which) && dev.interactive(),
..., id.n = 3, labels.id = names(residuals(x)), cex.id = 0.75, cex.pt = 1,
qqline = TRUE, cook.levels = c(0.5, 1), add.smooth = getOption("add.smooth"),
iter.smooth = if (isGlm) 0 else 3, label.pos = c(4, 2), cex.caption = 1,
cex.oma.main = 1.25, cex.lab = 1, line.lab = 3, xlim = NULL, ylim = NULL)
an object of class "gsm" output by the gsm
function, "sm" output by the sm
function, or "ss" output by the ss
function
subset of the integers 1:6
indicating which plots to produce
captions to appear above the plots
panel function (panel.smooth or points?)
common title (for use above multiple figures)
title to each plot (in addition to caption
)
if TRUE
, the user is asked before each plot
other parameters to be passed through to plotting functions
number of points to be labeled in each plot, starting with the most extreme
vector of labels for extreme observations (NULL
uses the observation numbers)
magnification of point labels
magnification of points
logical indicating if a qqline
should be added to the normal Q-Q plot
levels of Cook's distance at which to draw contours
logical indicating if a smoother should be added to most plots
the number of robustness iterations, the argument iter
in panel.smooth
positioning of the labels, for the left hald and right half of the graph respectively, for plots 1-3, 5, and 6
controls the size of the caption
controls the size of the sub.caption
only if that is above the figures (when there is more than one figure)
character expansion factor for axis labels
on which margin line should the axis labels be drawn?
Limits for x-axis. If length(which) == 1
, a vector of the form c(xmin, xmax)
. Otherwise a list the same length as which
such that each list entry gives the x-axis limits for the corresponding plot.
Limits for y-axis. If length(which) == 1
, a vector of the form c(ymin, ymax)
. Otherwise a list the same length as which
such that each list entry gives the y-axis limits for the corresponding plot.
Nathaniel E. Helwig <helwig@umn.edu>
This function is modeled after the plot.lm
function. The structure of the arguments, as well as the internal codes, mimics the plot.lm
function whenever possible. By default, only plots 1-3 and 5 are provided, but any subset of plots can be requested using the which
argument.
The six plots include: (1) residuals versus fitted values, (2) normal Q-Q plot, (3) scale-location plot of \(\sqrt{|residuals|}\) versus fitted values, (4) Cook's distances, (5) residuals versus leverages, and (6) Cook's distance versus variance ratio = leverage/(1-leverage).
Belsley, D. A., Kuh, E. and Welsch, R. E. (1980). Regression Diagnostics. New York: Wiley.
Cook, R. D. and Weisberg, S. (1982). Residuals and Influence in Regression. London: Chapman and Hall.
McCullagh, P. and Nelder, J. A. (1989). Generalized Linear Models. London: Chapman and Hall.
ss
, sm
, gsm
smooth.influence.measures
and smooth.influence
# generate data
set.seed(1)
n <- 100
x <- seq(0, 1, length.out = n)
fx <- 2 + 3 * x + sin(2 * pi * x)
y <- fx + rnorm(n, sd = 0.5)
# smoothing spline
mod.ss <- ss(x, y, nknots = 10)
diagnostic.plots(mod.ss)
# smooth model
mod.sm <- sm(y ~ x, knots = 10)
diagnostic.plots(mod.sm)
# generalized smooth model (family = gaussian)
mod.gsm <- gsm(y ~ x, knots = 10)
diagnostic.plots(mod.gsm)
Run the code above in your browser using DataLab