RNMTN

Generates pseudorandom numbers from a multinomial distribution.

Required Arguments

N — Multinomial parameter indicating the number of independent trials. (Input)

P — Vector of length K containing the probabilities of the possible outcomes. (Input)
The elements of P must be positive and must sum to 1.0.

IRNR by K matrix containing the random multinomial vectors in its rows. (Output)

Optional Arguments

NR — Number of random multinomial vectors to generate. (Input)
Default: NR = size (IR,1).

K — The number of mutually exclusive outcomes on any trial. (Input)
K is the length of the multinomial vectors. K must be greater than or equal to 2.
Default: K = size (IR,2).

LDIR — Leading dimension of IR exactly as specified in the dimension statement of the calling program. (Input)
Default: LDIR = size (IR,1).

FORTRAN 90 Interface

Generic: CALL RNMTN (N, P, IR [])

Specific: The specific interface name is S_RNMTN.

FORTRAN 77 Interface

Single: CALL RNMTN (NR, N, K, P, IR, LDIR)

Description

Routine RNMTN generates pseudorandom numbers from a K‑variate multinomial distribution with parameters N and P. K and N must be positive. Each element of P must be positive and the elements must sum to 1. The probability function (with n = N, k = K, and pi = P(I)) is

 

for xi  0 and

 

The deviate in each row of IR is produced by generation of the binomial deviate x1with parameters n and pi and then by successive generations of the conditional binomial deviates xj given x1x2xj1 with parameters nx1  x2  xj1 and pj /(1  p1  p2    pj1).

Comments

The routine RNSET can be used to initialize the seed of the random number generator. The routine RNOPT can be used to select the form of the generator.

Example

In this example, RNMTN is used to generate five pseudorandom 3‑dimensional multinomial variates with parameters N = 20 and P = (0.1, 0.3, 0.6).

 

USE RNMTN_INT

USE UMACH_INT

USE RNSET_INT

 

IMPLICIT NONE

INTEGER K, LDIR

PARAMETER (K=3, LDIR=5)

!

INTEGER I, IR(LDIR,K), ISEED, J, N, NOUT, NR

REAL P(K)

!

CALL UMACH (2, NOUT)

N = 20

NR = 5

P(1) = 0.1

P(2) = 0.3

P(3) = 0.6

ISEED = 123457

CALL RNSET (ISEED)

CALL RNMTN (N, P, IR)

WRITE (NOUT,99999) ((IR(I,J),J=1,K),I=1,NR)

99999 FORMAT (' Multinomial random deviates: ', 3I4, /, (30X,3I4))

END

Output

 

Multinomial random deviates: 5 4 11

3 6 11

3 3 14

5 5 10

4 5 11