plugin.density {plugdensity}R Documentation

Kernel Density Estimation by Plug-In Bandwidth Selection

Description

The function provides kernel density estimation with iterative plug-in bandwidth selection.

Usage

plugin.density(x, nout = 201, xout = NULL, na.rm = FALSE)

Arguments

x

vector of numbser whose density is to be estimated.

nout

integer specifying the number of equispaced xout values to use only when xout = NULL (as by default).

xout

numeric vector of abscissa values at which the density is to be evaluated. By default, an equispaced sequence of values covering (slightly more than) the range of x.

na.rm

logical; if TRUE, missing values are removed from x. If FALSE any missing values cause an error.

Value

an object of class "densityEHpi" inheriting also from class "density". It is a list with components

x

the n coordinates of the points where the density is estimated.

y

the estimated density values.

bw

the bandwidth used.

n

the sample size after elimination of missing values.

call

the call which produced the result.

data.name

the deparsed name of the x argument.

Author(s)

Algorithm and C code: Eva Herrmann eherrmann@mathematik.tu-darmstadt.de; R interface: Martin Maechler maechler@R-project.org.

References

J. Engel, Eva Herrmann and Theo Gasser (1994). An iterative bandwidth selector for kernel estimation of densities and their derivatives. Journal of Nonparametric Statistics 4, 21–34.

See Also

density.

Examples

data(co2)
plot(dco2 <- density(co2), ylim = c(0, 0.03))
(pdco2 <- plugin.density(co2, xout = dco2$x))
lines(pdco2, col = "red")

plot(pdco2)# calls 'plot.density' method

str(pdco2 <- plugin.density(co2))
xo <- pdco2 $x
str(d.co2 <- density(co2, n = length(xo), from=xo[1],to=max(xo),
                     width= 4 * pdco2$bw))
nms <- c("x","y", "bw", "n")
all.equal(d.co2[nms], pdco2[nms])
## are close: "Component 2 (= 'y'): Mean relative difference: 0.0009..."

[Package plugdensity version 0.8-3 Index]