KernelDensity - Maple Help

# Online Help

###### All Products    Maple    MapleSim

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[{2.09200984298361}{×}{{10}}^{{-8}}{,}{-2.10541484186103}{×}{{10}}^{{-8}}{,}{2.11898493755920}{×}{{10}}^{{-8}}{,}{-2.13273630765391}{×}{{10}}^{{-8}}{,}{2.14665972081418}{×}{{10}}^{{-8}}{,}{-2.16076891804487}{×}{{10}}^{{-8}}{,}{2.17505733701717}{×}{{10}}^{{-8}}{,}{-2.18953627026050}{×}{{10}}^{{-8}}{,}{2.20420187648993}{×}{{10}}^{{-8}}{,}{-2.21906298189176}{×}{{10}}^{{-8}}{,}{2.23411847112553}{×}{{10}}^{{-8}}{,}{-2.24937471531017}{×}{{10}}^{{-8}}{,}{2.26483334317754}{×}{{10}}^{{-8}}{,}{-2.28049826305962}{×}{{10}}^{{-8}}{,}{2.29637385600057}{×}{{10}}^{{-8}}{,}{-2.31246157795378}{×}{{10}}^{{-8}}{,}{2.32876857415854}{×}{{10}}^{{-8}}{,}{-2.34529386172050}{×}{{10}}^{{-8}}{,}{2.36204733342071}{×}{{10}}^{{-8}}{,}{-2.37902557584380}{×}{{10}}^{{-8}}{,}{2.39624128057364}{×}{{10}}^{{-8}}{,}{-2.41368859014296}{×}{{10}}^{{-8}}{,}{2.43138299164253}{×}{{10}}^{{-8}}{,}{-2.44931619673705}{×}{{10}}^{{-8}}{,}{2.46750650953476}{×}{{10}}^{{-8}}{,}{-2.48594320909762}{×}{{10}}^{{-8}}{,}{2.50464743407203}{×}{{10}}^{{-8}}{,}{-2.52360603889695}{×}{{10}}^{{-8}}{,}{2.54284300473667}{×}{{10}}^{{-8}}{,}{-2.56234278656065}{×}{{10}}^{{-8}}{,}{2.58213220371423}{×}{{10}}^{{-8}}{,}{-2.60219332557515}{×}{{10}}^{{-8}}{,}{2.62255583586418}{×}{{10}}^{{-8}}{,}{-2.64319943710234}{×}{{10}}^{{-8}}{,}{2.66415665604869}{×}{{10}}^{{-8}}{,}{-2.68540484970464}{×}{{10}}^{{-8}}{,}{2.70697943279691}{×}{{10}}^{{-8}}{,}{-2.72885541195006}{×}{{10}}^{{-8}}{,}{2.75107110321582}{×}{{10}}^{{-8}}{,}{-2.77359918539333}{×}{{10}}^{{-8}}{,}{2.79648088158391}{×}{{10}}^{{-8}}{,}{-2.81968657485365}{×}{{10}}^{{-8}}{,}{2.84326040107807}{×}{{10}}^{{-8}}{,}{-2.86717046112106}{×}{{10}}^{{-8}}{,}{2.89146382774497}{×}{{10}}^{{-8}}{,}{-2.91610634112205}{×}{{10}}^{{-8}}{,}{2.94114803831014}{×}{{10}}^{{-8}}{,}{-2.96655250087152}{×}{{10}}^{{-8}}{,}{2.99237274438424}{×}{{10}}^{{-8}}{,}{-3.01857015459761}{×}{{10}}^{{-8}}{,}{3.04520070618097}{×}{{10}}^{{-8}}{,}{-3.07222361370374}{×}{{10}}^{{-8}}{,}{3.09969786192743}{×}{{10}}^{{-8}}{,}{-3.12758049736406}{×}{{10}}^{{-8}}{,}{3.15593355060262}{×}{{10}}^{{-8}}{,}{-3.18471191536329}{×}{{10}}^{{-8}}{,}{3.21398068783840}{×}{{10}}^{{-8}}{,}{-3.24369266828384}{×}{{10}}^{{-8}}{,}{3.27391601884219}{×}{{10}}^{{-8}}{,}{-3.30460147753009}{×}{{10}}^{{-8}}{,}{3.33582030435930}{×}{{10}}^{{-8}}{,}{-3.36752120459749}{×}{{10}}^{{-8}}{,}{3.39977858331009}{×}{{10}}^{{-8}}{,}{-3.43253913417940}{×}{{10}}^{{-8}}{,}{3.46588043893988}{×}{{10}}^{{-8}}{,}{-3.49974720774762}{×}{{10}}^{{-8}}{,}{3.53422023903482}{×}{{10}}^{{-8}}{,}{-3.56924231724107}{×}{{10}}^{{-8}}{,}{3.60489746213666}{×}{{10}}^{{-8}}{,}{-3.64112658600424}{×}{{10}}^{{-8}}{,}{3.67801697171571}{×}{{10}}^{{-8}}{,}{-3.71550770116025}{×}{{10}}^{{-8}}{,}{3.75368934190864}{×}{{10}}^{{-8}}{,}{-3.79249922724881}{×}{{10}}^{{-8}}{,}{3.83203121851437}{×}{{10}}^{{-8}}{,}{-3.87222095681386}{×}{{10}}^{{-8}}{,}{3.91316563454029}{×}{{10}}^{{-8}}{,}{-3.95479924647371}{×}{{10}}^{{-8}}{,}{3.99722238694626}{×}{{10}}^{{-8}}{,}{-4.04036745021297}{×}{{10}}^{{-8}}{,}{4.08433843591751}{×}{{10}}^{{-8}}{,}{-4.12906623152990}{×}{{10}}^{{-8}}{,}{4.17465827160324}{×}{{10}}^{{-8}}{,}{-4.22104399826440}{×}{{10}}^{{-8}}{,}{4.26833432459290}{×}{{10}}^{{-8}}{,}{-4.31645728365551}{×}{{10}}^{{-8}}{,}{4.36552734702279}{×}{{10}}^{{-8}}{,}{-4.41547118483155}{×}{{10}}^{{-8}}{,}{4.46640682727078}{×}{{10}}^{{-8}}{,}{-4.51825967585508}{×}{{10}}^{{-8}}{,}{4.57115136275142}{×}{{10}}^{{-8}}{,}{-4.62500606338231}{×}{{10}}^{{-8}}{,}{4.67994900994052}{×}{{10}}^{{-8}}{,}{-4.73590323003249}{×}{{10}}^{{-8}}{,}{4.79299759969390}{×}{{10}}^{{-8}}{,}{-4.85115399951599}{×}{{10}}^{{-8}}{,}{4.91050496339665}{×}{{10}}^{{-8}}{,}{-4.97097127065096}{×}{{10}}^{{-8}}{,}{5.03268909139949}{×}{{10}}^{{-8}}{,}{-5.09557813650511}{×}{{10}}^{{-8}}{,}{\dots }{,}{\text{⋯ 412 Array entries not shown}}\right]$ (2)
 > $F\left[256\right]$
 ${0.790843983524199}$ (3)
 > $N≔\mathrm{RandomVariable}\left(\mathrm{Normal}\left(0,1\right)\right):$
 > $\mathrm{Statistics}:-\mathrm{PDF}\left(N,0.\right)$
 ${0.3989422803}$ (4)
 > $S≔\mathrm{Sample}\left(N,100000\right)$
 ${S}{≔}\left[{-1.07242412799827}{,}{-0.329077870547065}{,}{-0.617091936909790}{,}{0.214466745245291}{,}{-0.0254281280423846}{,}{1.72882128417783}{,}{-1.63485675434390}{,}{1.57117217175430}{,}{0.170358421410408}{,}{1.00647840875181}{,}{0.268712679158310}{,}{-1.46598044695878}{,}{-0.0357578538394966}{,}{-0.00650336346263664}{,}{-0.0571830022332381}{,}{-0.184600094624929}{,}{0.203855402371112}{,}{-0.0988718240271234}{,}{-0.0826980970419822}{,}{-0.168119128121408}{,}{0.162021299867933}{,}{-0.675918709672617}{,}{-0.440797644048532}{,}{0.896019985259550}{,}{0.461022953380023}{,}{1.27797705227385}{,}{0.234565961794581}{,}{-0.0362744912936830}{,}{-0.448848123512147}{,}{-1.16737308532471}{,}{-1.21794288394124}{,}{-1.15469196092625}{,}{0.109659323283598}{,}{-0.619809380641282}{,}{0.642151004644923}{,}{-0.170770918098244}{,}{-0.820052241027982}{,}{1.34633519663234}{,}{-0.986038560158125}{,}{-0.965838793499848}{,}{-1.36462571980574}{,}{1.65007871956408}{,}{1.34804151352017}{,}{-1.02537392618659}{,}{0.229788060863910}{,}{1.48493457968053}{,}{-1.30030905411587}{,}{-0.376131116236207}{,}{0.0617841966672065}{,}{0.801907829141039}{,}{-0.129975470550859}{,}{0.112484530604133}{,}{0.630360591794658}{,}{-0.0208959396841725}{,}{-0.830442822997399}{,}{-0.262652510141184}{,}{-0.700300261968008}{,}{1.95556905861273}{,}{-0.259474165622608}{,}{-0.0820850625624299}{,}{1.21557945262500}{,}{-0.983131813759657}{,}{1.93069064888935}{,}{0.122735108586753}{,}{0.432945421151540}{,}{-0.524443817862805}{,}{0.224215551927832}{,}{-0.414225568098372}{,}{0.0355261362296387}{,}{1.98371209767999}{,}{2.21337958939036}{,}{0.881229888626876}{,}{0.886856450560421}{,}{-0.861665947308802}{,}{-0.906611303340893}{,}{-0.876730984349719}{,}{-0.217490459619989}{,}{-0.336155174289136}{,}{0.549376576019130}{,}{-1.19754843404833}{,}{-0.927510339539523}{,}{-1.32995060542228}{,}{-1.13043603146978}{,}{1.27187025067002}{,}{-1.47651546344906}{,}{1.61338249093609}{,}{-0.685342069367486}{,}{1.08241290092064}{,}{-0.776734900479867}{,}{-0.555481438094644}{,}{1.07239184776825}{,}{0.0713529776295548}{,}{-0.182122924489555}{,}{0.628549543618577}{,}{-0.725850645010288}{,}{-0.413380338600023}{,}{1.54241530115661}{,}{-0.220309427423809}{,}{-0.840816024752715}{,}{0.385066012066646}{,}{\dots }{,}{\text{⋯ 99900 row vector entries not shown}}\right]$ (5)
 > $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}$ (6)
 > $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]$ (7)
 > $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}$ (8)

 See Also