densityAdaptiveKernel.default: Adaptive Kernel Estimation of Probability Density

View source: R/adaptive.R

densityAdaptiveKernel.defaultR Documentation

Adaptive Kernel Estimation of Probability Density

Description

Computes an adaptive estimate of probability density from numeric data, using a variable-bandwidth smoothing kernel.

Usage

## Default S3 method:
densityAdaptiveKernel(X, bw, ...,
       weights = NULL,
       zerocor=c("none", "weighted", "convolution",
                 "reflection", "bdrykern", "JonesFoster"),
       at = c("grid", "data"), ngroups=Inf, fast=TRUE)

Arguments

X

Data to be smoothed. A numeric vector.

bw

Smoothing bandwidths. Either a numeric vector of the same length as X giving the bandwidth associated with each data value, or a function in the R language that provides the smoothing bandwidth at any desired location. The default is to compute bandwidths using bw.abram.default.

...

Additional arguments passed to density.default controlling the range of x values at which the density must be estimated, when at="grid".

weights

Optional. Numeric vector of weights attached to each value in X.

zerocor

Character string (partially matched) specifying a boundary correction. This is appropriate when X contains only positive values.

at

String (partially matched) specifying whether to evaluate the probability density only at the data points (at="data") or on a grid of x values (at="grid", the default).

ngroups

Integer, Inf or NULL. If ngroups = Inf, the density estimate will be computed exactly using C code. If ngroups is finite, then the fast subdivision technique of Davies and Baddeley (2018) will be applied. If ngroups = NULL then a default rule is used to choose an efficient number of groups.

fast

Logical value specifying whether to use the Fast Fourier Transform to accelerate computations, when appropriate.

Details

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).

Value

If at="data", a numeric vector of the same length as X. If at="grid", a probability density object of class "density".

Bandwidths and Bandwidth Selection

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.

Author(s)

\adrian

and \tilman.

References

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.

See Also

bw.abram.default

Examples

  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)

spatstat.univar documentation built on June 8, 2025, 12:52 p.m.