plsmo {Hmisc}R Documentation

Plot smoothed estimates

Description

Plot smoothed estimates of x vs. y, handling missing data for lowess or supsmu, and adding axis labels. Optionally suppresses plotting extrapolated estimates. An optional group variable can be specified to compute and plot the smooth curves by levels of group. When group is present, the datadensity option will draw tick marks showing the location of the raw x-values, separately for each curve. plsmo has an option to plot connected points for raw data, with no smoothing.

panel.plsmo is a panel function for trellis for the xyplot function that uses plsmo and its options to draw one or more nonparametric function estimates on each panel. This has advantages over using xyplot with panel.xyplot and panel.loess: (1) by default it will invoke labcurve to label the curves where they are most separated, (2) the datadensity option will put rug plots on each curve (instead of a single rug plot at the bottom of the graph), and (3) when panel.plsmo invokes plsmo it can use the "super smoother" (supsmu function) instead of lowess. panel.plsmo senses when a group variable is specified to xyplot so that it can invoke panel.superpose instead of panel.xyplot. Using panel.plsmo through trellis has some advantages over calling plsmo directly in that conditioning variables are allowed and trellis uses nicer fonts etc.

When a group variable was used, panel.plsmo creates a function Key in the session frame that the user can invoke to draw a key for individual data point symbols used for the groups. By default, the key is positioned at the upper right corner of the graph. If Key(locator(1)) is specified, the key will appear so that its upper left corner is at the coordinates of the mouse click.

Usage

plsmo(x, y, method=c("lowess","supsmu","raw"), xlab, ylab, 
      add=FALSE, lty=1:nlev, col=par("col"), lwd=par("lwd"),
      iter=if(length(unique(y))>2) 3 else 0, bass=0, trim, 
      fun, group, prefix, xlim, ylim, 
      label.curves=TRUE, datadensity=FALSE, lines.=TRUE, subset=TRUE,
      grid=FALSE, ...)

#To use panel function:
#xyplot(formula=y ~ x | conditioningvars, groups,
#       panel=panel.plsmo, type='b', 
#       label.curves=TRUE,
#       lwd = superpose.line$lwd, 
#       lty = superpose.line$lty, 
#       pch = superpose.symbol$pch, 
#       cex = superpose.symbol$cex, 
#       font = superpose.symbol$font, 
#       col = NULL, ...)

Arguments

x vector of x-values, NAs allowed
y vector of y-values, NAs allowed
method "lowess" (the default), "supsmu", or "raw" to not smooth at all
xlab x-axis label iff add=F. Defaults of label(x) or argument name.
ylab y-axis label, like xlab.
add Set to T to call lines instead of plot. Assumes axes already labeled.
lty line type, default=1,2,3,..., corresponding to group
col color for each curve, corresponding to group. Default is current par("col").
lwd vector of line widths for the curves, corresponding to group. Default is current par("lwd"). lwd can also be specified as an element of label.curves if label.curves is a list.
iter iter parameter if method="lowess", default=0 if y is binary, and 3 otherwise.
bass bass parameter if method="bass", default=0.
trim only plots smoothed estimates between trim and 1-trim quantiles of x. Default is to use 10th smallest to 10th largest x in the group if the number of observations in the group exceeds 200 (0 otherwise). Specify trim=0 to plot over entire range.
fun after computing the smoothed estimates, if fun is given the y-values are transformed by fun()
group a variable, either a factor vector or one that will be converted to factor by plsmo, that is used to stratify the data so that separate smooths may be computed
prefix a character string to appear in group of group labels. The presence of prefix ensures that labcurve will be called even when add=TRUE.
xlim a vector of 2 x-axis limits. Default is observed range.
ylim a vector of 2 y-axis limits. Default is observed range.
label.curves set to FALSE to prevent labcurve from being called to label multiple curves corresponding to groups. Set to a list to pass options to labcurve. lty and col are passed to labcurve automatically.
datadensity set to TRUE to draw tick marks on each curve, using x-coordinates of the raw data x values. This is done using scat1d.
lines. set to FALSE to suppress smoothed curves from being drawn. This can make sense if datadensity=TRUE.
subset a logical or integer vector specifying a subset to use for processing, with respect too all variables being analyzed
grid set to TRUE if the R grid package drew the current plot
... optional arguments that are passed to scat1d, or optional parameters to pass to plsmo from panel.plsmo. See optional arguments for plsmo above.
type set to p to have panel.plsmo plot points (and not call plsmo), l to call plsmo and not plot points, or use the default b to plot both.
pch
cex
font vectors of graphical parameters corresponding to the groups (scalars if group is absent). By default, the parameters set up by trellis will be used.

Value

plsmo returns a list of curves (x and y coordinates) that was passed to labcurve

Side Effects

plots, and panel.plsmo creates the Key function in the session frame.

See Also

lowess, supsmu, label, quantile, labcurve, scat1d, xyplot, panel.superpose, panel.xyplot

Examples

set.seed(1)
x <- 1:100
y <- x + runif(100, -10, 10)
plsmo(x,y,"supsmu",xlab="Time of Entry") 
#Use label(y) or "y" for ylab

plsmo(x,y,add=TRUE,lty=2)
#Add lowess smooth to existing plot, with different line type

age <- rnorm(500, 50, 15)
survival.time <- rexp(500)
sex <- sample(c('female','male'), 500, TRUE)
race <- sample(c('black','non-black'), 500, TRUE)
plsmo(age, survival.time < 1, fun=qlogis, group=sex) # plot logit by sex

#Plot points and smooth trend line using trellis 
# (add type='l' to suppress points or type='p' to suppress trend lines)
if(.R.) library(lattice)
xyplot(survival.time ~ age, panel=panel.plsmo)

#Do this for multiple panels
xyplot(survival.time ~ age | sex, panel=panel.plsmo)

#Do this for subgroups of points on each panel, show the data
#density on each curve, and draw a key at the default location
xyplot(survival.time ~ age | sex, groups=race, panel=panel.plsmo,
       datadensity=TRUE)
Key()

#Use wloess.noiter to do a fast weighted smooth
plot(x, y)
lines(wtd.loess.noiter(x, y))
lines(wtd.loess.noiter(x, y, weights=c(rep(1,50), 100, rep(1,49))), col=2)
points(51, y[51], pch=18)   # show overly weighted point
#Try to duplicate this smooth by replicating 51st observation 100 times
lines(wtd.loess.noiter(c(x,rep(x[51],99)),c(y,rep(y[51],99)),
      type='ordered all'), col=3)
#Note: These two don't agree exactly

[Package Hmisc version 3.0-10 Index]