NAG Library Routine Document
G05PYF
Note: before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.
1 Purpose
G05PYF generates a random correlation matrix with given eigenvalues.
2 Specification
INTEGER
N, STATE(*), LDC, IFAIL
REAL (KIND=nag_wp)
D(N), EPS, C(LDC,N)
3 Description
Given
eigenvalues,
, such that
and
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.
4 References
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
5 Parameters
- 1: N – INTEGERInput
On entry: , the dimension of the correlation matrix to be generated.
Constraint:
.
- 2: D(N) – REAL (KIND=nag_wp) arrayInput
On entry: the eigenvalues,
, for .
Constraints:
- , for ;
- to within EPS.
- 3: EPS – REAL (KIND=nag_wp)Input
On entry: the maximum acceptable error in the diagonal elements.
Suggested value:
.
- 4: STATE() – INTEGER arrayCommunication Array
-
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: C(LDC,N) – REAL (KIND=nag_wp) arrayOutput
On exit: a random correlation matrix, , of dimension .
- 6: LDC – INTEGERInput
On entry: the first dimension of the array
C as declared in the (sub)program from which G05PYF is called.
Constraint:
.
- 7: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL 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.
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
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
On entry, .
On entry, for some ,
or .
On entry, .
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 or
G05KGF.
On entry, .
7 Accuracy
The maximum error in a diagonal element is given by
EPS.
The time taken by G05PYF is approximately proportional to .
9 Example
Following initialization of the pseudorandom number generator by a call to
G05KFF, a
by
correlation matrix with eigenvalues of
,
and
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)