Given
eigenvalues,
, such that
and
nag_rand_matrix_corr (g05py) 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
nag_rand_matrix_orthog (g05px) 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
.
One of the initialization functions
nag_rand_init_repeat (g05kf) (for a repeatable sequence if computed sequentially) or
nag_rand_init_nonrepeat (g05kg) (for a non-repeatable sequence) must be called prior to the first call to
nag_rand_matrix_corr (g05py).
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
The maximum error in a diagonal element is given by
eps.
Following initialization of the pseudorandom number generator by a call to
nag_rand_init_repeat (g05kf), a
by
correlation matrix with eigenvalues of
,
and
is generated and printed.
function g05py_example
fprintf('g05py example results\n\n');
seed = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
genid, subid, seed);
d = [0.7; 0.9; 1.4];
[state, c, ifail] = g05py( ...
d, state);
disp('Correlation Matrix');
disp(c);