densityAdaptiveKernel.default | R Documentation |
Computes an adaptive estimate of probability density from numeric data, using a variable-bandwidth smoothing kernel.
## Default S3 method:
densityAdaptiveKernel(X, bw, ...,
weights = NULL,
zerocor=c("none", "weighted", "convolution",
"reflection", "bdrykern", "JonesFoster"),
at = c("grid", "data"), ngroups=Inf, fast=TRUE)
X |
Data to be smoothed. A numeric vector. |
bw |
Smoothing bandwidths. Either a numeric vector of the same length as
|
... |
Additional arguments passed to |
weights |
Optional. Numeric vector of weights attached to each value in |
zerocor |
Character string (partially matched) specifying a boundary
correction. This is appropriate when |
at |
String (partially matched) specifying whether to evaluate the
probability density only at the data points ( |
ngroups |
Integer, |
fast |
Logical value specifying whether to use the Fast Fourier Transform to accelerate computations, when appropriate. |
This function computes an adaptive kernel estimate of
probability density on the real line (if zerocor="none"
)
or on the positive real line (if zerocor
is another value).
The argument bw
specifies the smoothing bandwidths to be
applied to each of the points in X
. It may be a numeric vector
of bandwidth values, or a function yielding the
bandwidth values.
If the values in X
are x_1,\ldots,x_n
and the corresponding bandwidths are
\sigma_1,\ldots,\sigma_n
then the adaptive kernel estimate of intensity at a location u
is
\hat\lambda(u) = \sum_{i=1}^n k(u, x_i, \sigma_i)
where k(u, v, \sigma)
is the value at u
of the (possibly edge-corrected) smoothing kernel with bandwidth \sigma
induced by a data point at v
.
Exact computation of the estimate above can be time-consuming:
it takes n
times longer than fixed-bandwidth smoothing.
The partitioning method of Davies and Baddeley (2018)
accelerates this computation by partitioning the range of
bandwidths into ngroups
intervals,
correspondingly subdividing X
into
ngroups
subsets according to bandwidth,
and applying fixed-bandwidth smoothing to each subset.
If ngroups=NULL
then we use a default rule where ngroups
is the integer part of the square root of
the number of points in X
, so that the computation time is
only about \sqrt{n}
times slower than fixed-bandwidth
smoothing. Any positive value of ngroups
can be specified by the user. Specifying ngroups=Inf
enforces exact
computation of the estimate without partitioning. Specifying
ngroups=1
is the same as fixed-bandwidth smoothing with
bandwidth sigma=median(bw)
.
If at="data"
, a numeric vector of the same length as X
.
If at="grid"
, a probability density object of class "density"
.
The function densityAdaptiveKernel.default
computes one adaptive estimate of probability density,
determined by the smoothing bandwidth values bw
.
Typically the bandwidth values are computed by first computing
a pilot estimate of the intensity, then using bw.abram.default
to compute the vector of bandwidths according to Abramson's rule.
This involves specifying a global bandwidth h0
.
and \tilman.
Davies, T.M. and Baddeley, A. (2018)
Fast computation of spatially adaptive kernel estimates.
Statistics and Computing, 28(4), 937-956.
Hall, P. and Marron, J.S. (1988)
Variable window width kernel density estimates of probability
densities.
Probability Theory and Related Fields, 80, 37-49.
Silverman, B.W. (1986) Density Estimation for Statistics and Data Analysis. Chapman and Hall, New York.
bw.abram.default
xx <- rexp(100, rate=5)
plot(density(xx))
curve(5 * exp(-5 * x), add=TRUE, col=3)
plot(densityAdaptiveKernel(xx, at="grid"))
curve(5 * exp(-5 * x), add=TRUE, col=3)
plot(densityAdaptiveKernel(xx, at="grid", zerocor="w"))
curve(5 * exp(-5 * x), add=TRUE, col=3)
plot(densityAdaptiveKernel(xx, at="grid", zerocor="c"))
curve(5 * exp(-5 * x), add=TRUE, col=3)
plot(densityAdaptiveKernel(xx, at="grid", zerocor="r"))
curve(5 * exp(-5 * x), add=TRUE, col=3)
plot(densityAdaptiveKernel(xx, at="grid", zerocor="b"))
curve(5 * exp(-5 * x), add=TRUE, col=3)
plot(densityAdaptiveKernel(xx, at="grid", zerocor="J"))
curve(5 * exp(-5 * x), add=TRUE, col=3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.