Generates pseudorandom numbers from a multivariate normal distribution.
RSIG — Upper
triangular matrix, K by K, containing the
Cholesky factor of the variance-covariance matrix. (Input)
The
variance-covariance matrix is equal to the product of the transpose of RSIG and RSIG. RSIG can be obtained
from the variance-covariance matrix using routine CHFAC.
R — NR by K matrix containing the random multivariate normal vectors in its rows. (Output)
NR — Number of
random multivariate normal vectors to generate. (Input)
Default:
NR = size (R,1).
K — Length of the
multivariate normal vectors. (Input)
Default: K = size (R,2).
LDRSIG — Leading
dimension of RSIG exactly as
specified in the dimension statement in the calling program.
(Input)
Default: LDRSIG = size (RSIG,1).
LDR — Leading
dimension of R
exactly as specified in the dimension statement of the calling
program. (Input)
Default: LDR = size (R,1).
Generic: CALL RNMVN (RSIG, R [,…])
Specific: The specific interface names are S_RNMVN and D_RNMVN.
Single: CALL RNMVN (NR, K, RSIG, LDRSIG, R, LDR)
Double: The double precision name is DRNMVN.
Routine RNMVN
generates pseudorandom numbers from a multivariate normal distribution with mean
vector consisting of all zeroes and variance-covariance matrix whose Cholesky
factor
(or “square root”) is RSIG;
that is, RSIG
is an upper triangular matrix such that the transpose of RSIG
times RSIG
is the variance-covariance matrix. First, independent random normal deviates
with mean 0 and variance 1 are generated, and then the matrix containing these
deviates is postmultiplied by RSIG.
The independent normals are generated into the columns of a matrix, which has
NR
rows; hence, if RNSET
is called with different values of NR,
the output is different even if the seed is the same in the calls.
Deviates from a multivariate normal distribution with means other than zero can be generated by using RNMVN and then by adding the vector of means to each row of R.
The routine RNSET can be used to initialize the seed of the random number generator. The routine RNOPT can be used to select the form of the generator.
In this example, RNMVN is used to generate five pseudorandom multivariate normal vectors of length 2 with variance-covariance matrix equal to
0.500 0.375
0.375 0.500
The routine CHFAC is first called to compute the Cholesky factorization of the variance-covariance matrix.
USE RNMVN_INT
USE UMACH_INT
USE CHFAC_INT
USE RNSET_INT
IMPLICIT NONE
INTEGER I, IRANK, ISEED, J, K, LDR, LDRSIG, NOUT, NR
REAL COV(2,2), R(5,2), RSIG(2,2)
!
CALL UMACH (2, NOUT)
NR = 5
K = 2
LDRSIG = 2
LDR = 5
COV(1,1) = 0.5
COV(1,2) = 0.375
COV(2,1) = 0.375
COV(2,2) = 0.5
! Obtain the Cholesky factorization.
CALL CHFAC (COV, IRANK, RSIG)
! Initialize seed of random number
! generator.
ISEED = 123457
CALL RNSET (ISEED)
CALL RNMVN (RSIG, R)
WRITE (NOUT,99999) ((R(I,J),J=1,K),I=1,NR)
99999 FORMAT (' Multivariate normal random deviates: ', /, &
(1X,2F8.4))
END
Multivariate normal random deviates:
1.4507 1.2463
0.7660 -0.0429
0.0584 -0.6692
0.9035 0.4628
-0.8669 -0.9334
PHONE: 713.784.3131 FAX:713.781.9260 |