NAG Library Routine Document
G05PZF
Note: before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.
1 Purpose
G05PZF generates a random two-way table.
2 Specification
SUBROUTINE G05PZF (
MODE,
NROW,
NCOL,
TOTR,
TOTC,
R,
LR,
STATE,
X,
LDX,
IFAIL)
INTEGER
MODE, NROW, NCOL, TOTR(NROW), TOTC(NCOL), LR, STATE(*), X(LDX,NCOL), LDX, IFAIL
REAL (KIND=nag_wp)
R(LR)
3 Description
Given row totals and column totals (with , say),
G05PZF will generate a pseudorandom two-way table of integers such that the row and column totals are satisfied.
The method used is based on that described by
Patefield (1981) which is most efficient when
is large relative to the number of table entries
(i.e.,
). Entries are generated one row at a time and one entry at a time within a row. Each entry is generated using the conditional probability distribution for that entry given the entries in the previous rows and the previous entries in the same row.
A reference vector is used to store computed values that can be reused in the generation of new tables with the same row and column totals. G05PZF can be called to simply set up the reference vector, or to generate a two-way table using a reference vector set up in a previous call, or it can combine both functions in a single call.
One of the initialization routines
G05KFF (for a repeatable sequence if computed sequentially) or
G05KGF (for a non-repeatable sequence) must be called prior to the first call to G05PZF.
4 References
Patefield W M (1981) An efficient method of generating tables with given row and column totals Appl. Stats. 30 91–97
5 Parameters
- 1: MODE – INTEGERInput
On entry: a code for selecting the operation to be performed by the routine.
- Set up reference vector only.
- Generate two-way table using reference vector set up in a prior call to G05PZF.
- Set up reference vector and generate two-way table.
Constraint:
, or .
- 2: NROW – INTEGERInput
On entry: , the number of rows in the table.
Constraint:
.
- 3: NCOL – INTEGERInput
On entry: , the number of columns in the table.
Constraint:
.
- 4: TOTR(NROW) – INTEGER arrayInput
On entry: the row totals,
, for .
Constraints:
- , for ;
- ;
- , for .
- 5: TOTC(NCOL) – INTEGER arrayInput
On entry: the column totals,
, for .
Constraints:
- , for ;
- .
- 6: R(LR) – REAL (KIND=nag_wp) arrayCommunication Array
On entry: if , the reference vector from the previous call to G05PZF.
On exit: the reference vector.
- 7: LR – INTEGERInput
On entry: the dimension of the array
R as declared in the (sub)program from which G05PZF is called.
Constraint:
.
- 8: STATE() – INTEGER arrayCommunication Array
-
Note: the actual argument supplied must be the array
STATE supplied to the initialization routines
G05KFF or
G05KGF.
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
- 9: X(LDX,NCOL) – INTEGER arrayOutput
On exit: if or , a pseudorandom two-way by table, , with element containing the th entry in the table such that and
- 10: LDX – INTEGERInput
On entry: the first dimension of the array
X as declared in the (sub)program from which G05PZF is called.
Constraint:
.
- 11: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
On entry, , or .
On entry, .
On entry, .
At least one element of
TOTR is negative.
At least one element of
TOTC is negative.
The value of
NROW or
NCOL is not the same as when
R was set up in a previous call to G05PZF with
or
.
On entry,
LR is too small when
or
(see
Section 5).
On entry,
STATE vector was not initialized or has been corrupted.
On entry, .
The arrays
TOTR and
TOTC do not sum to the same total.
7 Accuracy
None.
None.
9 Example
Following initialization of the pseudorandom number generator by a call to
G05KFF, this example generates and prints a
by
two-way table, with row totals of
,
,
and
respectively, and column totals of
,
and
respectively.
9.1 Program Text
Program Text (g05pzfe.f90)
9.2 Program Data
Program Data (g05pzfe.d)
9.3 Program Results
Program Results (g05pzfe.r)