kernel.fun: Evaluate Kernel Function and Its Derivatives

View source: R/kernel.fun.R

kernel.funR Documentation

Evaluate Kernel Function and Its Derivatives

Description

Evaluates the r-th derivative K^{(r)}(x) of a kernel function K and returns an S4 object of class kfun.

Usage

kernel.fun(x = NULL, deriv.order = 0L, kernel = "gaussian", n.grid = 512L)

Arguments

x

numeric vector of evaluation points. If NULL (default), a uniform grid of n.grid points over [-8, 8] (Gaussian, Silverman, logistic) or [-1.1, 1.1] (compact-support kernels) is used.

deriv.order

non-negative integer: derivative order r \ge 0. 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) (16 if s or t is not an integer). Above it, zero is returned (with a warning for logistic and pow). 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).

n.grid

number of grid points when x is NULL (default 512).

Details

The supported kernels at order r = 0:

  • Gaussian: K(x)=\frac{1}{\sqrt{2\pi}}e^{-x^2/2}, support (-\infty,+\infty).

  • Epanechnikov: K(x)=\frac{3}{4}(1-x^2)\mathbf{1}_{|x|\le 1}.

  • Uniform: K(x)=\frac{1}{2}\mathbf{1}_{|x|\le 1}.

  • Triangular: K(x)=(1-|x|)\mathbf{1}_{|x|\le 1}.

  • Biweight: K(x)=\frac{15}{16}(1-x^2)^2\mathbf{1}_{|x|\le 1}.

  • Triweight: K(x)=\frac{35}{32}(1-x^2)^3\mathbf{1}_{|x|\le 1}.

  • Tricube: K(x)=\frac{70}{81}(1-|x|^3)^3\mathbf{1}_{|x|\le 1}.

  • Cosine: K(x)=\frac{\pi}{4}\cos\!\left(\frac{\pi x}{2}\right)\mathbf{1}_{|x|\le 1}.

  • Silverman: K(x)=\frac{1}{2}e^{-|x|/\sqrt{2}}\sin\!\left(\frac{|x|}{\sqrt{2}}+\frac{\pi}{4}\right), support (-\infty,+\infty).

  • Logistic: K(x)=\frac{e^{-x}}{(1+e^{-x})^2}=\frac{1}{4}\mathrm{sech}^2(x/2), support (-\infty,+\infty).

  • Pow(s,t): K(x)=c_{s,t}(1-|x|^s)^t\mathbf{1}_{|x|\le 1}, c_{s,t}=s/(2B(1/s,t+1)), given as "pow(s,t)" (see kernel.pow).

Derivatives are computed analytically via Hermite polynomials (Gaussian, Silverman), Guidoum polynomials (finite-support kernels), the identity K^{(r)}=\sigma(1-\sigma)Q_{r+1}(\sigma) with \sigma(x)=1/(1+e^{-x}) (logistic, r \le 20) and exact power expansions (Pow, r \le 16).

Value

An S4 object of class kfun with slots:

x

numeric evaluation grid.

y

K^{(r)}(x) values.

kernel

kernel name.

deriv.order

derivative order r.

call

the matched call.

Use show() for a text 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

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.

See Also

kernel.conv, kfun, dkde, h.ucv.

Examples

## 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)))

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