densityBC {spatstat.univar} | R Documentation |
Kernel Density Estimation with Optional Boundary Correction
Description
A simple implementation of fixed-bandwidth kernel density estimation on the real line, or the positive real half-line, including optional corrections for a boundary at zero.
Usage
densityBC(x, kernel = "epanechnikov", bw=NULL,
...,
h=NULL,
adjust = 1,
weights = rep(1, length(x))/length(x), from, to = max(x), n = 256,
zerocor = c("none", "weighted", "convolution", "reflection",
"bdrykern", "JonesFoster"),
fast=FALSE,
internal=list())
Arguments
x |
Numeric vector. |
kernel |
String specifying kernel.
Options are
|
bw , h |
Alternative specifications of the scale factor for the kernel.
The bandwidth |
adjust |
Numeric value used to rescale the bandwidth |
weights |
Numeric vector of weights associated with |
from , to |
Lower and upper limits of interval on which density should be
computed.
The default value of |
n |
Number of |
zerocor |
String (partially matched) specifying a correction for the boundary effect
bias at |
fast |
Logical value specifying whether to perform the calculation rapidly
using the Fast Fourier Transform ( |
internal |
Internal use only. |
... |
Additional arguments are ignored. |
Details
If zerocor
is absent or given as "none"
,
this function computes the fixed bandwidth kernel estimator of the
probability density on the real line.
If zerocor
is given, it is assumed that the density
is confined to the positive half-line, and a boundary correction is
applied:
- weighted
The contribution from each point
x_i
is weighted by the factor1/m(x_i)
wherem(x) = 1 - F(-x)
is the total mass of the kernel centred onx
that lies in the positive half-line, andF(x)
is the cumulative distribution function of the kernel- convolution
The estimate of the density
f(r)
is weighted by the factor1/m(r)
wherem(r) = 1 - F(-r)
is given above.- reflection
-
if the kernel centred at data point
x_i
has a tail that lies on the negative half-line, this tail is reflected onto the positive half-line. - bdrykern
The density estimate is computed using the Boundary Kernel associated with the chosen kernel (Wand and Jones, 1995, page 47). That is, when estimating the density
f(r)
for values ofr
close to zero (defined asr < h
for all kernels except the Gaussian), the kernel contributionk_h(r - x_i)
is multiplied by a term that is a linear function ofr - x_i
.- JonesFoster
-
The modification of the Boundary Kernel estimate proposed by Jones and Foster (1996), equal to
\overline f(r) \exp( \hat f(r)/\overline f(r) - 1)
where\overline f(r)
is the convolution estimator and\hat f(r)
is the boundary kernel estimator.
If fast=TRUE
, the calculations are performed rapidly using
density.default
which employs the Fast Fourier
Transform. If fast=FALSE
(the default), the calculations are
performed exactly using slower C code.
Value
An object of class "density"
as described in the help file
for density.default
. It contains at least the entries
x |
Vector of |
y |
Vector of density values |
Author(s)
Adrian Baddeley Adrian.Baddeley@curtin.edu.au and Martin Hazelton Martin.Hazelton@otago.ac.nz.
References
Baddeley, A., Chang, Y-M., Davies, T.M. and Hazelton, M. (2024) In preparation.
Jones, M.C. and Foster, P.J. (1996) A simple nonnegative boundary correction method for kernel density estimation. Statistica Sinica, 6 (4) 1005–1013.
Wand, M.P. and Jones, M.C. (1995) Kernel Smoothing. Chapman and Hall.
Examples
sim.dat <- rexp(500)
fhatN <- densityBC(sim.dat, "biweight", h=0.4)
fhatB <- densityBC(sim.dat, "biweight", h=0.4, zerocor="bdrykern")
plot(fhatN, ylim=c(0,1.1), main="density estimates")
lines(fhatB, col=2)
curve(dexp(x), add=TRUE, from=0, col=3)
legend(2, 0.8,
legend=c("fixed bandwidth", "boundary kernel", "true density"),
col=1:3, lty=rep(1,3))