The routine may be called by the names g05pzf or nagf_rand_matrix_2waytable.
3Description
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.
4References
Patefield W M (1981) An efficient method of generating tables with given row and column totals Appl. Stats.30 91–97
5Arguments
1: – 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: – IntegerInput
On entry: , the number of rows in the table.
Constraint:
.
3: – IntegerInput
On entry: , the number of columns in the table.
Constraint:
.
4: – Integer arrayInput
On entry: the row totals,
, for .
Constraints:
, for ;
;
, for .
5: – Integer arrayInput
On entry: the column totals,
, for .
Constraints:
, for ;
.
6: – Real (Kind=nag_wp) arrayCommunication Array
On entry: if , the reference vector from the previous call to g05pzf.
On exit: the reference vector.
7: – IntegerInput
On entry: the dimension of the array r as declared in the (sub)program from which g05pzf is called.
Constraint:
.
8: – 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: – Integer arrayOutput
On exit: if or , a pseudorandom two-way table, , with element containing the th entry in the table such that and
10: – IntegerInput
On entry: the first dimension of the array x as declared in the (sub)program from which g05pzf is called.
Constraint:
.
11: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or 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).
6Error 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, .
Constraint: , or .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, at least one element of totr is negative or totr sums to zero.
nrow or ncol is not the same as when r was set up in a previous call.
Previous value of and .
Previous value of and .
On entry, lr is not large enough, : minimum length required .
On entry, state vector has been corrupted or not initialized.
On entry, and .
Constraint: .
On entry, the arrays totr and totc do not sum to the same total: totr array total is , totc array total is .
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
Not applicable.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g05pzf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
9Further Comments
None.
10Example
Following initialization of the pseudorandom number generator by a call to
g05kff, this example generates and prints a two-way table, with row totals of , , and respectively, and column totals of , and respectively.