dkde: Kernel Density Derivative Estimator

View source: R/dkde.R

dkdeR Documentation

Kernel Density Derivative Estimator

Description

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.

Usage

dkde(x = NULL, data, h, deriv.order = 0L,
     kernel = "gaussian", nthreads = 0L)

Arguments

x

numeric vector of evaluation points. If NULL (default), a regular grid of 512 points spanning [\min(data) - 3h,\; \max(data) + 3h] is used.

data

numeric vector of observations.

h

positive bandwidth scalar. If missing, the UCV bandwidth h.ucv(data, deriv.order, kernel) is used.

deriv.order

non-negative integer: derivative order r. Maximum r with K^{(r)} \ne 0: any for Gaussian, cosine and Silverman; logistic 20; Epanechnikov 2; uniform 0; triangular 1; biweight 4; triweight 6; tricube 9; pow(s,t) \min(st, 16). When h is missing it is chosen by h.ucv, whose limits are lower (see kedd-package, section ‘Maximum derivative order’).

kernel

character string giving the kernel; one of "gaussian" (default), "epanechnikov", "uniform", "triangular", "biweight", "triweight", "tricube", "cosine", "silverman", "logistic", or a power kernel "pow(s,t)" (see kernel.pow).

nthreads

number of OpenMP threads for this call: 0 (default) = all processors, k > 0 = k threads, both capped by the environment variable OMP_THREAD_LIMIT. The result does not depend on it, and it never changes the threads used by later calls.

Details

The r'th derivative kernel density estimator is:

\hat{f}_h^{(r)}(x) = \frac{1}{n\,h^{r+1}}\sum_{i=1}^{n}K^{(r)}\!\left(\frac{x-X_i}{h}\right)

where K^{(r)}(x)=d^r K(x)/dx^r (see kernel.fun).

Theoretical properties (Bhattacharya 1967; Schuster 1969):

  • Bias: E[\hat{f}_h^{(r)}(x)] - f^{(r)}(x) = \frac{h^2}{2}\mu_2(K)\,f^{(r+2)}(x) + o(h^2)

  • Variance: Var[\hat{f}_h^{(r)}(x)] = \frac{f(x)\,R(K^{(r)})}{n\,h^{2r+1}} + o(1/(n\,h^{2r+1}))

The AMISE-optimal bandwidth is of order n^{-1/(2r+5)}, so higher derivatives require larger bandwidths.

The AMISE is:

AMISE(\hat{f}_h^{(r)}) = \frac{R(K^{(r)})}{n\,h^{2r+1}} + \frac{\mu_2^2(K)}{4}\,h^4\,R(f^{(r+2)})

where R(K^{(r)})=\int (K^{(r)})^2\,dx and \mu_2(K)=\int x^2 K(x)\,dx.

Value

An S4 object of class dkde with slots x (evaluation points), y (estimates \hat{f}_h^{(r)}(x_i)), h, kernel, deriv.order, n, data and call. Use show() for a summary and plot() for a ggplot2 graphic.

Author(s)

Arsalane Chouaib Guidoum acguidoum@univ-tam.dz, Amel Henider amel.henider@univ-tam.dz and Iago Giné-Vázquez iago.gin-vaz@protonmail.com

References

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.

See Also

kernel.fun, h.ucv, h.bcv, h.amise, density (for r=0).

Examples

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)

kedd documentation built on Nov. 12, 2026, 5:10 p.m.