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..::..Int32
On entry: the number of elements in the population vector to be sampled.
Constraint: n1.
isampl
Type: array<System..::..Int32>[]()[][]
An array of size [m]
On exit: the selected sample.
m
Type: System..::..Int32
On entry: the sample size.
Constraint: 1mn.
g05state
Type: NagLibrary..::..G05..::..G05State
An Object of type G05.G05State.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

Description

g05nd 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 nm possible combinations of elements of isampl may be regarded as being equally probable.
For moderate or large values of n it is theoretically impossible that all combinations of size m may occur, unless m is near 1 or near n. This is because nm 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:
ifail=2
On entry, n<1.
ifail=4
On entry,m<1,
orm>n.
ifail=5
On entry,state vector was not initialized or has been corrupted.
ifail=-9000
An error occured, see message report.
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

Not applicable.

Parallelism and Performance

None.

Further Comments

The time taken by g05nd is of order n.
In order to sample other kinds of vectors, or matrices of higher dimension, the following technique may be used:
(a) set ipop[i-1]=i, for i=1,2,,n;
(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.

Example

See Also