Multinomial probability density function
Y = mnpdf(X,PROB)
Y = mnpdf(X,PROB) returns the pdf for the
multinomial distribution with probabilities
evaluated at each row of
PROB are m-by-k matrices
or 1-by-k vectors, where k is
the number of multinomial bins or categories. Each row of
sum to one, and the sample sizes for each observation (rows of
are given by the row sums
an m-by-1 vector, and
each row of
Y using the corresponding rows of the
inputs, or replicates them if needed.
Compute the Multinomial Distribution pdf
Compute the pdf of a multinomial distribution with a sample size of
n = 10. The probabilities are
p = 1/2 for outcome 1,
p = 1/3 for outcome 2, and
p = 1/6 for outcome 3.
p = [1/2 1/3 1/6]; n = 10; x1 = 0:n; x2 = 0:n; [X1,X2] = meshgrid(x1,x2); X3 = n-(X1+X2);
Compute the pdf of the distribution.
Y = mnpdf([X1(:),X2(:),X3(:)],repmat(p,(n+1)^2,1));
Plot the pdf on a 3-dimensional figure.
Y = reshape(Y,n+1,n+1); bar3(Y) h = gca; h.XTickLabel = [0:n]; h.YTickLabel = [0:n]; xlabel('x_1') ylabel('x_2') zlabel('Probability Mass') title('Trinomial Distribution')
Note that the visualization does not show
x3, which is determined by the constraint
x1 + x2 + x3 = n.