Title: | Plug-in Kernel Density Estimation |
---|---|
Description: | Kernel density estimation with global bandwidth selection via "plug-in". |
Authors: | Eva Herrmann [aut] (C original), Martin Maechler [cre, aut] (R Interface etc++, <https://orcid.org/0000-0002-8685-9910>) |
Maintainer: | Martin Maechler <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.8-6 |
Built: | 2024-12-17 19:18:36 UTC |
Source: | https://github.com/r-forge/curves-etc |
The function plugin.density()
provides kernel density estimation
with iterative plug-in bandwidth selection.
bw.EH()
computes the bandwidth (smoothing parameter) which
plugin.density()
also uses.
plugin.density(x, nout = 201, xout = NULL, na.rm = FALSE) bw.EH(x)
plugin.density(x, nout = 201, xout = NULL, na.rm = FALSE) bw.EH(x)
x |
vector of numbser whose density is to be estimated. |
nout |
integer specifying the number of equispaced |
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 |
na.rm |
logical; if |
bw.EH()
returns the bandwidth computed by Eva Herrmann's
plugin bandwith selector.
plugin.density()
returns an object of class "densityEHpi"
inheriting also from class "density"
.
It is a list
with components
x |
the |
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 |
Algorithm and C code: Eva Herrmann [email protected]; R interface: Martin Maechler [email protected].
Original code, no longer available, from ‘http://www.unizh.ch/biostat/Software/’ .
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.
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..." ## be.EH() directly computes the bandwidth only: stopifnot(all.equal(bw.EH(co2), pdco2$bw, tol = 3e-16))
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..." ## be.EH() directly computes the bandwidth only: stopifnot(all.equal(bw.EH(co2), pdco2$bw, tol = 3e-16))