Up: Discrete Multivariate Distributions


DRANDMULTINOMIAL / SRANDMULTINOMIAL

Generates a matrix of random variates from a Multinomial distribution with probability, f(X), defined by: f(X) = [M! * P1^(X1) * P2^(X2) * ... * PK^(XK)] / [X1! * X2! * ... * XK!], where X = (X1,X2,...,XK), P = (P1,P2,...,PK), X1 + X2 + ... + XK = 1 and P1 + P2 + ... + PK = 1.

(Note that SRANDMULTINOMIAL is the single precision version of DRANDMULTINOMIAL. The argument lists of both routines are identical except that any double precision arguments of DRANDMULTINOMIAL are replaced in SRANDMULTINOMIAL by single precision arguments - type REAL in FORTRAN or type float in C).

— SUBROUTINE: DRANDMULTINOMIAL (N,M,P,K,STATE,X,LDX,INFO)
— Input: INTEGER N

On input: number of variates required.
Constraint: N>=0.

— Input: INTEGER M

On input: number of trials.
Constraint: M>=0.

— Input: DOUBLE PRECISION P(K)

On input: vector of probabilities for each of the K possible outcomes.
Constraint: 0 <= P <= 1, for all elements of P and P1 + P2 + ... + PK = 1.

— Input: INTEGER K

On input: number of possible outcomes.
Constraint: K>=2.

— Input/Output: INTEGER STATE(*)

The STATE vector holds information on the state of the base generator being used and as such its minimum length varies. Prior to calling DRANDBINOMIAL STATE must have been initialized. See Initialization of the Base Generators for information on initialization of the STATE variable.
On input: the current state of the base generator.
On output: the updated state of the base generator.

— Output: INTEGER X(LDX,K)

On output: matrix of variates from the specified distribution.

— Input: INTEGER LDX

On input: leading dimension of X in the calling routine.
Constraint: LDX>=M.

— Output: INTEGER INFO

On output: INFO is an error indicator. On successful exit, INFO contains 0. If INFO = -i on exit, the i-th argument had an illegal value.

Example:

     C Generate 100 values from the Multinomial distribution
           INTEGER LSTATE,N, MK
           PARAMETER (LSTATE=16,N=100,MK=10)
           INTEGER I,J,INFO,SEED(1),STATE(LSTATE)
           INTEGER LDC,LDX,K,M
           INTEGER  X(N,MK)
           DOUBLE PRECISION P(MK)
     
     C Set array sizes
           LDX = N
     
     C Set the seed
           SEED(1) = 1234
     
     C Read in the distributional parameters
           READ(5,*) K
           READ(5,*) (P(I),I=1,K)
     
     C Initialize the STATE vector
           CALL DRANDINITIALIZE(1,1,SEED,1,STATE,LSTATE,INFO)
     
     C Generate N variates from the Multinomial distribution
           CALL DRANDMULTINOMIAL(N,M,P,K,STATE,X,LDX,INFO)
     
     C Print the results
           DO 20 I = 1,N
             WRITE(6,*) (X(I,J),J=1,K)
           20 CONTINUE