NAG Library Function Document
nag_rand_corr_matrix (g05pyc) generates a random correlation matrix with given eigenvalues.
||nag_rand_corr_matrix (Integer n,
const double d,
, such that
nag_rand_corr_matrix (g05pyc) will generate a random correlation matrix,
, of dimension
, with eigenvalues
The method used is based on that described by
Lin and Bendel (1985)
be the diagonal matrix with values
be a random orthogonal matrix generated by
then the matrix
is a random covariance matrix with eigenvalues
. The matrix
is transformed into a correlation matrix by means of
elementary rotation matrices
. The restriction on the sum of eigenvalues implies that for any diagonal element of
, there is another diagonal element
are constructed from such pairs, chosen at random, to produce a unit diagonal element corresponding to the first element. This is repeated until all diagonal elements are
to within a given tolerance
The randomness of should be interpreted only to the extent that is a random orthogonal matrix and is computed from using the which are chosen as arbitrarily as possible.
One of the initialization functions nag_rand_init_repeatable (g05kfc)
(for a repeatable sequence if computed sequentially) or nag_rand_init_nonrepeatable (g05kgc)
(for a non-repeatable sequence) must be called prior to the first call to nag_rand_corr_matrix (g05pyc).
Lin S P and Bendel R B (1985) Algorithm AS 213: Generation of population correlation on matrices with specified eigenvalues Appl. Statist. 34 193–198
n – IntegerInput
On entry: , the dimension of the correlation matrix to be generated.
d[n] – const doubleInput
On entry: the eigenvalues,
, for .
- , for ;
- to within eps.
eps – doubleInput
On entry: the maximum acceptable error in the diagonal elements.
(see Chapter x02
state – IntegerCommunication Array
, of this array is dictated by the requirements of associated functions that must have been previously called. This array MUST be the same array passed as argument state
in the previous call to nag_rand_init_repeatable (g05kfc)
or nag_rand_init_nonrepeatable (g05kgc)
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
c – doubleOutput
On exit: a random correlation matrix, , of dimension .
pdc – IntegerInput
: the stride separating row elements of the matrix
in the array
fail – NagError *Input/Output
The NAG error argument (see Section 3.6
in the Essential Introduction).
6 Error Indicators and Warnings
Dynamic memory allocation failed.
On entry, argument had an illegal value.
The diagonals of the returned matrix are not unity, try increasing the value of eps
, or rerun the code using a different seed.
On entry, the eigenvalues do not sum to n
On entry, .
On entry, .
On entry, and .
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG
On entry, state
vector has been corrupted or not initialized.
On entry, an eigenvalue is negative.
On entry, .
The maximum error in a diagonal element is given by
8 Parallelism and Performance
nag_rand_corr_matrix (g05pyc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_rand_corr_matrix (g05pyc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the Users' Note
for your implementation for any additional implementation-specific information.
The time taken by nag_rand_corr_matrix (g05pyc) is approximately proportional to .
Following initialization of the pseudorandom number generator by a call to
correlation matrix with eigenvalues of
is generated and printed.
10.1 Program Text
Program Text (g05pyce.c)
10.2 Program Data
Program Data (g05pyce.d)
10.3 Program Results
Program Results (g05pyce.r)