kfun {evmix} | R Documentation |
Various subsidiary kernel function, conversion of bandwidths and evaluating certain kernel integrals.
Description
Functions for checking the inputs to the kernel functions, evaluating
integrals \int u^l K*(u) du
for l = 0, 1, 2
and conversion between the two bandwidth
definitions.
Usage
check.kinputs(x, lambda, bw, kerncentres, allownull = FALSE)
check.kernel(kernel)
check.kbw(lambda, bw, allownull = FALSE)
klambda(bw = NULL, kernel = "gaussian", lambda = NULL)
kbw(lambda = NULL, kernel = "gaussian", bw = NULL)
ka0(truncpoint, kernel = "gaussian")
ka1(truncpoint, kernel = "gaussian")
ka2(truncpoint, kernel = "gaussian")
Arguments
x |
location to evaluate KDE (single scalar or vector) |
lambda |
bandwidth for kernel (as half-width of kernel) or |
bw |
bandwidth for kernel (as standard deviations of kernel) or |
kerncentres |
kernel centres (typically sample data vector or scalar) |
allownull |
logical, where TRUE permits NULL values |
kernel |
kernel name ( |
truncpoint |
upper endpoint as standardised location |
Details
Various boundary correction methods require integral of (partial moments of)
kernel within the range of support, over the range [-1, p]
where p
is the truncpoint
determined by the standardised distance of location x
where KDE is being evaluated to the lower bound of zero, i.e. truncpoint = x/lambda
.
The exception is the normal kernel which has unbounded support so the [-5*\lambda, p]
where
lambda
is the standard deviation bandwidth. There is a function for each partial moment
of degree (0, 1, 2):
-
ka0
-\int_{-1}^{p} K*(z) dz
-
ka1
-\int_{-1}^{p} u K*(z) dz
-
ka2
-\int_{-1}^{p} u^2 K*(z) dz
Notice that when evaluated at the upper endpoint on the support p = 1
(or p = \infty
for normal) these are the zeroth, first and second moments. In the
normal distribution case the lower bound on the region of integration is \infty
but
implemented here as -5*\lambda
.
These integrals are all specified in closed form, there is no need for numerical integration
(except normal which uses the pnorm
function).
See kpu
for list of kernels and discussion of bandwidth
definitions (and their default values):
-
bw
- in terms of number of standard deviations of the kernel, consistent with the defined values in thedensity
function in theR
base libraries -
lambda
- in terms of half-width of kernel
The klambda
function converts the bw
to the lambda
equivalent, and kbw
applies converse. These conversions are
kernel specific as they depend on the kernel standard deviations. If both bw
and
lambda
are provided then the latter is used by default. If neither are provided
(bw=NULL
and lambda=NULL
) then default is lambda=1
.
check.kinputs
checks all the kernel function inputs,
check.klambda
checks the pair of inputted bandwidths and
check.kernel
checks the kernel names.
Value
klambda
and kbw
return the
lambda
and bw
bandwidths respectively.
The checking functions check.kinputs
,
check.klambda
and check.kernel
will stop on errors and return no value.
ka0
, ka1
and ka2
return the partial moment integrals specified above.
Author(s)
Carl Scarrott carl.scarrott@canterbury.ac.nz.
References
http://en.wikipedia.org/wiki/Kernel_density_estimation
http://en.wikipedia.org/wiki/Kernel_(statistics)
Wand and Jones (1995). Kernel Smoothing. Chapman & Hall.
See Also
kernels
, density
,
kden
and bckden
.
Other kernels: kernels
Examples
xx = seq(-2, 2, 0.01)
plot(xx, kdgaussian(xx), type = "l", col = "black",ylim = c(0, 1.2))
lines(xx, kduniform(xx), col = "grey")
lines(xx, kdtriangular(xx), col = "blue")
lines(xx, kdepanechnikov(xx), col = "darkgreen")
lines(xx, kdbiweight(xx), col = "red")
lines(xx, kdtriweight(xx), col = "purple")
lines(xx, kdtricube(xx), col = "orange")
lines(xx, kdparzen(xx), col = "salmon")
lines(xx, kdcosine(xx), col = "cyan")
lines(xx, kdoptcosine(xx), col = "goldenrod")
legend("topright", c("Gaussian", "uniform", "triangular", "Epanechnikov",
"biweight", "triweight", "tricube", "Parzen", "cosine", "optcosine"), lty = 1,
col = c("black", "grey", "blue", "darkgreen", "red", "purple",
"salmon", "orange", "cyan", "goldenrod"))