g05tg generates a sequence of variates, each consisting of pseudorandom integers, from the discrete multinomial distribution with outcomes and trials, where the outcomes have probabilities respectively.
Syntax
C# |
---|
public static void g05tg( int mode, int n, int m, int k, double[] p, double[] r, G05..::..G05State g05state, int[,] x, out int ifail ) |
Visual Basic |
---|
Public Shared Sub g05tg ( _ mode As Integer, _ n As Integer, _ m As Integer, _ k As Integer, _ p As Double(), _ r As Double(), _ g05state As G05..::..G05State, _ x As Integer(,), _ <OutAttribute> ByRef ifail As Integer _ ) |
Visual C++ |
---|
public: static void g05tg( int mode, int n, int m, int k, array<double>^ p, array<double>^ r, G05..::..G05State^ g05state, array<int,2>^ x, [OutAttribute] int% ifail ) |
F# |
---|
static member g05tg : mode : int * n : int * m : int * k : int * p : float[] * r : float[] * g05state : G05..::..G05State * x : int[,] * ifail : int byref -> unit |
Parameters
- mode
- Type: System..::..Int32On entry: a code for selecting the operation to be performed by the method.
- Set up reference vector only.
- Generate variates using reference vector set up in a prior call to g05tg.
- Set up reference vector and generate variates.
- Generate variates without using the reference vector.
Constraint: , , or .
- n
- Type: System..::..Int32On entry: , the number of pseudorandom numbers to be generated.Constraint: .
- m
- Type: System..::..Int32On entry: , the number of trials of the multinomial distribution.Constraint: .
- k
- Type: System..::..Int32On entry: , the number of possible outcomes of the multinomial distribution.Constraint: .
- p
- Type: array<System..::..Double>[]()[][]An array of size [k]On entry: contains the probabilities , for , of the possible outcomes of the multinomial distribution.Constraint: and .
- r
- Type: array<System..::..Double>[]()[][]An array of size [lr]On exit: if , the reference vector.
- g05state
- Type: NagLibrary..::..G05..::..G05StateAn Object of type G05.G05State.
- x
- Type: array<System..::..Int32,2>[,](,)[,][,]An array of size [dim1, _tdx]Note: dim1 must satisfy the constraint:On exit: the first rows of each contain pseudorandom numbers representing a -dimensional variate from the specified multinomial distribution.
- ifail
- Type: System..::..Int32%On exit: unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).
Description
g05tg generates a sequence of groups of integers , for and , from a multinomial distribution with trials and outcomes, where the probability of for each is
where
A single trial can have several outcomes () and the probability of achieving each outcome is known (). After trials each outcome will have occurred a certain number of times. The numbers representing the numbers of occurrences for each outcome after trials is then a single sample from the multinomial distribution defined by the parameters , and , for . This method returns such samples.
When this distribution is equivalent to the binomial distribution with parameters and (see g05ta).
The variates can be generated with or without using a search table and index. If a search table is used then it is stored with the index in a reference vector and subsequent calls to g05tg with the same parameter values can then use this reference vector to generate further variates. The reference array is generated only for the outcome with greatest probability. The number of successes for the outcome with greatest probability is calculated first as for the binomial distribution (see g05ta); the number of successes for other outcomes are calculated in turn for the remaining reduced multinomial distribution; the number of successes for the final outcome is simply calculated to ensure that the total number of successes is .
One of the initialization methods (G05KFF not in this release) (for a repeatable sequence if computed sequentially) or (G05KGF not in this release) (for a non-repeatable sequence) must be called prior to the first call to g05tg.
References
Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley
Error Indicators and Warnings
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface
(LDX) In these
cases, an error in another parameter has usually caused an incorrect value to be inferred.
- On entry, , , or .
- On entry, .
- On entry, .
- On entry, .
- On entry, or for at least one value of .The probabilities , for , do not add up to .
- The maximum value of , for , or m is not the same as when r was set up in a previous call to g05tg with or .On entry, the r vector was not initialized correctly, or has been corrupted.
- On entry, lr is too small when or .
On entry, state vector was not initialized or has been corrupted.
- On entry, .
Accuracy
Not applicable.
Parallelism and Performance
None.
Further Comments
The reference vector for only one outcome can be set up because the conditional distributions cannot be known in advance of the generation of variates. The outcome with greatest probability of success is chosen for the reference vector because it will have the greatest spread of likely values.