NAG Library Function Document
nag_ran_sample_vec (g05ejc) selects a pseudorandom sample without replacement from an integer vector.
||nag_ran_sample_vec (const Integer ia,
nag_ran_sample_vec (g05ejc) performs a single pseudorandom selection of
elements from vector ia
and then places them in vector iz
. Their order in ia
will be preserved in iz
. Each of the
possible combinations of elements of ia
may be regarded as being equiprobable.
Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin
Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley
ia[n] – const IntegerInput
On entry: the population to be sampled.
n – IntegerInput
On entry: the number of elements in the vector to be sampled.
iz[m] – IntegerOutput
On exit: the selected sample.
m – IntegerInput
On entry: the sample size.
fail – NagError *Input/Output
The NAG error argument (see Section 3.6
in the Essential Introduction).
6 Error Indicators and Warnings
On entry, while . These arguments must satisfy .
On entry, .
On entry, .
If is greater than 60 it is theoretically impossible to generate all combinations unless is near 1 or near . This is because the number of possible combinations exceeds the cycle length of the internal random number generator.
The time taken by nag_ran_sample_vec (g05ejc) is of order .
In order to sample other kinds of objects (i.e., vectors, or matrices of higher dimensions), the following technique may be used:
||Set , for (where is the number of objects)
||Use nag_ran_sample_vec (g05ejc) to take a sample from ia and put it into iz
||Use the contents of iz as a set of indices to access the relevant object.
In order to divide a population into several groups, nag_ran_permut_vec (g05ehc)
is more efficient.
From a vector containing and the first positive integers in ascending order, random samples of size are selected and printed.
9.1 Program Text
Program Text (g05ejce.c)
9.2 Program Data
9.3 Program Results
Program Results (g05ejce.r)