|On this page…|
The probability density function of the d-dimensional multivariate normal distribution is given by
where x and μ are 1-by-d vectors and Σ is a d-by-d symmetric positive definite matrix. While it is possible to define the multivariate normal for singular Σ, the density cannot be written as above. Only random vector generation is supported for the singular case. Note that while most textbooks define the multivariate normal with x and μ oriented as column vectors, for the purposes of data analysis software, it is more convenient to orient them as row vectors, and Statistics Toolbox™ software uses that orientation.
The multivariate normal distribution is a generalization of the univariate normal to two or more variables. It is a distribution for random vectors of correlated variables, each element of which has a univariate normal distribution. In the simplest case, there is no correlation among variables, and elements of the vectors are independent univariate normal random variables.
The multivariate normal distribution is parameterized with a mean vector, μ, and a covariance matrix, Σ. These are analogous to the mean μ and variance σ2 parameters of a univariate normal distribution. The diagonal elements of Σ contain the variances for each variable, while the off-diagonal elements of Σ contain the covariances between variables.
The multivariate normal distribution is often used as a model for multivariate data, primarily because it is one of the few multivariate distributions that is tractable to work with.
This example shows the probability density function (pdf) and cumulative distribution function (cdf) for a bivariate normal distribution with unequal standard deviations. You can use the multivariate normal distribution in a higher number of dimensions as well, although visualization is not easy.
mu = [0 0]; Sigma = [.25 .3; .3 1]; x1 = -3:.2:3; x2 = -3:.2:3; [X1,X2] = meshgrid(x1,x2); F = mvnpdf([X1(:) X2(:)],mu,Sigma); F = reshape(F,length(x2),length(x1)); surf(x1,x2,F); caxis([min(F(:))-.5*range(F(:)),max(F(:))]); axis([-3 3 -3 3 0 .4]) xlabel('x1'); ylabel('x2'); zlabel('Probability Density');
F = mvncdf([X1(:) X2(:)],mu,Sigma); F = reshape(F,length(x2),length(x1)); surf(x1,x2,F); caxis([min(F(:))-.5*range(F(:)),max(F(:))]); axis([-3 3 -3 3 0 1]) xlabel('x1'); ylabel('x2'); zlabel('Cumulative Probability');
Since the bivariate normal distribution is defined on the plane, you can also compute cumulative probabilities over rectangular regions. For example, this contour plot illustrates the computation that follows, of the probability contained within the unit square.
contour(x1,x2,F,[.0001 .001 .01 .05:.1:.95 .99 .999 .9999]); xlabel('x'); ylabel('y'); line([0 0 1 1 0],[1 0 0 1 1],'linestyle','--','color','k');
mvncdf([0 0],[1 1],mu,Sigma) ans = 0.20974
Computing a multivariate cumulative probability requires significantly more work than computing a univariate probability. By default, the mvncdf function computes values to less than full machine precision, and returns an estimate of the error as an optional second output:
[F,err] = mvncdf([0 0],[1 1],mu,Sigma) F = 0.20974 err = 1e-008