Statistics Toolbox    
ksdensity

Compute density estimate using a kernel smoothing method

Syntax

Description

[f,xi] = ksdensity(x) computes a probability density estimate of the sample in the vector x. f is the vector of density values evaluated at the points in xi. The estimate is based on a normal kernel function, using a window parameter ('width') that is a function of the number of points in x. The density is evaluated at 100 equally-spaced points covering the range of the data in x.

f = ksdensity(x,xi) specifies the vector xi of values where the density estimate is to be evaluated.

[f,xi,u] = ksdensity(...) also returns the width of the kernel smoothing window.

[...] = ksdensity(...,'param1',val1,'param2',val2,...) specifies parameter name/value pairs to control the density estimation. Valid parameters and their possible values are:

'kernel'
The type of kernel smoother to use. Choose the value as 'normal' (default), 'box', 'triangle', or 'epanechinikov'.
Alternatively, you can specify some other function, as a function handle or as a string, e.g., @normpdf or 'normpdf'. The function must take a single argument that is an array of distances between data values and places where the density is evaluated. It must return an array of the same size containing corresponding values of the kernel function.
'npoints'
The number of equally-spaced points in xi. Default is 100.
'width'
The bandwidth of the kernel smoothing window. The default is optimal for estimating normal densities, but you may want to choose a smaller value to reveal features such as multiple modes.

Examples

This example generates a mixture of two normal distributions, and plots the estimated density.

See Also

hist, @ (function handle)

References

[1]  Bowman, A.W. and A. Azzalini, Applied Smoothing Techniques for Data Analysis, Oxford University Press, 1997.


  kruskalwallis kstest