KernelDensity - Maple Help

Statistics

 KernelDensity
 estimate the probability density function of a data set

 Calling Sequence KernelDensity(data, options)

Parameters

 data - 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

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $A≔\mathrm{Array}\left(\left[-1.,-0.4,-0.2,0.,0.,0.1,0.2,0.7,0.9\right]\right)$
 ${A}{≔}\left[\begin{array}{ccccccccc}{-1.}& {-0.4}& {-0.2}& {0.}& {0.}& {0.1}& {0.2}& {0.7}& {0.9}\end{array}\right]$ (1)
 > $F≔\mathrm{KernelDensity}\left(A,\mathrm{bins}=512,\mathrm{bandwidth}=\frac{1}{4},\mathrm{kernel}='\mathrm{biweight}',\mathrm{left}=-5,\mathrm{right}=5\right)$
 > $F\left[256\right]$
 ${0.790843983524199}$ (2)
 > $N≔\mathrm{RandomVariable}\left(\mathrm{Normal}\left(0,1\right)\right):$
 > $\mathrm{Statistics}:-\mathrm{PDF}\left(N,0.\right)$
 ${0.3989422803}$ (3)
 > $S≔\mathrm{Sample}\left(N,100000\right)$
 > $F≔\mathrm{KernelDensity}\left(S,\mathrm{bins}=512,\mathrm{kernel}='\mathrm{biweight}',\mathrm{left}=-5,\mathrm{right}=5,\mathrm{method}='\mathrm{discrete}'\right):$
 > $F\left[256\right]$
 ${0.400806618880859}$ (4)
 > $S≔\mathrm{Sample}\left(N,100\right)$
 ${S}{≔}\left[\begin{array}{cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc}{-2.31628938858161}& {0.876615712467426}& {0.755433662848402}& {-0.0256748583963029}& {1.07805689576433}& {-0.00852994197857369}& {0.248755949814253}& {-0.218218983725947}& {0.0487503188444441}& {-0.925249106904635}& {-0.941562414556374}& {-0.526590394149012}& {0.0202148211237441}& {0.422437934010982}& {1.50376020130448}& {0.00614634648750615}& {0.162979880841587}& {-0.820987609203309}& {1.08272898393155}& {-0.189671911186741}& {-0.428572493036612}& {0.000995207601774491}& {0.250530582165037}& {0.665906489865850}& {-0.138228315499703}& {0.228253903125008}& {0.632018089177005}& {-0.938990206901091}& {1.30054306449926}& {-0.0384277360025428}& {0.735789829715344}& {-1.23939901572288}& {1.54062001834553}& {0.222854605647868}& {0.651558905456853}& {-0.728613593330106}& {-0.809230459072730}& {1.07104134954450}& {-0.751728235530542}& {-0.259131447583416}& {-0.479251077468774}& {-1.72600581850632}& {-0.139999961772659}& {-1.27686548823171}& {-0.224289310916678}& {0.674424943329972}& {-0.708137444740243}& {2.43683075227907}& {-0.561888743531226}& {-0.600710420468611}& {-0.0207266529576681}& {0.454094098214602}& {0.597338794806091}& {0.468819843829382}& {-0.104230300510418}& {-0.600535420611268}& {0.00612691531736691}& {0.300926827175324}& {1.69535043966206}& {0.815326656975645}& {-1.17448609537049}& {1.03678396497547}& {1.37364726153471}& {-0.743530690974258}& {0.0729612602658883}& {-0.153982844818202}& {-0.182356895365875}& {0.337055625382118}& {-0.574379044182314}& {-0.530593305299774}& {0.00519803435779703}& {0.939039616131183}& {-1.79411479485972}& {-0.157636891486776}& {-3.08765298542783}& {0.400170715805038}& {0.323039809504786}& {-0.0313330466855132}& {0.288608339356529}& {0.142459142008888}& {-1.03761814583726}& {0.248133397427395}& {-1.28311346292802}& {1.07109035367896}& {0.535203632672633}& {0.963852594760354}& {0.259651672627876}& {-0.369143594225130}& {1.71349471253299}& {-2.89949853731110}& {-0.526631142182501}& {-0.149705638178913}& {-0.723806358275047}& {0.338725713069038}& {-0.423072709958352}& {1.24534807960347}& {1.18751902287925}& {0.388574332471800}& {-1.96957512872961}& {0.170639153710438}\end{array}\right]$ (5)
 > $F≔\mathrm{KernelDensity}\left(S,\mathrm{kernel}='\mathrm{gaussian}',\mathrm{bandwidth}=\frac{1}{4},\mathrm{left}=-5,\mathrm{right}=5,\mathrm{method}='\mathrm{exact}'\right):$
 > $\mathrm{evalf}\left(F\left(0.\right)\right)$
 ${0.511163772943709}$ (6)