# ASA205 Enumerate Contingency Tables

ASA205 is a FORTRAN90 library which enumerates contingency tables.

ASA205 is Applied Statistics Algorithm 205.

This algorithm generates contingency tables, which are M by N tables of nonnegative integers with specified row and column sums.

For example, for the row sum vector (1,3) and column sum vector (1,1,2), there are "essentially" only the two solutions:

```        0  0  1
1  1  1
```
and
```        0  1  0
1  0  2
```
We could generate another solution by permuting the first two columns of the second solution, but ASA205 doesn't consider that a distinct solution.

Note that it is possible to specify a problem for which there are no corresponding contingency tables at all. The simplest way is if the row and column sum vectors don't themselves sum up to the same value. But there is also a "technical" condition that the two vectors have to satisfy in order for a solution to exist.

### Languages:

ASA205 is available in a FORTRAN77 version and a FORTRAN90 version.

### Related Data and Programs:

ASA144, a FORTRAN90 library which randomly generates an RxC contingency table.

ASA159, a FORTRAN90 library which randomly selects one of the contingency tables corresponding to a given set of row and column sums.

SUBSET, a FORTRAN90 library which includes a routine called I4MAT_01_ROWCOLSUM which generates a (0,1) matrix with given row and column sums.

### Reference:

1. Ian Saunders,
Algorithm AS 205: Enumeration of R x C Tables with Repeated Row Totals,
Applied Statistics,
Volume 33, Number 3, 1984, pages 340-352.

### List of Routines:

• ENUM generates contingency tables with given shape and row and column sums.
• EVAL is called by ENUM every time a new contingency table is determined.
• I4_SWAP swaps two integer values.
• I4MAT_PRINT prints an I4MAT.
• I4VEC_PRINT prints an I4VEC.
• TIMESTAMP prints the current YMDHMS date as a time stamp.

You can go up one level to the FORTRAN90 source codes.

Last revised on 27 January 2008.