Welcome to the L3 Harris Geospatial documentation center. Here you will find reference guides and help documents.
﻿

### IMSL_RANDOM_SAMPLE

IMSL_RANDOM_SAMPLE

The IMSL_RANDOM_SAMPLE function generates a simple pseudorandom sample from a finite population.

Routine IMSL_RANDOM_SAMPLE generates a pseudorandom sample from a given population, without replacement, using an algorithm due to McLeod and Bellhouse (1983).

The first Nsamp items in the population are included in the sample. Then, for each successive item from the population, a random item in the sample is replaced by that item from the population with probability equal to the sample size divided by the number of population items that have been encountered at that time.

## Examples

### Example 1

In this example, IMSL_RANDOM_SAMPLE is used to generate a sample of size 5 from a population stored in the matrix population.

`IMSL_RANDOMOPT, Set = 123457`
`pop = IMSL_STATDATA(2)`
`samp = IMSL_RANDOM_SAMPLE(5, pop)`
`PM, samp`
` `
`1764.00 36.4000`
`1828.00 62.5000`
`1923.00 5.80000`
`1773.00 34.8000`
`1769.00 106.100`

### Example 2

Routine IMSL_RANDOM_SAMPLE is now used to generate a sample of size 5 from the same population as in the example above except the data are input to IMSL_RANDOM_SAMPLE one observation at a time. This is the way IMSL_RANDOM_SAMPLE may be used to sample from a file on disk or tape.

Notice that the number of records need not be known in advance.

`IMSL_RANDOMOPT, SET = 123457`
`pop = IMSL_STATDATA(2)`
`samp = IMSL_RANDOM_SAMPLE(5, pop(0, *), /FIRST_CALL, INDEX = ii, \$`
`  NPOP=np)`
`FOR i=1,175 DO samp = IMSL_RANDOM_SAMPLE(5, pop(i, *), \$`
`  /ADDITIONAL_CALL, INDEX = ii, NPOP = np, SAMPLE = samp)`
`PM, samp`
` `
`1764.00 36.4000`
`1828.00 62.5000`
`1923.00 5.80000`
`1773.00 34.8000`
`1769.00 106.100`

## Syntax

Result = IMSL_RANDOM_SAMPLE(Nsamp, Population [, /ADDITIONAL_CALL] [, /DOUBLE] [, /FIRST_CALL] [, INDEX=array] [, NPOP=value] [, SAMPLE=array])

## Return Value

Nsamp by nvar array containing the sample, where nvar is the number of columns in the argument population.

## Arguments

### Nsamp

The sample size desired.

### Population

A one or two dimensional array containing the population to be sampled. If either of the keywords FIRST_CALL or ADDITIONAL_CALL are specified, then population contains a different part of the population on each invocation, otherwise population contains the entire population.

## Keywords

If present and nonzero, then this is an additional invocation of IMSL_RANDOM_SAMPLE, and updating for the subpopulation in population is performed. Keywords Index, NPOP, and Sample are required if ADDITIONAL_CALL is set.

It is not necessary to know the number of items in the population in advance. NPOP is used to cumulate the population size and should not be changed between calls to IMSL_RANDOM_SAMPLE. See Example 2.

### DOUBLE (optional)

If present and nonzero, double precision is used.

### FIRST_CALL (optional)

If present and nonzero, then this is the first invocation with this data; additional calls to IMSL_RANDOM_SAMPLE may be made to add to the population. Additional calls should be made using the keyword ADDITIONAL_CALL. The keywords INDEX and NPOP are required if FIRST_CALL is set. See Example 2.

### INDEX (optional)

A one-dimensional array of length Nsamp containing the indices of the sample in the population. Output if keyword FIRST_CALL is used. Input/Output if keyword ADDITIONAL_CALL is used.

### NPOP (optional)

The number of items in the population. Output if keyword FIRST_CALL is used. Input/Output if keyword ADDITIONAL_CALL is used.

### SAMPLE (optional)

An array of size nsamp by nvar containing the sample. Initially, the result of calling IMSL_RANDOM_SAMPLE with keyword FIRST_CALL is used for Sample.

## Version History

 6.4 Introduced