Kernel: Kernels

Description Usage Arguments Details See Also Examples

View source: R/kernel.R

Description

The kernels are key-objects of the KDE package. The S3 class Kernel tries to ensure some of the properties of kernels and is a subclass of IntegrableFunction (see: 'Details' for exact requirements).

Usage

1
Kernel(fun, support = NULL, subdivisions = 1000L, ...)

Arguments

fun

a R function taking a single numeric argument and returning a numeric vector of the same length. See 'Details' for further requirements.

support

numerical vector of length 2; the lower- and upper bound of the compact support in the first and second entry respectively. In particular non-finite values are prohibited. IntegrableFunction will try to find bounds on the support itself if NULL is passed.

subdivisions

positive numeric scalar; the subdivisions parameter for the function integrate_primitive.

...

additional parameters to keep fixed during the evaluation of fun.

Details

A kernel function is a real valued, integrable function, such that its integral over the real numbers equals one. Kernel functions as R functions are required to

  1. be vectorised in its argument, taking a single numeric argument, returning a numerical vector of the same length only,

  2. return zero for inputs outside their compact support,

  3. can be integrated over their support using integrate_primitive and the given number of subdivisions (the relative error converges).

  4. yield an integral of nearly 1 (absolute error < 1%).

See the 'Details' section of IntegrableFunction for comments on the restrictiveness of compact supports.

The S3 class Density exists to ensure some of the most basic properties of density functions. The class is build on IntegrableFunctions and inherits its structure.

The constructor Kernel tries to construct a valid Kernel object based on the passed arguments. Returned objects are guaranteed to pass the validator validate_Kernel.

Attention: This does not guarantee the conditions in the first 'Details' paragraph: see validate_Kernel.

List of built-in kernels functions:

rectangular
triangular
epanechnikov
biweight
triweight
tricube
gaussian
cosine
logistic
sigmoid
silverman

See Also

validate_Kernel for the corresponding validator, IntegrableFunction for more information about the superclass.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
rectangular_function <- function(u) 1/2*(abs(u) <= 1)
rectangular_ker <- Kernel(rectangular_function, support=c(-1,1))
x <- seq(from = -4, to = 4, length.out = 1000)
plot(x, gaussian$fun(x),
     xlim=c(-5,5), ylim=c(0,1),
     main="Kernels", xlab="", ylab="",
     col="black", type="l")
lines(x, triangular$fun(x), col="red")
lines(x, rectangular_ker$fun(x), col="blue")
legend("topright",
       legend=c("gaussian", "triangular","rectangular"),
       col=c("black","red", "blue"), lty=1, cex=0.8)

hericks/KDE documentation built on Aug. 22, 2020, 12:04 a.m.