| kernels | R Documentation |
Kernel functions are an important part of kdensity. This document
lists the available built-in functions and the structure of them. Any kernel
in the list can be used in kdensity by using kernel = "kernel"
for the intended kernel.
Ordinary symmetric kernel estimates use exact normalization constants.
With a non-uniform parametric start, compact-support kernels still require
numerical normalization, which can fail to converge; use gaussian if this
occurs.
gaussian, normal: The Gaussian kernel. The default argument when
starts is supported on R.
epanechnikov, rectangular (uniform), triangular, biweight, cosine, optcosine: Standard symmetric kernels, also used in
stats::density().
tricube, triweight: Standard symmetric kernels. Not supported by
stats::density().
laplace: Uses the Laplace density, also known as the double
exponential density.
gamma, gamma_biased: The gamma kernels of Chen (2000). For use on the
positive half-line. gamma_biased is Chen's first kernel, a gamma
density with shape y / h + 1 and scale h. gamma is the recommended
bias-corrected (modified) kernel, with shape y / h when y >= 2h and
(y / (2h))^2 + 1 otherwise.
gcopula: The Gaussian copula kernel of Jones & Henderson (2007). For use
on the unit interval.
beta, beta_biased: The beta kernel of Chen (1999). For use on the unit interval.
beta is the recommended bias-corrected kernel.
A kernel is a list containing two mandatory elements and one optional
element. The mandatory element 'kernel' is the kernel function.
It takes arguments y, x, h, where x is the data supplied
to kdensity and y is the point of evaluation. h is
the bandwidth. Internally, the kernel function is evaluated as
1/h*kernel(y, x, h). It should be vectorized in x, but
vectorization in y is not needed.
The second mandatory element is support, stating the domain of
definition for the kernel. This is used to distinguish kernels on the
unit interval / positive half-line from kernels on R.
sd is used for symmetric kernels and is the reciprocal of the kernel's
standard deviation. This scale factor converts a bandwidth on the Gaussian
standard-deviation scale to h = adjust * bw * sd.
Custom objects must use names different from the built-ins (for example,
my_gaussian). Registering another custom object under the same name
replaces the earlier custom object.
Chen, Song Xi. "Probability density function estimation using gamma kernels." Annals of the Institute of Statistical Mathematics 52.3 (2000): 471-480. Jones, M. C., and D. A. Henderson. "Kernel-type density estimation on the unit interval." Biometrika 94.4 (2007): 977-984. Chen, Song Xi. "Beta kernel estimators for density functions." Computational Statistics & Data Analysis 31.2 (1999): 131-145.
kdensity(); parametric_starts();
bandwidths().
my_gaussian <- list(
kernel = function(y, x, h) stats::dnorm((y - x) / h),
sd = 1,
support = c(-Inf, Inf)
)
my_gcopula <- list(
kernel = function(y, x, h) {
rho <- 1 - h^2
inside <- rho^2 * (qnorm(y)^2 + qnorm(x)^2) - 2 * rho * qnorm(y) * qnorm(x)
h / sqrt(1 - rho^2) * exp(-inside / (2 * (1 - rho^2)))
},
support = c(0, 1)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.