The routine may be called by the names g05pyf or nagf_rand_matrix_corr.
, such that
g05pyf will generate a random correlation matrix,
, of dimension , with eigenvalues .
The method used is based on that described by
Lin and Bendel (1985). Let be the diagonal matrix with values and let be a random orthogonal matrix generated by
g05pxf then the matrix is a random covariance matrix with eigenvalues . The matrix is transformed into a correlation matrix by means of elementary rotation matrices such that . The restriction on the sum of eigenvalues implies that for any diagonal element of , there is another diagonal element . The 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 routines g05kff (for a repeatable sequence if computed sequentially) or g05kgf (for a non-repeatable sequence) must be called prior to the first call to g05pyf.
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
1: – IntegerInput
On entry: , the dimension of the correlation matrix to be generated.
Note: the actual argument supplied must be the array state supplied to the initialization routines g05kff or g05kgf.
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
5: – Real (Kind=nag_wp) arrayOutput
On exit: a random correlation matrix, , of dimension .
6: – IntegerInput
On entry: the first dimension of the array c as declared in the (sub)program from which g05pyf is called.
7: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
On entry, state vector has been corrupted or not initialized.
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, and .
An unexpected error has been triggered by this routine. Please
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
The maximum error in a diagonal element is given by
8Parallelism and Performance
g05pyf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g05pyf 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 X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
The time taken by g05pyf is approximately proportional to .
Following initialization of the pseudorandom number generator by a call to
g05kff, a correlation matrix with eigenvalues of , and is generated and printed.