next up previous contents
Next: RANDNCHI Generate Noncentral Chi-Square Up: Random Number Generation Previous: RANDGAMMA Generate Gamma-Distributed Random   Contents

Subsections

RANDMULTI Generate Multinomial-distributed Random Variables

Usage

This function generates samples from a multinomial distribution given the probability of each outcome. The general syntax for its use is

   y = randmulti(N,pvec)

where N is the number of experiments to perform, and pvec is the vector of probabilities describing the distribution of outcomes.

Function Internals

A multinomial distribution describes the number of times each of m possible outcomes occurs out of N trials, where each outcome has a probability p_i. More generally, suppose that the probability of a Bernoulli random variable X_i is p_i, and that

$\displaystyle \sum_{i=1}^{m} p_i = 1.
$

Then the probability that X_i occurs x_i times is

$\displaystyle P_N(x_1,x_2,\ldots,x_n) = \frac{N!}{x_1!\cdots x_n!} p_1^{x_1}\cdots p_n^{x_n}.
$

Example

Suppose an experiment has three possible outcomes, say heads, tails and edge, with probabilities 0.4999, 0.4999 and 0.0002, respectively. Then if we perform ten thousand coin flips we get

--> randmulti(10000,[0.4999,0.4999,0.0002])
ans = 
  <int32>  - size: [1 3]
 
Columns 1 to 3
          5011           4987              2



Samit K. Basu 2005-03-16