FreeMat

- Main Page
- Related Pages

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 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.

# 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

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 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 =
     5051    0 4948