Categories &

Functions List

Function Reference: mvksdensity

statistics: f = mvksdensity (x, pts, Name, Value)

Multivariate kernel smoothing density estimate.

f = mvksdensity (x, pts) computes a probability density estimate of the sample in the N×D matrix x, evaluated at the points in the M×D matrix pts. Each row of x is a single D-dimensional observation, and each row of pts is a point at which to evaluate the estimate. The result f is an M×1 vector, with one density value per row of pts.

The density estimate uses a product kernel: the multivariate kernel is the product of the univariate kernels applied to each dimension, each with its own bandwidth.

The following Name-Value pairs are supported:

NameValue
'Bandwidth'The kernel bandwidth, either a positive scalar applied to every dimension or a 1×D vector of positive values, one per dimension. The default is a diagonal normal-reference (Silverman) rule computed from x.
'Kernel'The smoothing kernel applied in each dimension: 'normal' (default), 'box', 'triangle', or 'epanechnikov'.
'Function'The function to estimate: 'pdf' (default) or 'cdf'.
'Weights'A vector of non-negative weights, one for each row of x. The default weights are all equal.

Source Code: mvksdensity

See also: ksdensity

Source Code: mvksdensity

Bivariate kernel density estimate over a grid, drawn as a contour plot.

 x = [randn(60, 2); randn(40, 2) + 3];
 [gx, gy] = meshgrid (linspace (-4, 7, 60));
 f = mvksdensity (x, [gx(:), gy(:)]);
 contourf (gx, gy, reshape (f, size (gx)));
 hold on;  plot (x(:,1), x(:,2), 'k.');  hold off;
 title ('Bivariate kernel density estimate');
plotted figure