RAND_FROM_DATA Function
Generates pseudorandom numbers from a multivariate distribution determined from a given sample.
Usage
result = RAND_FROM_DATA(n_random, x, nn)
Input Parameters
n_random—Number of random multivariate vectors to generate.
x—Two dimensional array of size nsamp by ndim containing the given sample.
nn—Number of nearest neighbors of the randomly selected point in x that are used to form the output point in the result.
Returned Value
resultn × ndim matrix containing random multivariate vectors in its rows.
Input Keywords
Double—If present and nonzero, double precision is used.
Discussion
Given a sample of size nsamp of observations of a k-variate random variable, RAND_FROM_DATA generates a pseudorandom sample with approximately the same moments as the given sample. The sample obtained is the same as if sampling from a Gaussian kernel estimate of the sample density. (See Thompson 1989.) Routine RAND_FROM_DATA 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 u1, u2, ..., um is generated from a uniform distribution with lower bound:
and upper bound:
The random variate delivered is:
The process is then repeated until n such simulated variates are generated and stored in the rows of the result.
Example
In this example, RAND_FROM_DATA 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 STATDATA, see Chapter 15: Utilities of this manual).
RANDOMOPT, Set = 123457
r = STATDATA(9)
x = FLTARR(113, 4)
x(*, 0) = r(*,6)
x(*, 1) = r(*,9)
x(*, 2) = r(*,20)
x(*, 3) = r(*,23) 
r  =  RAND_FROM_DATA(5, x, 5)
PM, r
; PV-WAVE prints the following:
; 162.767      90.5057      153.717      104.877
; 153.353      78.3180      176.664      85.2155
; 93.6958      48.1675      153.549      71.3688
; 101.751      54.1855      113.121      56.2916
; 91.7403      58.7684      48.4368      28.0994