Language Reference

RANDNORMAL Function

RANDNORMAL (N, Mean, Cov ) ;

This function is supported by the IML procedure and the iml action.

The RANDNORMAL function is part of the IMLMLIB library. The RANDNORMAL function returns an upper N times p matrix that contains N random draws from the multivariate normal distribution with mean vector Mean and covariance matrix Cov.

The inputs are as follows:

N

is the number of desired observations sampled from the multivariate normal distribution.

Mean

is a 1 times p vector of means.

Cov

is a p times p symmetric positive definite variance-covariance matrix.

If X follows a multivariate normal distribution with mean vector mu and variance-covariance matrix normal upper Sigma, then

  • the probability density function for x is

    f left-parenthesis x semicolon mu comma normal upper Sigma right-parenthesis equals StartFraction 1 Over left-parenthesis 2 pi right-parenthesis Superscript p slash 2 Baseline StartAbsoluteValue normal upper Sigma EndAbsoluteValue Superscript 1 slash 2 Baseline EndFraction exp left-parenthesis minus StartFraction left-parenthesis x minus mu right-parenthesis normal upper Sigma Superscript negative 1 Baseline left-parenthesis x minus mu right-parenthesis Superscript upper T Baseline Over 2 EndFraction right-parenthesis
  • if p equals 1, the probability density function reduces to a univariate normal distribution.

  • the expected value of upper X Subscript i is mu Subscript i.

  • the covariance of upper X Subscript i and upper X Subscript j is normal upper Sigma Subscript i j.

The following example generates 1,000 samples from a two-dimensional multivariate normal distribution with mean vector (1, 2) and a given covariance matrix. Each row of the returned matrix x is a row vector sampled from the multivariate normal distribution. The example computes the sample mean and covariance and compares them with the expected values.

call randseed(1);
N = 1000;
Mean = {1 2};
Cov = {2.4 3, 3 8.1};

x = RandNormal( N, Mean, Cov );
SampleMean = mean(x);
SampleCov = cov(x);
print SampleMean Mean, SampleCov Cov;

Figure 344: Estimated Mean and Covariance Matrix

SampleMean Mean 
1.06196042.115608412

SampleCov Cov 
2.55135183.27295592.43
3.27295598.709958538.1


For further details about sampling from the multivariate normal distribution, see Gentle (2003).

Last updated: July 20, 2026