nag_rngs_2_way_table (g05qdc) generates a random two-way table.
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_rngs_2_way_table (g05qdc) 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_rngs_init_repeatable (g05kbc) (for a repeatable sequence if computed sequentially) or
nag_rngs_init_nonrepeatable (g05kcc) (for a non-repeatable sequence) must be called prior to the first call to nag_rngs_2_way_table (g05qdc).
- 1:
order – Nag_OrderTypeInput
-
On entry: the
order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by
. See
Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint:
or Nag_ColMajor.
- 2:
mode – IntegerInput
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_rngs_2_way_table (g05qdc).
- Set up reference vector and generate two-way table.
Constraint:
, or .
- 3:
nrow – IntegerInput
On entry:
, the number of rows in the table.
Constraint:
.
- 4:
ncol – IntegerInput
On entry:
, the number of columns in the table.
Constraint:
.
- 5:
totr[nrow] – const IntegerInput
On entry: the row totals, , for .
Constraints:
- , for ;
- .
- 6:
totc[ncol] – const IntegerInput
On entry: the column totals, , for .
Constraints:
- , for ;
- .
- 7:
x[] – IntegerOutput
-
Note: the dimension,
dim, of the array
x
must be at least
- when ;
- when .
Where
appears in this document, it refers to the array element
- when ;
- when .
On exit: if or , a pseudorandom two-way by table, , with element containing the th entry in the table such that and
- 8:
pdx – IntegerInput
-
On entry: the stride separating row or column elements (depending on the value of
order) in the array
x.
Constraints:
- if ,
;
- if , .
- 9:
igen – IntegerInput
-
On entry: must contain the identification number for the generator to be used to return a pseudorandom number and should remain unchanged following initialization by a prior call to
nag_rngs_init_repeatable (g05kbc) or
nag_rngs_init_nonrepeatable (g05kcc).
- 10:
iseed[] – IntegerCommunication Array
-
On entry: contains values which define the current state of the selected generator.
On exit: contains updated values defining the new state of the selected generator.
- 11:
r[nr] – doubleCommunication Array
-
On entry: if , the reference vector from the previous call to nag_rngs_2_way_table (g05qdc).
On exit: the reference vector.
- 12:
nr – IntegerInput
On entry: the dimension of the array
r.
Constraint:
.
- 13:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
- NE_ALLOC_FAIL
Dynamic memory allocation failed.
- NE_BAD_PARAM
On entry, argument had an illegal value.
- NE_INT
On entry, .
Constraint: , or .
On entry, .
Constraint: .
On entry,
nr not large enough,
. Minimum length required
.
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_2
On entry, or : and .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
- NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
- NE_PREV_CALL
nrow or
ncol is not the same as when
r was set up in a previous call. Previous value of
, current value of
. Previous value of
, current value of
.
- NE_REAL_ARRAY_ELEM_CONS
On entry,
totc has at least one negative element.
On entry,
totr has at least one negative element.
- NE_REAL_ARRAYS_SUM
On entry, the arrays
totr and
totc do not sum to the same total:
totr array total is
,
totc array total is
.
None.
None.
Following initialization of the pseudorandom number generator by a call to
nag_rngs_init_repeatable (g05kbc), this example generates and prints a
by
two-way table, with row totals of
,
,
and
respectively, and column totals of
,
and
respectively.
None.