General Instructions
To do each example, just click the Submit
button.
You do not have to type in any R instructions or specify a dataset.
That's already done for you.
Notes
The handout for smoothing is available in Adobe PDF format. Paper copies were handed out in class. No need to print out another if you got one in class.
Local Polynomial Smoother
We use for example data the cholostyramine data from Section 7.3 in Efron and Tibshirani.
The KernSmooth package for R has a function dpill
that does bandwidth selection for local polynomial smoothing by what it
calls direct plug-in methodology
, which, unfortunately, is not
explained in the handout.
Help
The on-line help for the locpoly function.
The on-line help for the dpill function.
Smoothing Spline
We use for example data the cholostyramine data from Section 7.3 in Efron and Tibshirani.
The smooth.spline function does automatic smoothing parameter
selection by either CV or GCV (the default is GCV) when neither of the
arguments bandwidth or spar is supplied.
Help
The on-line help for the smooth.spline function.
Another Smoothing Spline
We use for example data the cholostyramine data from Section 7.3 in Efron and Tibshirani.
The mgcv package for R has a function does
generalized additive models
(the subject of Hastie and Tibshirani, 1990).
The univariate models are either cubic smoothing splines
(explained in the handout) or thin plate splines
(not explained in the handout).
This package has functions
-
gamfits generalized additive models -
gam.checkshows diagnostic plots -
summaryprints regression summaries -
plotprints estimated regression curves with confidence bands
Help
The on-line help for the gam function.
The on-line help for the gam.check function.
The on-line help for the plot.gam function.
The on-line help for the summary.gam function.
Comments
This package is much more ambitious than the other smoothing methods we have discussed. It is the only that does multiple regression models (so-called generalized additive models) of the form
where s1, s2, … sk are arbitrary smooth functions to be estimated.
Another Kernel Smoother
We use for example data the cholostyramine data from Section 7.3 in Efron and Tibshirani.
The sm package for R also does kernel smoothing.
It has a function sm.regression that does kernel smoothing
and a function h.select
that does bandwidth selection for kernel smoothing by cross validation.
Help
The on-line
help for the h.select function.
The
on-line
help for the sm.regression function.
The on-line
help for the sm.options function (describes some arguments
to the other two functions).
Try Two
This function, in violation of R principles, makes its own, somewhat funny looking plot. To get it to make a plot just like the other functions, we need some contortions.
All Together Now