asa159, a FORTRAN77 code which constructs a table having given row and column sums, by Michael Patefield;
This is a version of Applied Statistics Algorithm 159.
This code accepts a table shape (the number of rows and columns), and two vectors, the lists of row and column sums. There may be 0, 1, or many tables with nonnegative, integral entries that have the given shape and sums. The routine will report the case if there are no candidates. If there is at least one candidate, then the routine will choose one, uniformly over the number of distinct candidates.
For example, suppose M = 2, N = 3, row sum = (/ 6, 5 /) and column sum = (/ 3, 4, 4 /), then here are two tables that satisfy the constraints:
1 2 3 2 2 1and
3 0 3 0 4 1
The computer code and data files described and made available on this web page are distributed under the MIT license
asa159 is available in a C version and a C++ version and a Fortran90 version and a MATLAB version and an Octave version.
asa144, a FORTRAN77 library which randomly generates an RxC contingency table.
ASA205, a FORTRAN77 library which generates all the contingency tables corresponding to a given set of row and column sums.
SUBSET, a FORTRAN77 library which includes a routine called I4MAT_01_ROWCOLSUM which generates a (0,1) matrix with given row and column sums.
Original FORTRAN77 version by Michael Patefield; This version by John Burkardt.