RNDAT
Generates pseudorandom numbers from a multivariate distribution determined from a given sample.
Required Arguments
XNSAMP by K matrix containing the given sample. (Input/Output)
If IDO = 0 or 1, on output the rows of X are rearranged by routine QUADT to form a kd tree.
NN — Number of nearest neighbors of the randomly selected point in X that are used to form the output point in R. (Input)
RNR by K matrix containing the random multivariate vectors in its rows. (Output)
Optional Arguments
IDO — Generator option. (Input)
Default: IDO = 0.
IDO
Action
0
This is the only invocation of RNDAT with the sample in X and all desired pseudorandom numbers are to be generated in this call.
1
This is the first invocation, and additional calls to RNDAT will be made to generate additional random numbers using the same given sample.
2
This is an intermediate invocation of RNDAT. The work vectors have been set up in a previous call, but they are not to be released because additional calls will be made.
3
This is the final invocation of RNDAT. The work vectors have been set up in a previous call and they are to be released.
NR — Number of random multivariate vectors to generate. (Input)
If NR = 0, only initialization or wrap up operations are performed. (This would make sense only if IDO = 1 or 3.)
Default: NR = size (R,1).
K — The length of the multivariate vectors, that is, the number of dimensions. (Input)
Default: K = size (R,2).
NSAMP — Number of given data points from the distribution to be simulated. (Input)
Default: NSAMP = size (X,1).
LDX — Leading dimension of X exactly as specified in the dimension statement in the calling program. (Input)
Default: LDX = size (X,1).
LDR — Leading dimension of R exactly as specified in the dimension statement of the calling program. (Input)
Default: LDR = size (R,1).
FORTRAN 90 Interface
Generic: CALL RNDAT (X, NN, R [])
Specific: The specific interface names are S_RNDAT and D_RNDAT.
FORTRAN 77 Interface
Single: CALL RNDAT (IDO, NR, K, NSAMP, X, LDX, NN, R, LDR)
Double: The double precision name is DRNDAT.
Description
Given a sample of size n (= NSAMP) of observations of a k‑variate random variable, RNDAT generates a pseudorandom sample with approximately the same moments as the given sample. The sample obtained is essentially the same as if sampling from a Gaussian kernel estimate of the sample density. (See Thompson 1989.) Routine RNDAT uses methods described by Taylor and Thompson (1986).
Assume that the (vector‑valued) observations xi are in the rows of X. An observation, xj, is chosen randomly; its nearest m (= NN) neighbors,
are determined; and the mean
of those nearest neighbors is calculated. Next, a random sample
u1u2um is generated from a uniform distribution with lower bound
and upper bound
The random variate delivered is
The process is then repeated until NR such simulated variates are generated and stored in the rows of R.
When RNDAT is invoked for the first time for a given sample, a search tree is computed for the rows of X. During the generation process, this tree is used to find the nearest neighbors of the randomly selected row. The argument IDO is used to determine whether or not the tree must be computed and whether workspace has to be allocated to store the tree.
Comments
1. Workspace may be explicitly provided, if desired, by use of R2DAT/DR2DAT. The reference is:
CALL R2DAT (IDO, NR, K, NSAMP, X, LDX, NN, R, LDR, IWK, WK)
The additional arguments are as follows:
IWK — Work vector of length equal to 2 * NSAMP + 3 * LEN + K + NN.
WK — Work vector of length equal to 2 * NSAMP + 2 * K * LEN + K + 2 * NN.
R2DAT allows alternating calls for two different populations (see Comment 3). Warning: R2DAT does no error checking.
2. The rows of X are rearranged on output from either RNDAT or R2DAT.
3. When more than one call is to be made to RNDAT to generate more than one R matrix using the same sample in X, IDO should be set to 1 for the first call, to 2 for all subsequent calls except the last one, and to 3 for the last call. If more than one population is to be simulated (that is, there is more than one sample, X), it is necessary to generate all of the observations from each population at one time because data is stored in the work vectors. If the user provides work vectors for each population to be simulated, R2DAT can be used to simulate different population alternatively.
4. 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.
Example
In this example, RNDAT is used to generate 5 pseudorandom vectors of length 4 using the initial and final systolic pressure and the initial and final diastolic pressure from Data Set A in Afifi and Azen (1979) as the fixed sample from the population to be modeled. (Values of these four variables are in the seventh, tenth, twenty‑first, and twenty‑fourth columns of data set number nine in routine GDATA).
 
USE IMSL_LIBRARIES
 
IMPLICIT NONE
INTEGER LDR, LDRDAT, LDX, NDR, NDRDAT, NDX
PARAMETER (LDR=5, LDRDAT=113, LDX=113, NDR=4, NDRDAT=34, NDX=4)
!
INTEGER ISEED, NN, NRCOL, NRROW
REAL R(LDR,NDR), RDATA(LDRDAT,NDRDAT), X(LDX,NDX)
CHARACTER * 6 NUMBER(1)
! Afifi and Azen Data Set A
DATA NUMBER(1)/'NUMBER'/
CALL GDATA (9, RDATA, NRROW, NRCOL)
CALL SCOPY (NRROW, RDATA(1:,7), 1, X(1:,1), 1)
CALL SCOPY (NRROW, RDATA(1:,10), 1, X(1:,2), 1)
CALL SCOPY (NRROW, RDATA(1:,21), 1, X(1:,3), 1)
CALL SCOPY (NRROW, RDATA(1:,24), 1, X(1:,4), 1)
!
ISEED = 123457
CALL RNSET (ISEED)
! Set input values
NN = 5
! Generate random variates
CALL RNDAT (X, NN, R)
! Print results
CALL WRRRL ('Random variates', R, NUMBER, NUMBER, FMT='(F15.4)')
!
END
Output
 
Random variates
1 2 3 4
1 162.7668 90.5057 153.7173 104.8768
2 153.3533 78.3180 176.6643 85.2155
3 93.6958 48.1675 153.5495 71.3688
4 101.7508 54.1855 113.1215 56.2916
5 91.7403 58.7684 48.4368 28.0994
Published date: 03/19/2020
Last modified date: 03/19/2020