# diagnostic.plots: Plot Nonparametric Regression Diagnostics In npreg: Nonparametric Regression via Smoothing Splines

 diagnostic.plots R Documentation

## Plot Nonparametric Regression Diagnostics

### Description

Six regression diagnostic plots for a fit smoothing spline (fit by `ss`), smooth model (fit by `sm`), or generalized smooth model (fit by `gsm`).

### Usage

```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,
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)
```

### Arguments

 `x` an object of class "gsm" output by the `gsm` function, "sm" output by the `sm` function, or "ss" output by the `ss` function `which` subset of the integers `1:6` indicating which plots to produce `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 `caption`) `ask` if `TRUE`, the user is asked before each plot `...` 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 (`NULL` uses the observation numbers) `cex.id` magnification of point labels `cex.pt` magnification of points `qqline` logical indicating if a `qqline` should be added to the normal Q-Q plot `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 `iter` in `panel.smooth` `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 `caption` `cex.oma.main` controls the size of the `sub.caption` only if that is above the figures (when there is more than one figure) `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 `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. `ylim` 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.

### Details

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 √{|residuals|} versus fitted values, (4) Cook's distances, (5) residuals versus leverages, and (6) Cook's distance versus variance ratio = leverage/(1-leverage).

### Author(s)

Nathaniel E. Helwig <helwig@umn.edu>

### References

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`

### Examples

```# 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)

```

npreg documentation built on July 21, 2022, 1:06 a.m.