how to calculate the probability of a multinomial distribution in matlab

You can calculate the probability mass function (pmf) or probability density function (pdf) of a multinomial distribution in MATLAB using the mnpdf function.

The syntax of the function is as follows:

main.m
p = mnpdf(X, pvals)
20 chars
2 lines

where X is a matrix whose rows represent the observed values of the multinomial random variable, and pvals is a vector of length k containing the probabilities of the k possible outcomes of the multinomial distribution.

Here's an example code that calculates the probabilities of a multinomial distribution with k = 3 possible outcomes, given n = 10 trials and the following probabilities: p1 = 0.2, p2 = 0.5, and p3 = 0.3.

main.m
% Define the probabilities
pvals = [0.2, 0.5, 0.3];

% Define the observed values
X = [2, 5, 3; 3, 4, 3; 1, 6, 3];

% Calculate the pmf
p = mnpdf(X, repmat(n, size(X, 1), 1), pvals);
183 chars
9 lines

In this example, the X matrix has three rows, representing three different observations, each with three columns (one for each possible outcome). The n parameter is set to 10 for all observations. The resulting p vector contains the pmf values for each observation.

gistlibby LogSnag