Dataplot Vol 2 Vol 1

# MULTINOMIAL RANDOM NUMBER

Name:
MULTINOMIAL RANDOM NUMBER GENERATOR
Type:
Let Subcommand
Purpose:
Generate random numbers from a multinomial distribution.
Description:
The multinomial distribution is a multivariate generalization of the binomial distribution. For a binomial distribution, we perform n trials where each trial has two mutually exclusive outcomes (labeled success and failure). Each trial has the same probability of success, p. The binomial distribution is the probability of x successes in the n trials.

The multinomial distribution extends this by allowing k possible outcomes. These outcomes are mutually exclusive with each outcome having probability pi. The pi must sum to 1 and are the same for each trial. The multinomial distribution is the probability that each event occurs xi times (i = 1, 2, ..., k) in the n trials.

For univariate distributions, Dataplot generates random numbers using the common syntax

LET <shape-parameter> = <value>
LET Y = <dist> RANDOM NUMBERS FOR I = 1 1 N
LET Y = LOC + SCALE*Y

Multivariate distributions, however, generally require matrix operations. For this reason, random numbers for multivariate distributions each have their own unique syntax.

To generate multinomial random numbers, you need to specify a variable containing the k probabilities for each outcome (these probabilities must sum to 1), a scalar value specifying the number of trials (n), and a scalar value specifying the number of multinomial events (nevents) to simulate. The output is a matrix with nevent rows and k columns. Each row of the matrix should sum to n.

Syntax:
LET <mat> = MULTINOMIAL RANDOM NUMBERS ' <p> <n> <nevents>
where <p> is a variable containing the desired probabilities for each outcome;
<n> is a number or parameter specifying the desired number of trials;
<nevents> is a number or parameter specifying the number of multinomial events being generated;
and where <mat> is a matrix where the resulting multinomial random numbers are stored.

Dataplot determines the number of possible outcomes from the number of rows in the <p> variable. The returned matrix will have <nevents> rows and columns equal to the number of rows in <p>.

Examples:
LET P = DATA 0.2 0.1 0.3 0.2 0.2
LET N = 100
LET NEVENTS = 10
LET M = MULTINOMIAL RANDOM NUMBERS P N
Note:
Dataplot uses code from the RANLIB library of Brown and Lavato. This library was downloaded from the statlib library. This code implements an algorithm suggested by Luc Devroye (see Reference).
Note:
As with univariate random numbers, the multinomial random numbers are built on an underlying uniform random number generator. Dataplot supports a number of different uniform random number generators. For details, enter

HELP SET RANDOM NUMBER GENERATOR
Default:
None
Synonyms:
None
Related Commands:
 RANDOM NUMBERS = Generate random numbers for 60+ univariate distributions. SET RANDOM NUMBER GENERATOR = Specify which univariate generator to use. MULTIVARIATE NORMAL RANDOM NUMBERS = Generate multivariate normal random numbers. MULTIVARIATE T RANDOM NUMBERS = Generate multivariate t random numbers. INDEPENDENT UNIFORM RANDOM NUMBERS = Generate random numbers for independent uniform distributions. WISHART RANDOM NUMBERS = Generate random numbers for a Wishart distribution. DIRICHLET RANDOM NUMBERS = Generate random numbers for a Dirichlet distribution.
Reference:
"Statistical Distributions: Third Edition", Evans, Hastings, and Peacock, Wiley, 2000.

"Non-Uniform Random Variate Generation", Luc Devroye, Springer-Verlang, 1986, p. 559.

Applications:
Simulation, Bayesian Analysis
Implementation Date:
2003/5
Program:
```dimension 100 columns
.
let p = data 0.2 0.1 0.2 0.3 0.2
let n = 200
let nevents = 10
.
let m = multinomial random numbers p n nevents
.
set write decimals 0
print m
```
Dataplot generated the following output.
```         MATRIX M       --           10 ROWS
--            5 COLUMNS

VARIABLES--M1             M2             M3             M4             M5

33             14             46             67             40
48             22             38             59             33
46             19             38             60             37
37             20             35             61             47
37             28             33             61             41
40             17             35             69             39
33             16             37             68             46
35             24             39             66             36
39             17             39             62             43
33             18             51             54             44
```

Date created: 5/21/2003
Last updated: 5/21/2003