Main Content

Multivariate Normal Distribution

Overview

The multivariate normal distribution is a generalization of theunivariate normal distributionto two or more variables. It is a distribution for random vectors of correlated variables, where each vector element has a univariate normal distribution. In the simplest case, no correlation exists among variables, and elements of the vectors are independent univariate normal random variables.

Because it is easy to work with, the multivariate normal distribution is often used as a model for multivariate data.

Statistics and Machine Learning Toolbox™ provides several functionalities related to the multivariate normal distribution.

  • Generate random numbers from the distribution usingmvnrnd.

  • Evaluate the probability density function (pdf) at specific values usingmvnpdf.

  • Evaluate the cumulative distribution function (cdf) at specific values usingmvncdf.

Parameters

The multivariate normal distribution uses the parameters in this table.

Parameter Description Univariate Normal Analogue
μ Mean vector Meanμ(scalar)
Σ 协方差矩阵,对角元素包含variances for each variable, and off-diagonal elements contain the covariances between variables Varianceσ2(scalar)

Note that in the one-dimensional case,Σis the variance, not the standard deviation. For more information on the parameters of the univariate normal distribution, seeParameters.

Probability Density Function

The probability density function (pdf) of thed-dimensional multivariate normal distribution is

y = f ( x , μ , Σ ) = 1 | Σ | (2 π ) d exp ( 1 2 ( x - μ ) Σ -1 ( x - μ )' )

wherexandμare 1-by-dvectors andΣis ad-by-dsymmetric, positive definite matrix.

Note that Statistics and Machine Learning Toolbox:

  • Supports singularΣfor random vector generation only. The pdf cannot be written in the same form whenΣis singular.

  • Usesxandμoriented as row vectors rather than column vectors.

For an example, seeBivariate Normal Distribution pdf.

Cumulative Distribution Function

The multivariate normal cumulative distribution function (cdf) evaluated atxis defined as the probability that a random vectorv, distributed as multivariate normal, lies within the semi-infinite rectangle with upper limits defined byx,

Pr { v ( 1 ) x ( 1 ) , v ( 2 ) x ( 2 ) , ... , v ( d ) x ( d ) } .

Although the multivariate normal cdf has no closed form,mvncdfcan compute cdf values numerically.

For an example, seeBivariate Normal Distribution cdf.

Examples

Bivariate Normal Distribution pdf

Compute and plot the pdf of a bivariate normal distribution with parametersmu = [0 0]andSigma = [0.25 0.3; 0.3 1].

Define the parametersmuandSigma.

mu = [0 0]; Sigma = [0.25 0.3; 0.3 1];

Create a grid of evenly spaced points in two-dimensional space.

x1 = -3:0.2:3; x2 = -3:0.2:3; [X1,X2] = meshgrid(x1,x2); X = [X1(:) X2(:)];

Evaluate the pdf of the normal distribution at the grid points.

y = mvnpdf(X,mu,Sigma); y = reshape(y,length(x2),length(x1));

Plot the pdf values.

surf(x1,x2,y) caxis([min(y(:))-0.5*range(y(:)),max(y(:))]) axis([-3 3 -3 3 0 0.4]) xlabel('x1') ylabel('x2') zlabel('Probability Density')

Figure contains an axes object. The axes object contains an object of type surface.

Bivariate Normal Distribution cdf

Compute and plot the cdf of a bivariate normal distribution.

Define the mean vectormuand the covariance matrixSigma.

mu = [1 -1]; Sigma = [.9 .4; .4 .3];

Create a grid of 625 evenly spaced points in two-dimensional space.

[X1,X2] = meshgrid(linspace(-1,3,25)',linspace(-3,1,25)'); X = [X1(:) X2(:)];

Evaluate the cdf of the normal distribution at the grid points.

p = mvncdf(X,mu,Sigma);

Plot the cdf values.

Z = reshape(p,25,25); surf(X1,X2,Z)

Figure contains an axes object. The axes object contains an object of type surface.

Probability over Rectangular Region

Compute the probability over the unit square of a bivariate normal distribution, and create a contour plot of the results.

Define the bivariate normal distribution parametersmuandSigma.

mu = [0 0]; Sigma = [0.25 0.3; 0.3 1];

单位平方计算的概率。

p = mvncdf([0 0],[1 1],mu,Sigma)
p = 0.2097

To visualize the result, first create a grid of evenly spaced points in two-dimensional space.

x1 = -3:.2:3; x2 = -3:.2:3; [X1,X2] = meshgrid(x1,x2); X = [X1(:) X2(:)];

Then, evaluate the pdf of the normal distribution at the grid points.

y = mvnpdf(X,mu,Sigma); y = reshape(y,length(x2),length(x1));

Finally, create a contour plot of the multivariate normal distribution that includes the unit square.

contour(x1,x2,y,[0.0001 0.001 0.01 0.05 0.15 0.25 0.35]) xlabel('x') ylabel('y') line([0 0 1 1 0],[1 0 0 1 1],'Linestyle','--','Color','k')

Figure contains an axes object. The axes object contains 2 objects of type contour, line.

Computing a multivariate cumulative probability requires significantly more work than computing a univariate probability. By default, themvncdffunction computes values to less than full machine precision, and returns an estimate of the error as an optional second output. View the error estimate in this case.

[p,err] = mvncdf([0 0],[1 1],mu,Sigma)
p = 0.2097
err = 1.0000e-08

References

[1] Kotz, S., N. Balakrishnan, and N. L. Johnson.Continuous Multivariate Distributions: Volume 1: Models and Applications.2nd ed. New York: John Wiley & Sons, Inc., 2000.

See Also

|||

Related Topics