RNSRI
Generates a simple pseudorandom sample of indices.
Required Arguments
NPOP — Number of items in the population. (Input)
INDEX — Vector of length NSAMP containing the indices of the sample. (Output)
INDEX is a random sample (without replacement) of the integers from 1 to NPOP, in increasing order.
Optional Arguments
NSAMP — Sample size desired. (Input)
Default: NSAMP = size (INDEX,1).
FORTRAN 90 Interface
Generic: CALL RNSRI (NPOP, INDEX [, …])
Specific: The specific interface name is S_RNSRI.
FORTRAN 77 Interface
Single: CALL RNSRI (NSAMP, NPOP, INDEX)
Description
Routine RNSRI generates the indices of a pseudorandom sample,without replacement, of size NSAMP numbers from a population of size NPOP. If NSAMP is greater than NPOP/2, the integers from 1 to NPOP are selected sequentially with a probability conditional on the number selected and the number remaining to be considered. If, when the i‑th population index is considered, j items have been included in the sample, then the index i is included with probability
(NSAMP ‑ j)/(NPOP + 1 ‑ i).
If NSAMP is not greater than NPOP/2, a O(NSAMP) algorithm due to Ahrens and Dieter (1985) is used. Of the methods discussed by Ahrens and Dieter, the one called SG* is used in RNSRI. It involves a preliminary selection of q indices using a geometric distribution for the distances between each index and the next one. If the preliminary sample size q is less than NSAMP, a new preliminary sample is chosen, and this is continued until a preliminary sample greater in size than NSAMP is chosen. This preliminary sample is then thinned using the same kind of sampling as described above for the case in which the sample size is greater than half of the population size. Routine RNSRI does not store the preliminary sample indices, but rather restores the state of the generator used in selecting the sample initially, and then passes through once again, making the final selection as the preliminary sample indices are being generated.
Comments
1. The routine
RNSET can be used to initialize the seed of the random number generator. If
NSAMP is greater than
NPOP/2,
RNSRI uses two different generators in an algorithm due to Ahrens and Dieter (1985). The routine
RNOPT can be used to select the form of the generator used for uniform deviates in the algorithm. The generator used for exponential deviates in the algorithm is a nonshuffled generator that is different from the one for the uniform. If
IOPTU is the option indicator for the uniform generator (see documentation for
RNOPT), then the option indicator for the exponential generator is
MOD((2
* INT((
IOPTU + 1)/2) + 1), 6).
2. The routine
RNSRS can be used to select a sample from a population of unknown size.
Example
In this example, RNSRI is used to generate the indices of a pseudorandom sample of size 5 from a population of size 100.
USE RNSRI_INT
USE UMACH_INT
USE RNSET_INT
IMPLICIT NONE
INTEGER INDEX(5), ISEED, NOUT, NPOP
!
CALL UMACH (2, NOUT)
NPOP = 100
ISEED = 123457
CALL RNSET (ISEED)
CALL RNSRI (NPOP, INDEX)
WRITE (NOUT,99999) INDEX
99999 FORMAT (' Random sample: ', 5I4)
END
Output
Random sample: 2 22 53 61 79
Published date: 03/19/2020
Last modified date: 03/19/2020