|
NAG[g05ejc] NAG[nag_ran_sample_vec] - Pseudo-random sample without replacement from an integer vector
|
|
Calling Sequence
g05ejc(ia, iz, 'n'=n, 'm'=m, 'fail'=fail)
nag_ran_sample_vec(. . .)
Parameters
|
ia - Vector(1..n, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
On entry: the population to be sampled.
|
|
|
iz - Vector(1..m, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
On exit: the selected sample.
|
|
|
'n'=n - integer; (optional)
|
|
|
Default value: the first dimension of the array ia.
|
|
On entry: the number of elements in the vector to be sampled.
|
|
Constraint: . .
|
|
|
'm'=m - integer; (optional)
|
|
|
Default value: the first dimension of the array iz.
|
|
On entry: the sample size.
|
|
Constraint: . .
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_ran_sample_vec (g05ejc) selects a pseudo-random sample without replacement from an integer vector.
|
|
Description
|
|
nag_ran_sample_vec (g05ejc) performs a single pseudo-random selection of elements from vector ia of length 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.
|
|
Error Indicators and Warnings
|
|
"NE_2_INT_ARG_GT"
On entry, while . These arguments must satisfy .
"NE_INT_ARG_LT"
On entry, n must not be less than 1: .
|
|
Further Comments
|
|
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:
|
b. Use nag_ran_sample_vec (g05ejc) to take a sample from ia and put it into iz
|
|
c. Use the contents of iz as a set of indices to access the relevant object.
|
In order to divide a population into several groups, g05ehc (nag_ran_permut_vec) is more efficient.
|
|
|
Examples
|
|
>
|
n := 8:
m := 1:
ia := Vector([0, 1, 2, 3, 4, 5, 6, 7], datatype=integer[kernelopts('wordsize')/8]):
iz := Vector(1, datatype=integer[kernelopts('wordsize')/8]):
NAG:-g05cbc(0):
NAG:-g05ejc(ia, iz, 'n' = n, 'm' = m):
|
|
|
Download Help Document
Was this information helpful?