RANDMULTI Generate Multinomial-distributed Random Variables
Section: Random Number Generation
Usage
This function generates samples from a multinomial distribution given the probability of each outcome. The general syntax for its use isy = 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 ofm
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
Then the probability that X_i
occurs x_i
times is
Example
Suppose an experiment has three possible outcomes, say heads, tails and edge, with probabilities0.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 = 5026 4973 1