Last chance! 50% off unlimited learning
Sale ends in
Functions for checking the inputs to the kernel functions, evaluating
integrals
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")
location to evaluate KDE (single scalar or vector)
bandwidth for kernel (as half-width of kernel) or NULL
bandwidth for kernel (as standard deviations of kernel) or NULL
kernel centres (typically sample data vector or scalar)
logical, where TRUE permits NULL values
kernel name (default = "gaussian"
)
upper endpoint as standardised location x/lambda
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.
Various boundary correction methods require integral of (partial moments of)
kernel within the range of support, over the range truncpoint
determined by the standardised distance of location truncpoint = x/lambda
.
The exception is the normal kernel which has unbounded support so the lambda
is the standard deviation bandwidth. There is a function for each partial moment
of degree (0, 1, 2):
ka0
-
ka1
-
ka2
-
Notice that when evaluated at the upper endpoint on the support 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 the density
function in
the R
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.
http://en.wikipedia.org/wiki/Kernel_density_estimation
http://en.wikipedia.org/wiki/Kernel_(statistics)
Wand and Jones (1995). Kernel Smoothing. Chapman & Hall.
kernels
, density
,
kden
and bckden
.
Other kernels: kernels
# NOT RUN {
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"))
# }
Run the code above in your browser using DataLab