KernelDensity - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Statistics

  

KernelDensity

  

estimate the probability density function of a data set

 

Calling Sequence

Parameters

Description

Options

Notes

Examples

Calling Sequence

KernelDensity(data, options)

Parameters

data

-

data sample

options

-

(optional) equation(s) of the form option=value where option is one of kernel, bandwidth, bins, left, right, ignore, weights, method or output; specify options for the KernelDensity function

Description

• 

The KernelDensity function attempts to perform kernel density estimation on a data set in order to develop an approximation to the probability density function that the data could have been drawn from.

• 

The first parameter data is the data set - given as e.g. a Vector.

Options

  

The options argument can contain one or more of the options shown below.

• 

kernel='gaussian', biweight, epanechnikov, triangular, rectangular -- By default this is 'gaussian'.  This option allows a non-Gaussian kernel to be used in developing the estimate.  The Gaussian and biweight kernels are smooth - if they are used no sharp edges will be present in the final estimate.  The Epanechnikov kernel is often considered to be the optimal kernel.  The triangular and rectangular kernels are sharp kernels - they will impose sharp edges in the final estimate.

• 

bandwidth=realcons -- The bandwidth is a positive quantity that specifies the width of the kernel (the amount each data point affects distant portions of the probability density estimate).  Each kernel is scaled such that the bandwidth is equal to the standard deviation of the kernel.

• 

bins=posint -- The number of bins in which to categorize data points (512 by default).  This value must be a power of 2 and is equal to the size of the array returned from the routine when the option method='discrete' is specified.  This parameter is ignored if method='exact'.

• 

left=realcons -- This option specifies the lower boundary on valid data values.  Any data values that are smaller than this value are discarded.  By default the algorithm attempts to determine the minimum value in the data set and further includes padding of width 3*bandwidth.

• 

right=realcons -- This option specifies the upper boundary on valid data values.  Any data values that are smaller than this value are discarded.  By default the algorithm attempts to determine the maximum value in the data set and further includes padding of width 3*bandwidth.

• 

ignore=truefalse -- This option is used to specify how to handle non-numeric data. If ignore is set to true all non-numeric items in data will be ignored.

• 

weights=rtable -- Vector of weights (one-dimensional rtable). If weights are given, the KernelDensity function will return scale each data point to have given weight. Note that the weights provided must have type,realcons and the results are floating-point, even if the problem is specified with exact values. Both the data array and the weights array must have the same number of elements.

• 

method='discrete', exact, piecewise or none -- This option specifies the method of performing the kernel density estimate (by default this is 'discrete').  If this value is 'discrete', the procedure will return an array of size bins that contains the value of the kernel density estimate at equally spaced points along the range.  If this value is 'exact', the function will return a procedure which can be called to return the value of the kernel density estimate at any real point.  If this value is 'piecewise', the function will return a piecewise procedure that linearly interpolates the array returned by 'discrete'.  Lastly, if this value is 'none', no calculation will be performed and instead the procedure will return a range indicating the interval over which the computation is done.

• 

output='value' or solutionmodule -- This option specifies the requested form of the output.  If 'value' is specified then kernel density will simply return the result of the computation.  If 'solutionmodule' is specified then it will return the result within a module that also contains other resources relevant to the calculation.

• 

eval='false' or realcons -- This option, if specified, indicates that kernel density estimation should immediately attempt to evaluate the estimate function at the specified point and return the result.

Notes

• 

Kernel density estimation works by considering the location of each data point and replacing that data point with a kernel function which has an area of one.  The kernels are then individually summed up over all data points and normalized so that the estimate is a probability density function.

• 

Note that the discrete case of kernel density estimation employs a discrete Fourier transform in order to calculate the kernel sums as quickly as possible.  However, this results in an estimating function which is periodic over the given range.  Hence estimates near the lower and upper boundaries of the range will often be more imprecise than points within the range.

• 

Note that points that do not fall into the range left..right and missing data are not considered for this operation and are normally discarded.  If ignore=false and this procedure encounters missing data, it will spawn a userinfo message.

Examples

withStatistics:

AArray1.,0.4,0.2,0.,0.,0.1,0.2,0.7,0.9

A−1.−0.4−0.20.0.0.10.20.70.9

(1)

FKernelDensityA,bins=512,bandwidth=14,kernel=biweight,left=5,right=5

F256

0.790843983524199

(2)

NRandomVariableNormal0,1:

Statistics:-PDFN,0.

0.3989422803

(3)

SSampleN,100000

FKernelDensityS,bins=512,kernel=biweight,left=5,right=5,method=discrete:

F256

0.400806618880859

(4)

SSampleN,100

S−2.316289388581610.8766157124674260.755433662848402−0.02567485839630291.07805689576433−0.008529941978573690.248755949814253−0.2182189837259470.0487503188444441−0.925249106904635−0.941562414556374−0.5265903941490120.02021482112374410.4224379340109821.503760201304480.006146346487506150.162979880841587−0.8209876092033091.08272898393155−0.189671911186741−0.4285724930366120.0009952076017744910.2505305821650370.665906489865850−0.1382283154997030.2282539031250080.632018089177005−0.9389902069010911.30054306449926−0.03842773600254280.735789829715344−1.239399015722881.540620018345530.2228546056478680.651558905456853−0.728613593330106−0.8092304590727301.07104134954450−0.751728235530542−0.259131447583416−0.479251077468774−1.72600581850632−0.139999961772659−1.27686548823171−0.2242893109166780.674424943329972−0.7081374447402432.43683075227907−0.561888743531226−0.600710420468611−0.02072665295766810.4540940982146020.5973387948060910.468819843829382−0.104230300510418−0.6005354206112680.006126915317366910.3009268271753241.695350439662060.815326656975645−1.174486095370491.036783964975471.37364726153471−0.7435306909742580.0729612602658883−0.153982844818202−0.1823568953658750.337055625382118−0.574379044182314−0.5305933052997740.005198034357797030.939039616131183−1.79411479485972−0.157636891486776−3.087652985427830.4001707158050380.323039809504786−0.03133304668551320.2886083393565290.142459142008888−1.037618145837260.248133397427395−1.283113462928021.071090353678960.5352036326726330.9638525947603540.259651672627876−0.3691435942251301.71349471253299−2.89949853731110−0.526631142182501−0.149705638178913−0.7238063582750470.338725713069038−0.4230727099583521.245348079603471.187519022879250.388574332471800−1.969575128729610.170639153710438

(5)

FKernelDensityS,kernel=gaussian,bandwidth=14,left=5,right=5,method=exact:

evalfF0.

0.511163772943709

(6)

See Also

Statistics

Statistics[Computation]