| Title: | Kernel Estimator and Bandwidth Selection for Density and Its Derivatives |
|---|---|
| Description: | Kernel estimation of a univariate probability density and of its derivatives of any order r, with data-driven bandwidth selection. Provides the kernel estimator of the derivative of order r, the kernels, their derivatives and convolutions, and eight bandwidth selectors: the asymptotic MISE rule (AMISE), and unbiased (UCV), biased (BCV1, BCV2), complete (CCV), modified (MCV), trimmed (TCV), smoothed (SCV) and maximum-likelihood (MLCV) cross-validation. Supports ten named kernels (Gaussian, Epanechnikov, uniform, triangular, biweight, triweight, tricube, cosine, Silverman, logistic) and the power family Pow(s,t), c(1-|x|^s)^t on [-1,1]. Results are S4 objects with 'ggplot2' graphics; the O(n^2) criteria are computed in C++ ('Rcpp') with 'OpenMP' parallelism. Includes five example samples from Marron and Wand (1992) normal mixtures, a vignette and demos. Companion to Guidoum (2020) <doi:10.48550/arXiv.2012.06102>. |
| Authors: | Arsalane Chouaib Guidoum [aut, cre] (ORCID: <https://orcid.org/0000-0003-3781-2160>), Amel Henider [aut], Iago Giné-Vázquez [ctb] (ORCID: <https://orcid.org/0000-0002-6725-2638>) |
| Maintainer: | Arsalane Chouaib Guidoum <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 2.0.0 |
| Built: | 2026-11-02 12:44:43 UTC |
| Source: | https://github.com/ac-guidoum/kedd |
Kernel smoothing of a univariate density and of its -th
derivative :
with S4 classes, ggplot2 graphics and Rcpp/OpenMP data-driven bandwidth selectors.
Kernels. Every function accepts kernel as one of
"gaussian", "epanechnikov", "uniform",
"triangular", "biweight", "triweight",
"tricube", "cosine", "silverman", "logistic",
or a member "pow(s,t)" of the power family
(see
kernel.pow).
Maximum derivative order for each kernel (see the section
below).
Bandwidth selectors (S4 class bandwidth):
h.amise |
asymptotic MISE (normal reference) |
h.ucv |
unbiased (least-squares) cross-validation |
h.bcv |
biased cross-validation (BCV1, BCV2) |
h.ccv |
complete cross-validation |
h.mcv |
modified cross-validation |
h.tcv |
trimmed cross-validation |
h.scv |
smoothed cross-validation (Gaussian) |
h.mlcv |
maximum-likelihood cross-validation |
Estimation and kernels: dkde (S4 class
dkde), kernel.fun (, class kfun),
kernel.conv (, class kconv).
All classes have show() and ggplot2-based plot() methods;
lines() on a bandwidth object returns a layer to add with
+.
Parallelism: the criteria run in C++ with OpenMP. The
nthreads argument sets the threads of each call: 0 (default) =
all processors, k > 0 = k threads, capped by
OMP_THREAD_LIMIT; it does not change results nor later calls.
Cpp_omp_threads(nthreads) reports the threads actually used.
Data: five samples of size 200 from Marron and Wand (1992) normal
mixtures, kurtotic, outlier, bimodal, trimodal
and claw (see kedd-data).
Source code and bug reports: https://github.com/ac-guidoum/kedd and https://github.com/ac-guidoum/kedd/issues.
Documentation: a worked introduction is given in
vignette("kedd", package = "kedd"), and demonstrations in
demo("kedd"), demo("kernels") and demo("bandwidths").
Highest derivative order (deriv.order) for each kernel.
Column 2: is not identically zero (kernel.fun,
kernel.conv, dkde); above it these functions
return zero. Columns 3 to 5: the selector criterion is finite; above it the
selectors return h = NA with a warning. "any" means no limit and "–"
means not available, even at .
| kernel | kernel.fun, kernel.conv, dkde | UCV, BCV, TCV, AMISE | MCV | CCV |
gaussian |
any | any | any | any |
cosine |
any | 1 | 0 | -- |
silverman |
any | any | any | any |
logistic |
20 | 8 | 8 | 8 |
epanechnikov |
2 | 1 | 0 | -- |
uniform |
0 | 0 | -- | -- |
triangular |
1 | 0 | -- | -- |
biweight |
4 | 2 | 1 | 0 |
triweight |
6 | 3 | 2 | 1 |
tricube |
9 | 3 | 2 | 1 |
pow(s,t) |
|
|
|
|
For pow(s,t), applies when and are integers
(16 otherwise), and is the largest integer
, with when and
are integers and when is not an even integer.
For example pow(2,3): 6, 3, 2, 1; pow(2,8): 16, 6, 6, 6;
pow(1.5,2.5): 16, 1, 0, –.
h.scv (Gaussian kernel) has no limit and h.mlcv
is for only.
Arsalane Chouaib Guidoum [email protected] (author, maintainer), Amel Henider [email protected] (author), Iago Giné-Vázquez [email protected] (contributor).
Guidoum, A. C. (2020). Kernel estimator and bandwidth selection for density and its derivatives: the kedd package. arXiv:2012.06102.
Marron, J. S. and Wand, M. P. (1992). Exact mean integrated squared error. The Annals of Statistics, 20, 712–736.
Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.
dkde, kernel.fun, kernel.conv,
kernel.pow, h.ucv, h.scv,
bandwidth, kedd-data,
vignette("kedd"), citation("kedd").
x <- rnorm(150) bw <- h.ucv(x, kernel = "biweight") bw plot(dkde(data = x, h = bw@h, kernel = "biweight")) ## logistic and power kernels h.bcv(x, whichbcv = 2, kernel = "logistic") h.bcv(x, whichbcv = 2, kernel = kernel.pow(2, 4))x <- rnorm(150) bw <- h.ucv(x, kernel = "biweight") bw plot(dkde(data = x, h = bw@h, kernel = "biweight")) ## logistic and power kernels h.bcv(x, whichbcv = 2, kernel = "logistic") h.bcv(x, whichbcv = 2, kernel = kernel.pow(2, 4))
"bandwidth" — Result of Bandwidth SelectionAn S4 class returned by all bandwidth selector functions in kedd
(h.ucv, h.bcv, h.ccv,
h.mcv, h.tcv, h.scv,
h.amise, h.mlcv). It stores the selected bandwidth together with
the data, kernel, derivative order, and optimisation details.
Objects are created by calls to the bandwidth selector functions, or
directly with new("bandwidth", ...).
data:Object of class "numeric". The (cleaned)
data vector.
kernel:Object of class "character". Name of the
kernel function used (one of "gaussian", "epanechnikov",
"triangular", "biweight", "uniform",
"triweight", "tricube", "cosine",
"silverman", "logistic" or "pow(s,t)").
deriv.order:Object of class "integer". Derivative
order .
h:Object of class "numeric". The selected
bandwidth.
min.obj:Object of class "numeric". The minimum
value of the cross-validation (or other) criterion at h.
NA for h.amise.
hos:Object of class "numeric". The
over-smoothing bandwidth ; the default search
interval is .
method:Object of class "character". The
selector used: one of "UCV", "BCV1", "BCV2",
"CCV", "MCV", "TCV", "SCV",
"AMISE", "MLCV".
show(object)Prints a compact summary: method, kernel, derivative order, selected bandwidth, minimum criterion.
plot(x, h = NULL, type = "o", n.points = 100L,
log_scale_x = FALSE, show.min = TRUE, show.hos = FALSE, ...)Draws
the cross-validation curve over a grid of bandwidths with ggplot2
and marks the selected h. Returns invisibly a list with
h, cv and the ggplot object plot. Not available
for "AMISE" (closed-form rule, no criterion).
lines(x, n.points = 100L, color, linewidth, linetype, ...)Returns
a ggplot2::geom_line() layer with the curve of x, to be
added to a plot: plot(bw1)$plot + lines(bw2).
x$nameCompatibility with kedd 1.x, where the
selectors returned a list: bw$h is bw@h, and $
also accepts the slot names, x (the data), n and the
1.x names min.ucv, min.bcv, ... (the slot
min.obj). Unknown names give NULL.
Arsalane Chouaib Guidoum [email protected]
h.ucv, h.bcv, h.ccv,
h.mcv, h.tcv, h.scv,
h.amise, h.mlcv, dkde.
x <- rnorm(100) bw <- h.ucv(x, deriv.order = 0) show(bw) p <- plot(bw) ## overlay a second criterion (ggplot2 layer) p$plot + lines(h.bcv(x), color = "darkred")x <- rnorm(100) bw <- h.ucv(x, deriv.order = 0) show(bw) p <- plot(bw) ## overlay a second criterion (ggplot2 layer) p$plot + lines(h.bcv(x), color = "darkred")
Computes the r'th derivative of a kernel density estimator at a grid
of evaluation points. For deriv.order = 0 this reduces to an
ordinary kernel density estimate.
dkde(x = NULL, data, h, deriv.order = 0L, kernel = "gaussian", nthreads = 0L)dkde(x = NULL, data, h, deriv.order = 0L, kernel = "gaussian", nthreads = 0L)
x |
numeric vector of evaluation points. If |
data |
numeric vector of observations. |
h |
positive bandwidth scalar. If missing, the UCV bandwidth
|
deriv.order |
non-negative integer: derivative order |
kernel |
character string giving the kernel; one of
|
nthreads |
number of OpenMP threads for this call: |
The r'th derivative kernel density estimator is:
where
(see kernel.fun).
Theoretical properties (Bhattacharya 1967; Schuster 1969):
Bias:
Variance:
The AMISE-optimal bandwidth is of order ,
so higher derivatives require larger bandwidths.
The AMISE is:
where and
.
An S4 object of class dkde with slots x
(evaluation points), y (estimates
), h, kernel,
deriv.order, n, data and call. Use
show() for a summary and plot() for a ggplot2 graphic.
Arsalane Chouaib Guidoum [email protected]
Bhattacharya, P. K. (1967). Estimation of a probability density function and its derivatives. Sankhya: The Indian Journal of Statistics, Series A, 29, 373–382.
Radhey, S. S. (1987). MISE of kernel estimates of a density and its derivatives. Statistics and Probability Letters, 5, 153–159.
Schuster, E. F. (1969). Estimation of a probability density function and its derivatives. The Annals of Mathematical Statistics, 40(4), 1187–1195.
Scott, D. W. (1992). Multivariate Density Estimation. Theory, Practice and Visualization. New York: Wiley.
Silverman, B. W. (1986). Density Estimation for Statistics and Data Analysis. Chapman & Hall/CRC. London.
Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.
Härdle, W. (1991). Smoothing Techniques, With Implementation in S. Springer-Verlag, New York.
kernel.fun, h.ucv, h.bcv,
h.amise, density (for ).
x <- rnorm(100) ## density (r = 0) with automatic UCV bandwidth est0 <- dkde(data = x, deriv.order = 0) est0 plot(est0) ## first derivative (r = 1) est1 <- dkde(data = x, deriv.order = 1) plot(est1) ## fixed bandwidth, other kernels; slots are accessed with @ est2 <- dkde(data = x, h = 0.5, kernel = "epanechnikov") head(cbind(x = est2@x, y = est2@y)) plot(dkde(data = x, h = 0.6, kernel = kernel.pow(2, 3)), rug = FALSE)x <- rnorm(100) ## density (r = 0) with automatic UCV bandwidth est0 <- dkde(data = x, deriv.order = 0) est0 plot(est0) ## first derivative (r = 1) est1 <- dkde(data = x, deriv.order = 1) plot(est1) ## fixed bandwidth, other kernels; slots are accessed with @ est2 <- dkde(data = x, h = 0.5, kernel = "epanechnikov") head(cbind(x = est2@x, y = est2@y)) plot(dkde(data = x, h = 0.6, kernel = kernel.pow(2, 3)), rug = FALSE)
Computes the reference bandwidth for the r'th
derivative of a kernel density estimator: the AMISE-optimal bandwidth in
which is replaced by the value given by the
maximal smoothing principle of Terrell (1990). For it is the
oversmoothed bandwidth, an upper bound for the optimal one. Returns an S4
object of class bandwidth.
h.amise(x, deriv.order = 0L, kernel = "gaussian")h.amise(x, deriv.order = 0L, kernel = "gaussian")
x |
numeric vector of data values. |
deriv.order |
non-negative integer: derivative order |
kernel |
character string giving the kernel; one of
|
The AMISE of the r'th derivative estimator is (Scott 1992, p.\,131):
The minimising bandwidth is:
is replaced by
(maximal smoothing principle, Terrell 1990), where
is the sample standard deviation, which gives
The same value bounds the search interval of the cross-validation
selectors ().
No optimisation is performed; the result is computed directly.
,
.
An S4 object of class bandwidth with slots:
datathe (cleaned) data vector.
kernelname of the kernel used.
deriv.orderderivative order .
hreference bandwidth .
min.objNA (no minimisation is performed).
hossame as h (the reference bandwidth).
method"AMISE".
Arsalane Chouaib Guidoum [email protected]
Radhey, S. S. (1987). MISE of kernel estimates of a density and its derivatives. Statistics and Probability Letters, 5, 153–159.
Scott, D. W. (1992). Multivariate Density Estimation. Theory, Practice and Visualization. New York: Wiley.
Silverman, B. W. (1986). Density Estimation for Statistics and Data Analysis. Chapman & Hall/CRC. London.
Terrell, G. R. (1990). The maximal smoothing principle in density estimation. Journal of the American Statistical Association, 85, 470–477.
Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.
bandwidth, h.ucv, h.bcv,
h.ccv, h.mcv, h.tcv, h.scv,
h.mlcv, dkde.
x <- rnorm(100) ## density (r = 0) bw0 <- h.amise(x, deriv.order = 0) show(bw0) ## first derivative (r = 1) bw1 <- h.amise(x, deriv.order = 1) show(bw1) ## other kernels on a Marron-Wand sample h.amise(kurtotic, kernel = "logistic") h.amise(kurtotic, kernel = kernel.pow(2, 4))x <- rnorm(100) ## density (r = 0) bw0 <- h.amise(x, deriv.order = 0) show(bw0) ## first derivative (r = 1) bw1 <- h.amise(x, deriv.order = 1) show(bw1) ## other kernels on a Marron-Wand sample h.amise(kurtotic, kernel = "logistic") h.amise(kurtotic, kernel = kernel.pow(2, 4))
Computes the biased cross-validation bandwidth selector (BCV1 or BCV2)
of the r'th derivative of a kernel density estimator (one-dimensional).
Returns an S4 object of class bandwidth.
h.bcv(x, whichbcv = 1L, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)h.bcv(x, whichbcv = 1L, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)
x |
numeric vector of data values. |
whichbcv |
integer: |
deriv.order |
non-negative integer: derivative order |
kernel |
character string giving the kernel; one of
|
lower, upper
|
bounds of the search interval. Defaults to
|
tol |
convergence tolerance for |
nthreads |
number of OpenMP threads for this call: |
Let
and
BCV1 (Scott and Terrell 1987) minimises:
BCV2 (Jones and Kappenman 1991) minimises:
where is the convolution of the
r'th kernel derivative (see kernel.conv,
kernel.fun),
,
.
The search is bounded by the over-smoothing bandwidth hos
(Terrell and Scott 1985; Scott 1992, p.\,165; Wand and Jones 1995, p.\,61).
An S4 object of class bandwidth with slots:
datathe (cleaned) data vector.
kernelname of the kernel used.
deriv.orderderivative order .
hselected bandwidth.
min.objminimum BCV value.
hosover-smoothing bandwidth (upper bound).
method"BCV1" or "BCV2".
Arsalane Chouaib Guidoum [email protected]
Jones, M. C. and Kappenman, R. F. (1991). On a class of kernel density estimate bandwidth selectors. Scandinavian Journal of Statistics, 19, 337–349.
Peter, H. and Marron, J. S. (1987). Estimation of integrated squared density derivatives. Statistics and Probability Letters, 6, 109–115.
Scott, D. W. and Terrell, G. R. (1987). Biased and unbiased cross-validation in density estimation. Journal of the American Statistical Association, 82, 1131–1146.
Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.
Härdle, W. (1991). Smoothing Techniques, With Implementation in S. Springer-Verlag, New York.
bandwidth, h.ucv, h.ccv,
h.mcv, h.tcv, h.scv, h.amise,
kernel.conv, kernel.fun, dkde.
x <- rnorm(100) ## BCV1, density (r = 0) bw1 <- h.bcv(x, whichbcv = 1, deriv.order = 0) show(bw1) ## BCV2, first derivative (r = 1) bw2 <- h.bcv(x, whichbcv = 2, deriv.order = 1) show(bw2) plot(bw2) ## other kernels on a Marron-Wand sample h.bcv(bimodal, kernel = "logistic") h.bcv(bimodal, whichbcv = 2, kernel = kernel.pow(2, 4))x <- rnorm(100) ## BCV1, density (r = 0) bw1 <- h.bcv(x, whichbcv = 1, deriv.order = 0) show(bw1) ## BCV2, first derivative (r = 1) bw2 <- h.bcv(x, whichbcv = 2, deriv.order = 1) show(bw2) plot(bw2) ## other kernels on a Marron-Wand sample h.bcv(bimodal, kernel = "logistic") h.bcv(bimodal, whichbcv = 2, kernel = kernel.pow(2, 4))
Computes the complete cross-validation bandwidth selector of the r'th
derivative of a kernel density estimator (one-dimensional).
Returns an S4 object of class bandwidth.
h.ccv(x, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)h.ccv(x, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)
x |
numeric vector of data values. |
deriv.order |
non-negative integer: derivative order |
kernel |
character string giving the kernel; one of
|
lower, upper
|
bounds of the search interval. Defaults to
|
tol |
convergence tolerance for |
nthreads |
number of OpenMP threads for this call: |
Jones and Kappenman (1991) proposed complete cross-validation
(CCV) for kernel density estimation. The method estimates the
integrated squared density derivative using
(Peter and Marron 1987).
minimises:
with
and
where ,
,
.
The search is bounded by the over-smoothing bandwidth hos
(Scott 1992, p.\,165; Wand and Jones 1995, p.\,61).
An S4 object of class bandwidth with slots:
datathe (cleaned) data vector.
kernelname of the kernel used.
deriv.orderderivative order .
hselected bandwidth.
min.objminimum CCV value.
hosover-smoothing bandwidth (upper bound).
method"CCV".
Arsalane Chouaib Guidoum [email protected]
Jones, M. C. and Kappenman, R. F. (1991). On a class of kernel density estimate bandwidth selectors. Scandinavian Journal of Statistics, 19, 337–349.
Peter, H. and Marron, J. S. (1987). Estimation of integrated squared density derivatives. Statistics and Probability Letters, 6, 109–115.
Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.
bandwidth, h.ucv, h.bcv,
h.mcv, h.tcv, h.scv, h.amise,
kernel.conv, kernel.fun.
x <- rnorm(100) ## density (r = 0) bw0 <- h.ccv(x, deriv.order = 0) show(bw0) plot(bw0) ## first derivative (r = 1) bw1 <- h.ccv(x, deriv.order = 1) show(bw1) ## other kernels on a Marron-Wand sample h.ccv(trimodal, kernel = "logistic") h.ccv(trimodal, kernel = "pow(2,3)")x <- rnorm(100) ## density (r = 0) bw0 <- h.ccv(x, deriv.order = 0) show(bw0) plot(bw0) ## first derivative (r = 1) bw1 <- h.ccv(x, deriv.order = 1) show(bw1) ## other kernels on a Marron-Wand sample h.ccv(trimodal, kernel = "logistic") h.ccv(trimodal, kernel = "pow(2,3)")
Computes the modified cross-validation bandwidth selector of the r'th
derivative of a kernel density estimator (one-dimensional).
Returns an S4 object of class bandwidth.
h.mcv(x, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)h.mcv(x, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)
x |
numeric vector of data values. |
deriv.order |
non-negative integer: derivative order |
kernel |
character string giving the kernel; one of
|
lower, upper
|
bounds of the search interval. Defaults to
|
tol |
convergence tolerance for |
nthreads |
number of OpenMP threads for this call: |
Stute (1992) proposed modified cross-validation (MCV), a
modification of unbiased cross-validation that approximates the
problematic term via the Hajek projection.
minimises:
where
and is the convolution of the
r'th kernel derivative (see kernel.conv,
kernel.fun),
,
.
The search is bounded by the over-smoothing bandwidth hos
(Scott 1992, p.\,165; Wand and Jones 1995, p.\,61).
An S4 object of class bandwidth with slots:
datathe (cleaned) data vector.
kernelname of the kernel used.
deriv.orderderivative order .
hselected bandwidth.
min.objminimum MCV value.
hosover-smoothing bandwidth (upper bound).
method"MCV".
Arsalane Chouaib Guidoum [email protected]
Heidenreich, N. B., Schindler, A. and Sperlich, S. (2013). Bandwidth selection for kernel density estimation: a review of fully automatic selectors. Advances in Statistical Analysis.
Stute, W. (1992). Modified cross validation in density estimation. Journal of Statistical Planning and Inference, 30, 293–305.
Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.
bandwidth, h.ucv, h.bcv,
h.ccv, h.tcv, h.scv, h.amise,
kernel.conv, kernel.fun.
x <- rnorm(100) ## density (r = 0) bw0 <- h.mcv(x, deriv.order = 0) show(bw0) plot(bw0) ## first derivative (r = 1) bw1 <- h.mcv(x, deriv.order = 1) show(bw1) ## other kernels on a Marron-Wand sample h.mcv(claw, kernel = "logistic") h.mcv(claw, kernel = kernel.pow(2, 2))x <- rnorm(100) ## density (r = 0) bw0 <- h.mcv(x, deriv.order = 0) show(bw0) plot(bw0) ## first derivative (r = 1) bw1 <- h.mcv(x, deriv.order = 1) show(bw1) ## other kernels on a Marron-Wand sample h.mcv(claw, kernel = "logistic") h.mcv(claw, kernel = kernel.pow(2, 2))
Computes the maximum-likelihood (Kullback-Leibler) cross-validation
bandwidth selector for a kernel density estimator (density estimation
only, deriv.order = 0).
Returns an S4 object of class bandwidth.
h.mlcv(x, kernel = "gaussian", lower, upper, tol, nthreads = 0L)h.mlcv(x, kernel = "gaussian", lower, upper, tol, nthreads = 0L)
x |
numeric vector of data values. |
kernel |
character string giving the kernel; one of
|
lower, upper
|
bounds of the search interval. Defaults to
|
tol |
convergence tolerance for |
nthreads |
number of OpenMP threads for this call: |
Habbema, Hermans, and Van den Broek (1974) and Duin (1976) proposed maximising the leave-one-out log-likelihood:
where the leave-one-out estimator is
Equivalently,
Only applicable to density estimation ().
An S4 object of class bandwidth with slots:
datathe (cleaned) data vector.
kernelname of the kernel used.
deriv.order0L (density only).
hselected bandwidth.
min.objnegative of the maximum MLCV value.
hosover-smoothing bandwidth (upper bound).
method"MLCV".
Arsalane Chouaib Guidoum [email protected]
Duin, R. P. W. (1976). On the choice of smoothing parameters of Parzen estimators of probability density functions. IEEE Transactions on Computers, C-25, 1175–1179.
Habbema, J. D. F., Hermans, J. and Van den Broek, K. (1974). A stepwise discrimination analysis program using density estimation. Compstat 1974: Proceedings in Computational Statistics. Physica Verlag, Vienna.
Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.
bandwidth, h.ucv, h.amise, h.scv,
dkde.
x <- rnorm(100) bw <- h.mlcv(x) show(bw) plot(bw) bw2 <- h.mlcv(x, kernel = "epanechnikov") show(bw2) ## other kernels on a Marron-Wand sample h.mlcv(outlier, kernel = "logistic") h.mlcv(outlier, kernel = "pow(2,2)")x <- rnorm(100) bw <- h.mlcv(x) show(bw) plot(bw) bw2 <- h.mlcv(x, kernel = "epanechnikov") show(bw2) ## other kernels on a Marron-Wand sample h.mlcv(outlier, kernel = "logistic") h.mlcv(outlier, kernel = "pow(2,2)")
Selects the bandwidth of the r'th derivative kernel density estimator by
minimising the smoothed cross-validation (SCV) criterion of Hall, Marron
and Park (1992). Returns an S4 object of class
bandwidth.
h.scv(x, g = NULL, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)h.scv(x, g = NULL, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)
x |
numeric vector of data values. |
g |
pilot bandwidth (positive number). If |
deriv.order |
non-negative integer: derivative order |
kernel |
must be |
lower, upper
|
bounds of the search interval. Defaults to
|
tol |
convergence tolerance for |
nthreads |
number of OpenMP threads for this call: |
With a Gaussian kernel and a Gaussian pilot estimate , the
integrated squared bias of is estimated in closed form
by derivatives of normal densities:
where ,
,
and
.
It follows from
.
For it is the criterion of Hall, Marron and Park (1992).
The default pilot bandwidth is the density pilot of Hall et al.; for
derivatives a pilot can be supplied through g.
An S4 object of class bandwidth with
method = "SCV".
Arsalane Chouaib Guidoum [email protected]
Hall, P., Marron, J. S. and Park, B. U. (1992). Smoothed cross-validation. Probability Theory and Related Fields, 92, 1–20.
x <- rnorm(200) bw <- h.scv(x) show(bw) plot(bw) ## first derivative (r = 1) bw1 <- h.scv(x, deriv.order = 1) plot(dkde(data = x, h = bw1@h, deriv.order = 1)) ## on a Marron-Wand sample (SCV is defined for the Gaussian kernel) h.scv(bimodal) h.scv(bimodal, deriv.order = 2)x <- rnorm(200) bw <- h.scv(x) show(bw) plot(bw) ## first derivative (r = 1) bw1 <- h.scv(x, deriv.order = 1) plot(dkde(data = x, h = bw1@h, deriv.order = 1)) ## on a Marron-Wand sample (SCV is defined for the Gaussian kernel) h.scv(bimodal) h.scv(bimodal, deriv.order = 2)
Computes the trimmed cross-validation bandwidth selector of the r'th
derivative of a kernel density estimator (one-dimensional).
Returns an S4 object of class bandwidth.
h.tcv(x, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)h.tcv(x, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)
x |
numeric vector of data values. |
deriv.order |
non-negative integer: derivative order |
kernel |
character string giving the kernel; one of
|
lower, upper
|
bounds of the search interval. Defaults to
|
tol |
convergence tolerance for |
nthreads |
number of OpenMP threads for this call: |
Feluch and Koronacki (1992) proposed trimmed cross-validation
(TCV), a modification of unbiased cross-validation that trims small
pairwise distances. minimises:
where
with (ensuring convergence),
the indicator function,
and the convolution of the
r'th kernel derivative (see kernel.conv,
kernel.fun).
The search is bounded by the over-smoothing bandwidth hos
(Scott 1992, p.\,165; Wand and Jones 1995, p.\,61).
An S4 object of class bandwidth with slots:
datathe (cleaned) data vector.
kernelname of the kernel used.
deriv.orderderivative order .
hselected bandwidth.
min.objminimum TCV value.
hosover-smoothing bandwidth (upper bound).
method"TCV".
Arsalane Chouaib Guidoum [email protected]
Feluch, W. and Koronacki, J. (1992). A note on modified cross-validation in density estimation. Computational Statistics and Data Analysis, 13, 143–151.
Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.
bandwidth, h.ucv, h.bcv,
h.ccv, h.mcv, h.amise, h.scv,
kernel.conv, kernel.fun.
x <- rnorm(100) ## density (r = 0) bw0 <- h.tcv(x, deriv.order = 0) show(bw0) plot(bw0) ## first derivative (r = 1) bw1 <- h.tcv(x, deriv.order = 1) show(bw1) ## other kernels on a Marron-Wand sample h.tcv(kurtotic, kernel = "logistic") h.tcv(kurtotic, kernel = "pow(2,3)")x <- rnorm(100) ## density (r = 0) bw0 <- h.tcv(x, deriv.order = 0) show(bw0) plot(bw0) ## first derivative (r = 1) bw1 <- h.tcv(x, deriv.order = 1) show(bw1) ## other kernels on a Marron-Wand sample h.tcv(kurtotic, kernel = "logistic") h.tcv(kurtotic, kernel = "pow(2,3)")
Computes the unbiased (least-squares) cross-validation bandwidth selector
of the r'th derivative of a kernel density estimator (one-dimensional).
Returns an S4 object of class bandwidth.
h.ucv(x, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)h.ucv(x, deriv.order = 0L, kernel = "gaussian", lower, upper, tol, nthreads = 0L)
x |
numeric vector of data values. |
deriv.order |
non-negative integer: derivative order |
kernel |
character string giving the kernel; one of
|
lower, upper
|
bounds of the search interval. Defaults to
|
tol |
convergence tolerance passed to |
nthreads |
number of OpenMP threads for this call: |
Rudemo (1982) and Bowman (1984) proposed unbiased (least-squares)
cross-validation (UCV) for kernel density estimation. Härdle,
Marron and Wand (1990) extended the criterion to the r'th derivative
estimator. The bandwidth minimises:
where is the convolution
of the r'th derivative of the kernel (see kernel.conv,
kernel.fun), and
.
UCV is unbiased in the sense that
(Scott and Terrell 1987).
The search is bounded by the over-smoothing bandwidth hos
(Terrell and Scott 1985; Scott 1992, p.\,165; Wand and Jones 1995, p.\,61).
An S4 object of class bandwidth with slots:
datathe (cleaned) data vector.
kernelname of the kernel used.
deriv.orderderivative order .
hselected bandwidth.
min.objminimum UCV value.
hosover-smoothing bandwidth (upper bound).
method"UCV".
Arsalane Chouaib Guidoum [email protected]
Bowman, A. (1984). An alternative method of cross-validation for the smoothing of kernel density estimates. Biometrika, 71, 353–360.
Rudemo, M. (1982). Empirical choice of histograms and kernel density estimators. Scandinavian Journal of Statistics, 9, 65–78.
Scott, D. W. and Terrell, G. R. (1987). Biased and unbiased cross-validation in density estimation. Journal of the American Statistical Association, 82, 1131–1146.
Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.
Härdle, W., Marron, J. S. and Wand, M. P. (1990). Bandwidth choice for density derivatives. Journal of the Royal Statistical Society, Series B, 223–232.
bandwidth, h.bcv, h.ccv,
h.mcv, h.tcv, h.scv, h.amise,
kernel.conv, kernel.fun, dkde.
x <- rnorm(100) ## density (r = 0) bw0 <- h.ucv(x, deriv.order = 0) show(bw0) plot(bw0) ## first derivative (r = 1) bw1 <- h.ucv(x, deriv.order = 1) show(bw1) ## other kernels on a Marron-Wand sample h.ucv(claw, kernel = "logistic") h.ucv(claw, kernel = "pow(2,3)")x <- rnorm(100) ## density (r = 0) bw0 <- h.ucv(x, deriv.order = 0) show(bw0) plot(bw0) ## first derivative (r = 1) bw1 <- h.ucv(x, deriv.order = 1) show(bw1) ## other kernels on a Marron-Wand sample h.ucv(claw, kernel = "logistic") h.ucv(claw, kernel = "pow(2,3)")
"dkde", "kfun" and "kconv"
S4 classes returned by dkde (kernel density derivative
estimate), kernel.fun (kernel derivative ) and
kernel.conv (convolution ).
Common to the three classes:
x:"numeric", evaluation points.
y:"numeric", values at x.
kernel:"character", kernel name.
deriv.order:"integer", derivative order .
call:"call", the matched call.
Class "dkde" has in addition:
h:"numeric", bandwidth used.
n:"integer", sample size.
data:"numeric", the (cleaned) observations.
show(object)prints a short summary.
plot(x, type = "l", zero.line, main.title, x.title, y.title,
colors, title.size, title.face, axis.size, theme, ...)draws the
curve with ggplot2, prints it and returns the ggplot object
invisibly. type is "l", "p" or "o";
zero.line (default TRUE when ) adds a dashed
horizontal line at 0. For "dkde" objects, rug and
band (default TRUE) add the observations and a
one standard-error band.
x$nameCompatibility with kedd 1.x, where these
functions returned lists: $kx is the slot y of
"kfun" and "kconv" objects, and $eval.points,
$est.fx are the slots x, y of "dkde"
objects; the slot names can also be used. Unknown names give
NULL.
Arsalane Chouaib Guidoum [email protected]
dkde, kernel.fun, kernel.conv,
bandwidth.
kf <- kernel.fun(kernel = "logistic", deriv.order = 1L) kf p <- plot(kf, type = "o") kc <- kernel.conv(kernel = "biweight") plot(kc) d <- dkde(data = rnorm(100), h = 0.4) plot(d, band = FALSE)kf <- kernel.fun(kernel = "logistic", deriv.order = 1L) kf p <- plot(kf, type = "o") kc <- kernel.conv(kernel = "biweight") plot(kc) d <- dkde(data = rnorm(100), h = 0.4) plot(d, band = FALSE)
Five samples of size 200 drawn from normal mixtures of Marron and Wand
(1992), classical test cases for density (derivative) estimation and
bandwidth selection. Writing for a normal density:
kurtotickurtotic unimodal density (#4):
.
outlieroutlier density (#5):
.
bimodalseparated bimodal density (#7):
.
trimodaltrimodal density (#9):
.
clawclaw density (#10):
.
bimodal claw kurtotic outlier trimodalbimodal claw kurtotic outlier trimodal
Each object is a numeric vector of length 200.
The datasets are loaded lazily: claw is available as soon as the
package is attached (data(claw) also works). The true densities are
known, so the estimates and the selected bandwidths can
be compared with the truth.
Simulated samples, as in previous versions of kedd.
Marron, J. S. and Wand, M. P. (1992). Exact mean integrated squared error. The Annals of Statistics, 20, 712–736.
## the five samples sapply(list(kurtotic = kurtotic, outlier = outlier, bimodal = bimodal, trimodal = trimodal, claw = claw), summary) ## claw density: estimate with an MCV bandwidth and the true density bw <- h.mcv(claw) f_claw <- function(x) 0.5 * dnorm(x) + rowSums(sapply(0:4, function(l) 0.1 * dnorm(x, l / 2 - 1, 0.1))) p <- plot(dkde(data = claw, h = bw@h)) p + ggplot2::stat_function(fun = f_claw, linetype = "dashed") ## first derivative of the bimodal sample plot(dkde(data = bimodal, h = h.ucv(bimodal, deriv.order = 1)@h, deriv.order = 1))## the five samples sapply(list(kurtotic = kurtotic, outlier = outlier, bimodal = bimodal, trimodal = trimodal, claw = claw), summary) ## claw density: estimate with an MCV bandwidth and the true density bw <- h.mcv(claw) f_claw <- function(x) 0.5 * dnorm(x) + rowSums(sapply(0:4, function(l) 0.1 * dnorm(x, l / 2 - 1, 0.1))) p <- plot(dkde(data = claw, h = bw@h)) p + ggplot2::stat_function(fun = f_claw, linetype = "dashed") ## first derivative of the bimodal sample plot(dkde(data = bimodal, h = h.ucv(bimodal, deriv.order = 1)@h, deriv.order = 1))
K
Evaluates the self-convolution of the
-th derivative of the kernel . Returns an S4 object of
class kconv.
kernel.conv(x = NULL, deriv.order = 0L, kernel = "gaussian", n.grid = 512L)kernel.conv(x = NULL, deriv.order = 0L, kernel = "gaussian", n.grid = 512L)
x |
numeric vector of evaluation points; if |
deriv.order |
derivative order |
kernel |
character string giving the kernel; one of
|
n.grid |
number of grid points when |
Closed forms are used for the Gaussian, Silverman and finite-support named
kernels. The logistic convolution has no closed form and is computed by
composite Gauss-Legendre quadrature centred at . For "pow(s,t)"
kernels the convolution is computed once per by quadrature on
(split where the integrand is not smooth) and then interpolated.
At , .
An S4 object of class kconv with slots:
numeric evaluation grid.
values.
kernel name.
derivative order .
the matched call.
Use show() for a summary and plot() for a ggplot2 graphic.
kc <- kernel.conv(kernel = "gaussian", deriv.order = 0L) show(kc) plot(kc) kc2 <- kernel.conv(kernel = "epanechnikov", deriv.order = 1L) plot(kc2) ## logistic (any r) and Pow(s,t) plot(kernel.conv(kernel = "logistic", deriv.order = 1L)) plot(kernel.conv(kernel = kernel.pow(2, 3)))kc <- kernel.conv(kernel = "gaussian", deriv.order = 0L) show(kc) plot(kc) kc2 <- kernel.conv(kernel = "epanechnikov", deriv.order = 1L) plot(kc2) ## logistic (any r) and Pow(s,t) plot(kernel.conv(kernel = "logistic", deriv.order = 1L)) plot(kernel.conv(kernel = kernel.pow(2, 3)))
Evaluates the -th derivative of a kernel function
and returns an S4 object of class kfun.
kernel.fun(x = NULL, deriv.order = 0L, kernel = "gaussian", n.grid = 512L)kernel.fun(x = NULL, deriv.order = 0L, kernel = "gaussian", n.grid = 512L)
x |
numeric vector of evaluation points. If |
deriv.order |
non-negative integer: derivative order |
kernel |
character string giving the kernel; one of
|
n.grid |
number of grid points when |
The supported kernels at order :
Gaussian: ,
support .
Epanechnikov: .
Uniform: .
Triangular: .
Biweight: .
Triweight: .
Tricube: .
Cosine: .
Silverman: ,
support .
Logistic: ,
support .
Pow(s,t): ,
, given as "pow(s,t)"
(see kernel.pow).
Derivatives are computed analytically via Hermite polynomials (Gaussian,
Silverman), Guidoum polynomials (finite-support kernels), the identity
with
(logistic, ) and exact power expansions (Pow, ).
An S4 object of class kfun with slots:
xnumeric evaluation grid.
y values.
kernelkernel name.
deriv.orderderivative order .
callthe matched call.
Use show() for a text summary and plot() for a ggplot2 graphic.
Arsalane Chouaib Guidoum [email protected]
Wand, M. P. and Jones, M. C. (1995). Kernel Smoothing. Chapman and Hall, London.
Silverman, B. W. (1986). Density Estimation for Statistics and Data Analysis. Chapman & Hall/CRC, London.
kernel.conv, kfun,
dkde, h.ucv.
## Gaussian kernel (r = 0) kf <- kernel.fun(kernel = "gaussian", deriv.order = 0L) show(kf) plot(kf) ## First derivative of Epanechnikov kernel kf2 <- kernel.fun(kernel = "epanechnikov", deriv.order = 1L) plot(kf2) ## Evaluate at specific points kf3 <- kernel.fun(x = seq(-2, 2, by = 0.1), kernel = "biweight", deriv.order = 2L) ## Logistic and Pow(s,t) kernels plot(kernel.fun(kernel = "logistic", deriv.order = 2L)) plot(kernel.fun(kernel = kernel.pow(1.5, 2.5)))## Gaussian kernel (r = 0) kf <- kernel.fun(kernel = "gaussian", deriv.order = 0L) show(kf) plot(kf) ## First derivative of Epanechnikov kernel kf2 <- kernel.fun(kernel = "epanechnikov", deriv.order = 1L) plot(kf2) ## Evaluate at specific points kf3 <- kernel.fun(x = seq(-2, 2, by = 0.1), kernel = "biweight", deriv.order = 2L) ## Logistic and Pow(s,t) kernels plot(kernel.fun(kernel = "logistic", deriv.order = 2L)) plot(kernel.fun(kernel = kernel.pow(1.5, 2.5)))
Builds the name of a kernel of the power family
which can be passed as kernel to every function of the package
(bandwidth selectors, dkde, kernel.fun,
kernel.conv).
kernel.pow(s = 2, t = 2)kernel.pow(s = 2, t = 2)
s |
single positive number: shape exponent |
t |
single non-negative number: power |
The kernel can equally be given directly as the string "pow(s,t)",
e.g. kernel = "pow(2,3)"; "pow" alone means "pow(2,2)".
The family contains several classical kernels:
"pow(s,0)" |
uniform |
"pow(1,1)" |
triangular |
"pow(2,1)" |
Epanechnikov |
"pow(2,2)" |
biweight |
"pow(2,3)" |
triweight |
"pow(3,3)" |
tricube |
The constants used by the bandwidth selectors are exact:
for even and
. For ,
is a finite sum of terms
: an exact binomial expansion when is an
integer (), a recurrence otherwise; derivatives are available
up to order 16.
is finite only when and, for a non-integer
, (otherwise is not square integrable
at or at ). Bandwidth selectors return NA with a
warning for such derivative orders, as for the other finite-support kernels.
Maximum derivative order. up to
when and are
integers (16 otherwise) in kernel.fun,
kernel.conv and dkde. With the
largest integer (with for integer
and , and unless
is an even integer), the maximum is for
h.ucv, h.bcv, h.tcv and
h.amise, for
h.mcv and for
h.ccv. For example pow(2,3): 6, 3, 2, 1;
pow(2,8): 16, 6, 6, 6; pow(1.5,2.5): 16, 1, 0, not available.
A character string "pow(s,t)".
Arsalane Chouaib Guidoum [email protected]
kernel.fun, kernel.conv, h.ucv,
dkde.
kernel.pow(2, 3) # "pow(2,3)" x <- rnorm(200) h.ucv(x, kernel = kernel.pow(2, 2)) # same bandwidth as kernel = "biweight" h.ucv(x, kernel = "pow(1.5,2.5)") plot(kernel.fun(kernel = kernel.pow(1.5, 2.5), deriv.order = 1L))kernel.pow(2, 3) # "pow(2,3)" x <- rnorm(200) h.ucv(x, kernel = kernel.pow(2, 2)) # same bandwidth as kernel = "biweight" h.ucv(x, kernel = "pow(1.5,2.5)") plot(kernel.fun(kernel = kernel.pow(1.5, 2.5), deriv.order = 1L))