# IMSL_RAND_TABLE_2WAY

The IMSL_RAND_TABLE_2WAY function generates a pseudorandom two-way table.

Note: This routine requires an IDL Analyst license. For more information, contact your Exelis VIS sales or technical support representative.

Routine IMSL_RAND_TABLE_2WAY generates pseudorandom entries for a two-way contingency table with fixed row and column totals. The method depends on the size of the table and the total number of entries in the table. If the total number of entries is less than twice the product of the number of rows and columns, the method described by Boyette (1979) and by Agresti, Wackerly, and Boyette (1979) is used. In this method, a work vector is filled with row indices so that the number of times each index appears equals the given row total. This vector is then randomly permuted and used to increment the entries in each row so that the given row total is attained.

For tables with larger numbers of entries, the method of Patefield (1981) is used. This method can be considerably faster in these cases. The method depends on the conditional probability distribution of individual elements, given the entries in the previous rows. The probabilities for the individual elements are computed starting from their conditional means.

## Examples

### Example 1

In this example, IMSL_RAND_TABLE_2WAY is used to generate a two by three table with row totals 3 and 5, and column totals 2, 4, and 2.

r = IMSL_RAND_TABLE_2WAY([3, 5], [2, 4, 2])

PM, r

2 1 0

0 3 2

## Syntax

Result = IMSL_RAND_TABLE_2WAY (row_totals, col_totals)

## Return Value

A N_ELEMENTS(row_totals) by N_ELEMENTS(col_totals) random matrix with the given row and column totals.

## Arguments

### col_totals

One dimensional array containing the column totals. (Input) The elements of row_totals and col_totals must be nonnegative and must sum to the same quantity.

### row_totals

One dimensional array containing the row totals.

## Keywords

None

## Version History

6.4 | Introduced

## See Also