NAG Library Function Document
nag_ref_vec_multi_normal (g05eac)
1 Purpose
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.
2 Specification
| #include <nag.h> |
| #include <nagg05.h> |
| void |
nag_ref_vec_multi_normal (const double a[],
Integer n,
const double c[],
Integer tdc,
double eps,
double **r,
NagError *fail) |
|
3 Description
When the variance-covariance matrix is non-singular (i.e., strictly positive definite), the distribution has probability density function
where
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
,
and
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
, provided
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.
4 References
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
5 Arguments
- 1:
a[n] – const doubleInput
-
On entry: the vector of means, , of the distribution.
- 2:
n – IntegerInput
-
On entry: the number of dimensions, , of the distribution.
Constraint:
.
- 3:
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.
- 4:
tdc – IntegerInput
-
On entry: the stride separating matrix column elements in the array
c.
Constraint:
.
- 5:
eps – doubleInput
-
On entry: the maximum error in any element of , relative to the largest element of .
Constraint:
.
- 6:
r – double **Output
-
On exit: 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.
- 7:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_2_INT_ARG_LT
On entry, while . These arguments must satisfy .
- NE_2_REAL_ARG_GT
On entry,
while 0.1/
. These arguments must satisfy
/
n.
- NE_ALLOC_FAIL
Dynamic memory allocation failed.
- NE_INT_ARG_LT
On entry, .
Constraint: .
- NE_NOT_POS_SEM_DEF
Matrix is not positive semidefinite.
- NE_REAL_ARG_LT
On entry,
eps must not be less than 0.0:
.
7 Accuracy
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
, where
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.
9 Example
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
None.
9.3 Program Results
Program Results (g05eace.r)