ksmooth
Kernel Regression Smoother
Description
The Nadaraya–Watson kernel regression estimate.
Usage
ksmooth(x, y, kernel = c("box", "normal"), bandwidth = 0.5, range.x = range(x), n.points = max(100L, length(x)), x.points)
Arguments
x | input x values. Long vectors are supported. |
y | input y values. Long vectors are supported. |
kernel | the kernel to be used. Can be abbreviated. |
bandwidth | the bandwidth. The kernels are scaled so that their quartiles (viewed as probability densities) are at +/- |
range.x | the range of points to be covered in the output. |
n.points | the number of points at which to evaluate the fit. |
x.points | points at which to evaluate the smoothed fit. If missing, |
Value
A list with components
x | values at which the smoothed fit is evaluated. Guaranteed to be in increasing order. |
y | fitted values corresponding to |
Note
This function was implemented for compatibility with S, although it is nowhere near as slow as the S function. Better kernel smoothers are available in other packages such as KernSmooth.
Examples
require(graphics) with(cars, { plot(speed, dist) lines(ksmooth(speed, dist, "normal", bandwidth = 2), col = 2) lines(ksmooth(speed, dist, "normal", bandwidth = 5), col = 3) })
Copyright (©) 1999–2012 R Foundation for Statistical Computing.
Licensed under the GNU General Public License.