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).
— 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/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.
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 |