NAG Library Routine Document
G05NEF selects a pseudorandom sample, without replacement and allowing for unequal probabilities.
||IPOP(*), N, ISAMPL(M), M, STATE(*), IFAIL
G05NEF selects elements from either the set of values or a supplied population vector of length . The probability of selecting the th element is proportional to a user-supplied weight, . Each element will appear at most once in the sample, i.e., the sampling is done without replacement.
One of the initialization routines G05KFF
(for a repeatable sequence if computed sequentially) or G05KGF
(for a non-repeatable sequence) must be called prior to the first call to G05NEF.
- 1: ORDER – CHARACTER(1)Input
: a flag indicating the sorted status of the WT
- WT is sorted in ascending order,
- WT is sorted in descending order,
- WT is unsorted and G05NEF will sort the weights prior to using them.
Irrespective of the value of ORDER
, no checks are made on the sorted status of WT
, e.g., it is possible to supply
, even when WT
is not sorted. In such cases the WT
array will not be sorted internally, but G05NEF will still work correctly except, possibly, in cases of extreme weight values.
It is usually more efficient to specify a value of ORDER
that is consistent with the status of WT
, or .
- 2: WT(N) – REAL (KIND=nag_wp) arrayInput
On entry: , the relative probability weights. These weights need not sum to .
- , for ;
- at least M values must be nonzero.
- 3: POP – CHARACTER(1)Input
: a flag indicating whether a population to be sampled has been supplied.
- the population is assumed to be the integers and IPOP is not referenced,
- the population must be supplied in IPOP.
- 4: IPOP() – INTEGER arrayInput
the dimension of the array IPOP
must be at least
: the population to be sampled. If
then the population is assumed to be the set of values
and the array IPOP
is not referenced. Elements of IPOP
with the same value are not combined, therefore if
then there is a nonzero probability that the sample will contain both
then that value can appear in ISAMPL
more than once.
- 5: N – INTEGERInput
On entry: , the size of the population.
- 6: ISAMPL(M) – INTEGER arrayOutput
On exit: the selected sample.
- 7: M – INTEGERInput
On entry: , the size of the sample required.
- 8: STATE() – INTEGER arrayCommunication Array
the actual argument supplied must be the array STATE
supplied to the initialization routines G05KFF
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
- 9: IFAIL – INTEGERInput/Output
must be set to
. If you are unfamiliar with this parameter you should refer to Section 3.3
in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
On entry, , or
On entry, or
|On entry,||STATE vector was not initialized or has been corrupted.|
On entry, there are less than M
G05NEF internally allocates
reals and N
Although it is possible to use G05NEF to sample using equal probabilities, by setting all elements of the input array WT
to the same positive value, it is more efficient to use G05NDF
. To sample with replacement, G05TDF
can be used when the probabilities are unequal and G05TLF
when the probabilities are equal.
This example samples from a population of .
9.1 Program Text
Program Text (g05nefe.f90)
9.2 Program Data
Program Data (g05nefe.d)
9.3 Program Results
Program Results (g05nefe.r)