nag_rand_sample (g05ndc) selects a pseudorandom sample without replacement from an integer vector.
nag_rand_sample (g05ndc) selects
elements from a population vector
ipop of length
and places them in a sample vector
isampl. Their order in
ipop will be preserved in
isampl. Each of the
possible combinations of elements of
isampl may be regarded as being equally probable.
One of the initialization functions
nag_rand_init_repeatable (g05kfc) (for a repeatable sequence if computed sequentially) or
nag_rand_init_nonrepeatable (g05kgc) (for a non-repeatable sequence) must be called prior to the first call to nag_rand_sample (g05ndc).
Not applicable.
Not applicable.
In order to sample other kinds of vectors, or matrices of higher dimension, the following technique may be used:
(a) |
set , for ; |
(b) |
use nag_rand_sample (g05ndc) to take a sample from ipop and put it into isampl; |
(c) |
use the contents of isampl as a set of indices to access the relevant vector or matrix. |
In order to divide a population into several groups,
nag_rand_permute (g05ncc) is more efficient.
In the example program random samples of size
are selected from a vector containing the first eight positive integers in ascending order. The samples are generated and printed for each sample size by a call to nag_rand_sample (g05ndc) after initialization by
nag_rand_init_repeatable (g05kfc).
None.