naginterfaces.library.smooth.kerndens_​gauss

naginterfaces.library.smooth.kerndens_gauss(x, comm, wtype=2, window=1.0, slo=None, shi=None, ns=512)[source]

kerndens_gauss performs kernel density estimation using a Gaussian kernel.

For full information please refer to the NAG Library document for g10bb

https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g10/g10bbf.html

Parameters
xfloat, array-like, shape

, for .

On a continuation call, must be unchanged since the last call to kerndens_gauss.

commdict, communication object, modified in place

Communication structure.

If not initialized on entry then the values of are to be calculated by this call to kerndens_gauss.

Otherwise, this is a continuation call and it is assumed that the values of were calculated by a previous call to this function and the relevant information is stored in [‘rcomm’].

wtypeint, optional

How the window width, , is to be calculated:

is supplied in .

is to be calculated from the data, with

where is the inter-quartile range and the standard deviation of the sample, , and is a multipler supplied in . The and quartiles, and , are calculated using stat.quantiles. This is the ‘rule-of-thumb’ suggested by Silverman (1990).

windowfloat, optional

If , then , the window width. Otherwise, , the multiplier used in the calculation of .

sloNone or float, optional

Note: if this argument is None then a default value will be used, determined as follows: .

If then , the lower limit of the interval on which the estimate is calculated. Otherwise, and , the lower and upper limits of the interval, are calculated as follows:

where is the window width.

For most applications should be at least three window widths below the lowest data point.

On a continuation call, a supplied will be ignored and the appropriate value from the previous call to kerndens_gauss will be extracted from [‘rcomm’].

shiNone or float, optional

Note: if this argument is None then a default value will be used, determined as follows: .

If then , the upper limit of the interval on which the estimate is calculated. Otherwise a value for is calculated from the data as stated in the description of and the value supplied in is not used.

For most applications should be at least three window widths above the highest data point.

On a continuation call, a supplied will be ignored and the appropriate value from the previous call to kerndens_gauss will be extracted from [‘rcomm’].

nsint, optional

, the number of points at which the estimate is calculated.

On a continuation call, must be unchanged since the last call to kerndens_gauss.

Returns
windowfloat

, the window width actually used.

slofloat

, the lower limit actually used.

shifloat

, the upper limit actually used.

smoothfloat, ndarray, shape

, for , the values of the density estimate.

tfloat, ndarray, shape

, for , the points at which the estimate is calculated.

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, .

On entry at previous call, .

Constraint: on a continuation call, must be unchanged since previous call.

(errno )

On entry, .

Constraint: or .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

On exit from previous call, .

Constraint: on a continuation call, must be the same value returned by the previous call.

(errno )

On entry, .

On exit from previous call, .

Constraint: on a continuation call, must be the same value returned by the previous call.

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

On entry at previous call, .

Constraint: on a continuation call, must be unchanged since previous call.

(errno )

[‘rcomm’] has been corrupted between calls.

Warns
NagAlgorithmicWarning
(errno )

On entry, and .

On entry, and .

Expected values of at least and for and .

Notes

Given a sample of observations, , from a distribution with unknown density function, , an estimate of the density function, , may be required. The simplest form of density estimator is the histogram. This may be defined by:

where is the number of observations falling in the interval to , is the lower bound to the histogram, is the upper bound and is the total number of intervals. The value is known as the window width. To produce a smoother density estimate a kernel method can be used. A kernel function, , satisfies the conditions:

The kernel density estimator is then defined as

The choice of is usually not important but to ease the computational burden use can be made of the Gaussian kernel defined as

The smoothness of the estimator depends on the window width . The larger the value of the smoother the density estimate. The value of can be chosen by examining plots of the smoothed density for different values of or by using cross-validation methods (see Silverman (1990)).

Silverman (1982) and Silverman (1990) show how the Gaussian kernel density estimator can be computed using a fast Fourier transform (FFT). In order to compute the kernel density estimate over the range to the following steps are required.

  1. Discretize the data to give equally spaced points with weights (see Jones and Lotwick (1984)).

  2. Compute the FFT of the weights to give .

  3. Compute where .

  4. Find the inverse FFT of to give .

To compute the kernel density estimate for further values of only steps (iii) and (iv) need be repeated.

References

Jones, M C and Lotwick, H W, 1984, Remark AS R50. A remark on algorithm AS 176. Kernel density estimation using the Fast Fourier Transform, Appl. Statist. (33), 120–122

Silverman, B W, 1982, Algorithm AS 176. Kernel density estimation using the fast Fourier transform, Appl. Statist. (31), 93–99

Silverman, B W, 1990, Density Estimation, Chapman and Hall