Learn R Programming

sfsmisc (version 0.9-4)

pl.ds: Plot Data and Smoother / Fitted Values

Description

For one-dimensional nonparametric regression, plot the data and fitted values, typically a smooth function, and optionally use segments to visualize the residuals.

Usage

pl.ds(x, yd, ys, xlab = "", ylab = "", ylim = rrange(c(yd, ys)),
      xpd = TRUE, do.seg = TRUE, seg.p = 0.95,
      segP = list(lty = 2, lwd = 1,   col = 2),
      linP = list(lty = 1, lwd = 2.5, col = 3),
      ...)

Arguments

x, yd, ys
numeric vectors all of the same length, representing $(x_i, y_i)$ and fitted (smooth) values $\hat{y}_i$. Note that x will be sort increasingly if necessary, and yd and ys accordingly.
xlab, ylab
x- and y- axis labels, as in plot.default.
ylim
limits of y-axis to be used; defaults to a robust range of the values.
xpd
see par(xpd=.); by default do allow to draw outside the plot region.
do.seg
logical indicating if residual segments should be drawn, at x[i], from yd[i] to ys[i] (approximately, see seg.p).
seg.p
segment percentage of segments to be drawn, from yd to seg.p*ys + (1-seg.p)*yd.
segP
list with named components lty, lwd, col specifying line type, width and color for the residual segments, used only when do.seg is true.
linP
list with named components lty, lwd, col specifying line type, width and color for smooth curve lines.
...
further arguments passed to plot.

Examples

Run this code
data(cars)
 x <-  cars$speed
 yd <- cars$dist
 ys <- lowess(x, yd,f = .2)$y
 pl.ds(x, yd, ys)

 ## More interesting : Version of example(Theoph)
 data(Theoph)
 Th4 <- subset(Theoph, Subject == 4)
 fm1 <- nls(conc ~ SSfol(Dose, Time, lKe, lKa, lCl), data = Th4)
 pl.ds(Th4$Time, Th4$conc, fitted(fm1),
       sub  = "Theophylline data - Subject 4 only",
       segP = list(lty=1,col=2), las = 1)
 xvals <- seq(0, par("usr")[2], len = 55)
 lines(xvals, predict(fm1, newdata = list(Time = xvals)), col = 4)

Run the code above in your browser using DataLab