NAG Library Routine Document
G05PYF generates a random correlation matrix with given eigenvalues.
||N, STATE(*), LDC, IFAIL
||D(N), EPS, C(LDC,N)
, 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)
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 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: N – INTEGERInput
On entry: , the dimension of the correlation matrix to be generated.
- 2: D(N) – REAL (KIND=nag_wp) arrayInput
On entry: the eigenvalues,
, for .
- , for ;
- to within EPS.
- 3: EPS – REAL (KIND=nag_wp)Input
On entry: the maximum acceptable error in the diagonal elements.
(see Chapter X02
- 4: STATE() – INTEGER arrayCommunication Array
the actual argument supplied must be the array STATE
supplied to the initialization routines G05KFF
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: C(LDC,N) – REAL (KIND=nag_wp) arrayOutput
On exit: a random correlation matrix, , of dimension .
- 6: LDC – INTEGERInput
: the first dimension of the array C
as declared in the (sub)program from which G05PYF is called.
- 7: IFAIL – INTEGERInput/Output
must be set to
. If you are unfamiliar with this parameter you should refer to Section 3.3
in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
|On entry,|| for some ,|
|On entry,||STATE vector was not initialized or has been corrupted.|
The error in a diagonal element is greater than EPS
. The value of EPS
should be increased. Otherwise the program could be rerun with a different value used for the seed of the random number generator, see G05KFF
The maximum error in a diagonal element is given by
The time taken by G05PYF is approximately proportional to .
Following initialization of the pseudorandom number generator by a call to
correlation matrix with eigenvalues of
is generated and printed.
9.1 Program Text
Program Text (g05pyfe.f90)
9.2 Program Data
Program Data (g05pyfe.d)
9.3 Program Results
Program Results (g05pyfe.r)