kde: Fit a variable bandwidth kernel density estimate to a vector...

View source: R/kde.R

kdeR Documentation

Fit a variable bandwidth kernel density estimate to a vector of data

Description

The bandwidth of each kernel is calculated using neighboring points. We then sample the density on a fixed grid and construct interpolating functions for the density and CDF.

Usage

kde(x, n = NA, bwfac = 1, bwmin = 1e-06, limits = c(NA, NA), ngrid = 256)

Arguments

x

Vector of samples for which to construct density.

bwfac

Bandwidth adjustment factor. Calculated bandwidths will be uniformly scaled by this factor. Higher values produce smoother estimates.

bwmin

Minimum allowable bandwidth for an individual kernel.

limits

Closed boundaries for the distribution (NA means no boundary)

ngrid

Number of grid points to use for the interpolation function. Default is 256.

npt

Size of the neighborhood to use for estimating bandwidth. N data points on each side of the a point will be used in the estimate. Default is 1/20 the total size of the dataset.

Details

The bwmin parameter allows a minimum allowable bandwidth to be set. It's a good idea to set this to something like the smallest meaningful difference in measurement values. When in doubt, the smallest reporting unit of the measurement apparatus is a good choice. The default value is 1e-6, which is meant to be effectively zero, while protecting against a divide-by-zero in the event that the bandwidth calculation produces zero as a result.

TODO: Right now the quantile function is not an exact inverse of the CDF because there is no way to guarantee that the two spline functions interpolate the same way. Need to fix.


rplzzz/varkde documentation built on May 25, 2022, 2:58 p.m.