nag_rand_sample (g05ndc) selects a pseudorandom sample without replacement from an integer vector.
nag_rand_sample (g05ndc) selects
$m$ elements from a population vector
ipop of length
$n$ and places them in a sample vector
isampl. Their order in
ipop will be preserved in
isampl. Each of the
$\left(\begin{array}{c}n\\ m\end{array}\right)$ 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.
nag_rand_sample (g05ndc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
In order to sample other kinds of vectors, or matrices of higher dimension, the following technique may be used:
(a) |
set ${\mathbf{ipop}}\left[\mathit{i}-1\right]=\mathit{i}$, for $\mathit{i}=1,2,\dots ,n$; |
(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
$1,2,\dots ,8$ 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.