g05nd selects a pseudorandom sample without replacement from an integer vector.
Syntax
C# |
---|
public static void g05nd( int[] ipop, int n, int[] isampl, int m, G05..::..G05State g05state, out int ifail ) |
Visual Basic |
---|
Public Shared Sub g05nd ( _ ipop As Integer(), _ n As Integer, _ isampl As Integer(), _ m As Integer, _ g05state As G05..::..G05State, _ <OutAttribute> ByRef ifail As Integer _ ) |
Visual C++ |
---|
public: static void g05nd( array<int>^ ipop, int n, array<int>^ isampl, int m, G05..::..G05State^ g05state, [OutAttribute] int% ifail ) |
F# |
---|
static member g05nd : ipop : int[] * n : int * isampl : int[] * m : int * g05state : G05..::..G05State * ifail : int byref -> unit |
Parameters
- ipop
- Type: array<System..::..Int32>[]()[][]An array of size [n]On entry: the population to be sampled.
- n
- Type: System..::..Int32On entry: the number of elements in the population vector to be sampled.Constraint: .
- isampl
- Type: array<System..::..Int32>[]()[][]An array of size [m]On exit: the selected sample.
- m
- Type: System..::..Int32On entry: the sample size.Constraint: .
- g05state
- Type: NagLibrary..::..G05..::..G05StateAn Object of type G05.G05State.
- ifail
- Type: System..::..Int32%On exit: unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).
Description
g05nd 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.
For moderate or large values of it is theoretically impossible that all combinations of size may occur, unless is near 1 or near . This is because exceeds the cycle length of any of the base generators. For practical purposes this is irrelevant, as the time taken to generate all possible combinations is many millenia.
One of the initialization methods (G05KFF not in this release) (for a repeatable sequence if computed sequentially) or (G05KGF not in this release) (for a non-repeatable sequence) must be called prior to the first call to g05nd.
References
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
Error Indicators and Warnings
Errors or warnings detected by the method:
- On entry, .
On entry, , or .
On entry, state vector was not initialized or has been corrupted.
Accuracy
Not applicable.
Parallelism and Performance
None.
Further Comments
The time taken by g05nd is of order .
In order to sample other kinds of vectors, or matrices of higher dimension, the following technique may be used:
(a) | set , for ; |
(b) | use g05nd 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, g05nc is more efficient.