ksmooth(x, y=NULL, kernel="box", bandwidth=0.5, range.x=range(x), n.points=length(x), x.points=<<see below>>)
x
, and
missing values are not accepted.
kernel
can be:
"box"
- a rectangular box (the default).
"triangle"
- a triangle (a box convolved with itself).
"parzen"
- the parzen function (a box convolved with a triangle).
"normal"
- the gaussian density function.
bandwidth
is
1
.
Larger values of
bandwidth
make smoother estimates,
smaller values of
bandwidth
make less smooth estimates.
x
at which to
compute the estimate.
range.x
can not be given if
x.points
is supplied.
range.x
.
n.points
can not be given if
x.points
is supplied.
seq(range.x[1], range.x[2], length=n.points)
for density estimates and to
x
for regression estimates.
Note that if
x.points
is supplied then neither
range.x
nor
n.points
can be supplied.
y
is specified, a kernel regression estimate of E[Y|X] is computed.
If
y
is missing, a density estimate of
x
is computed.
x
.
Silverman, B. W. (1986).
Density Estimation for Statistics and Data Analysis.
Chapman and Hall, London.
Watson, G. S. (1966).
Smooth regression analysis.
Sankha, Ser. A
26, 359-378.
The chapter "Regression and Smoothing for Continuous Response Data"
in the S-PLUS Guide to Statistics.
# Make up some data: x <- rnorm(100); eps <- rnorm(100, 0, .1) y <- sin(x) + eps # A kernel density estimate for x ksmx <- ksmooth(x, ker="parzen", bandwidth=1, n.points=50) plot(ksmx, type='l') rugplot(x) # Add x locations at bottom of plot # A kernel regression estimate for y on x. ksmxy <- ksmooth(x, y, "normal", ban=.5, n=50) plot(x, y) lines(ksmxy)