View source: R/diagnostic.plots.R
diagnostic.plots | R Documentation |
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)
x |
an object of class "gsm" output by the |
which |
subset of the integers |
caption |
captions to appear above the plots |
panel |
panel function (panel.smooth or points?) |
sub.caption |
common title (for use above multiple figures) |
main |
title to each plot (in addition to |
ask |
if |
... |
other parameters to be passed through to plotting functions |
id.n |
number of points to be labeled in each plot, starting with the most extreme |
labels.id |
vector of labels for extreme observations ( |
cex.id |
magnification of point labels |
cex.pt |
magnification of points |
qqline |
logical indicating if a |
cook.levels |
levels of Cook's distance at which to draw contours |
add.smooth |
logical indicating if a smoother should be added to most plots |
iter.smooth |
the number of robustness iterations, the argument |
label.pos |
positioning of the labels, for the left hald and right half of the graph respectively, for plots 1-3, 5, and 6 |
cex.caption |
controls the size of the |
cex.oma.main |
controls the size of the |
cex.lab |
character expansion factor for axis labels |
line.lab |
on which margin line should the axis labels be drawn? |
xlim |
Limits for x-axis. If |
ylim |
Limits for y-axis. If |
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).
Nathaniel E. Helwig <helwig@umn.edu>
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.