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. nag_rand_2_way_table (g05pzc) 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 functions
nag_rand_init_repeatable (g05kfc) (for a repeatable sequence if computed sequentially) or
nag_rand_init_nonrepeatable (g05kgc) (for a non-repeatable sequence) must be called prior to the first call to
nag_rand_2_way_table (g05pzc).
- 1:
– Nag_ModeRNGInput
-
On entry: a code for selecting the operation to be performed by the function.
- Set up reference vector only.
- Generate two-way table using reference vector set up in a prior call to nag_rand_2_way_table (g05pzc).
- 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:
– const IntegerInput
-
On entry: the row totals,
, for .
Constraints:
- , for ;
- ;
- , for .
- 5:
– const IntegerInput
-
On entry: the column totals,
, for .
Constraints:
- , for ;
- .
- 6:
– doubleCommunication Array
-
On entry: if , the reference vector from the previous call to nag_rand_2_way_table (g05pzc).
On exit: the reference vector.
- 7:
– IntegerInput
-
On entry: the dimension of the array
r.
Constraint:
.
- 8:
– IntegerCommunication Array
-
Note: the dimension,
, of this array is dictated by the requirements of associated functions that must have been previously called. This array MUST be the same array passed as argument
state in the previous call to
nag_rand_init_repeatable (g05kfc) or
nag_rand_init_nonrepeatable (g05kgc).
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:
– IntegerOutput
-
On exit: if or , a pseudorandom two-way by table, , with element containing the th entry in the table such that and
- 10:
– IntegerInput
-
On entry: the stride separating matrix column elements in the array
x.
Constraint:
.
- 11:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.7 in How to Use the NAG Library and its Documentation).
None.
Please consult the
x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
None.
Following initialization of the pseudorandom number generator by a call to
nag_rand_init_repeatable (g05kfc), this example generates and prints a
by
two-way table, with row totals of
,
,
and
respectively, and column totals of
,
and
respectively.
None.