NAG Library Function Document
nag_ref_vec_multi_normal (g05eac) sets up a reference vector for a multivariate Normal distribution with mean vector
and variance-covariance matrix
, so that nag_return_multi_normal (g05ezc)
may be used to generate pseudorandom vectors.
||nag_ref_vec_multi_normal (const double a,
const double c,
When the variance-covariance matrix is non-singular (i.e., strictly positive definite), the distribution has probability density function
is the number of dimensions,
is the variance-covariance matrix,
is the vector of means and
is the vector of positions.
Variance-covariance matrices are symmetric and positive semidefinite. Given such a matrix , there exists a lower triangular matrix such that . is not unique, if is singular.
nag_ref_vec_multi_normal (g05eac) decomposes
to find such an
. It then stores
in the reference vector
for later use by nag_return_multi_normal (g05ezc)
. nag_return_multi_normal (g05ezc)
generates a vector
of independent standard Normal pseudorandom numbers. It then returns the vector
, which has the required multivariate Normal distribution.
It should be noted that this function will work with a singular variance-covariance matrix
is positive semidefinite, despite the fact that the above formula for the probability density function is not valid in that case. Wilkinson (1965)
should be consulted if further information is required.
Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley
Wilkinson J H (1965) The Algebraic Eigenvalue Problem Oxford University Press, Oxford
a[n] – const doubleInput
On entry: the vector of means, , of the distribution.
n – IntegerInput
On entry: the number of dimensions, , of the distribution.
c – const doubleInput
Note: the th element of the matrix is stored in .
On entry: the variance-covariance matrix of the distribution. Only the upper triangle need be set.
tdc – IntegerInput
: the stride separating matrix column elements in the array c
eps – doubleInput
On entry: the maximum error in any element of , relative to the largest element of .
r – double **Output
: reference vector for which memory will be allocated internally. This reference vector will subsequently be used by nag_return_multi_normal (g05ezc)
. If no memory is allocated to r
(e.g., when an input error is detected) then r
will be NULL
on return, otherwise you should use the NAG macro NAG_FREE
to free the storage allocated by r
when it is no longer of use.
fail – NagError *Input/Output
The NAG error argument (see Section 3.6
in the Essential Introduction).
6 Error Indicators and Warnings
On entry, while . These arguments must satisfy .
. These arguments must satisfy
Dynamic memory allocation failed.
On entry, .
Matrix is not positive semidefinite.
On entry, eps
must not be less than 0.0:
The maximum absolute error in , and hence in the variance-covariance matrix of the resulting vectors, is less than times the maximum element of , where is the machine precision. Under normal circumstances, the above will be small compared to sampling error.
The time taken by nag_ref_vec_multi_normal (g05eac) is of order .
It is recommended that the diagonal elements of
should not differ too widely in order of magnitude. This may be achieved by scaling the variables if necessary. The actual matrix decomposed is
is a diagonal matrix with small positive diagonal elements. This ensures that, even when
is singular, or nearly singular, the Cholesky factor
corresponds to a positive definite variance-covariance matrix that agrees with
within a tolerance determined by eps
The example program prints five pseudorandom observations from a bivariate Normal distribution with means vector
and variance-covariance matrix
generated by nag_ref_vec_multi_normal (g05eac) and nag_return_multi_normal (g05ezc)
after initialization by nag_random_init_repeatable (g05cbc)
9.1 Program Text
Program Text (g05eace.c)
9.2 Program Data
9.3 Program Results
Program Results (g05eace.r)