The Nadaraya--Watson kernel regression estimate.
ksmooth(x, y, kernel = c("box", "normal"), bandwidth = 0.5,
range.x = range(x),
n.points = max(100L, length(x)), x.points)
input x values. Long vectors are supported.
input y values. Long vectors are supported.
the kernel to be used. Can be abbreviated.
the bandwidth. The kernels are scaled so that their
quartiles (viewed as probability densities) are at
0.25*bandwidth
.
the range of points to be covered in the output.
the number of points at which to evaluate the fit.
points at which to evaluate the smoothed fit. If
missing, n.points
are chosen uniformly to cover
range.x
. Long vectors are supported.
A list with components
values at which the smoothed fit is evaluated. Guaranteed to be in increasing order.
fitted values corresponding to x
.
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)
})
Run the code above in your browser using DataLab