mnpdf - Multinomial probability density function
Syntax
Y = mnpdf(X,PROB)
Description
Y = mnpdf(X,PROB) returns the pdf for the
multinomial distribution with probabilities PROB,
evaluated at each row of X. X and PROB are m-by-k matrices
or 1-by-k vectors, where k is
the number of multinomial bins or categories. Each row of PROB must
sum to one, and the sample sizes for each observation (rows of X)
are given by the row sums sum(X,2). Y is
an m-by-k matrix, and mnpdf computes
each row of Y using the corresponding rows of the
inputs, or replicates them if needed.
Examples
% Compute the distribution
p = [1/2 1/3 1/6]; % Outcome probabilities
n = 10; % Sample size
x1 = 0:n;
x2 = 0:n;
[X1,X2] = meshgrid(x1,x2);
X3 = n-(X1+X2);
Y = mnpdf([X1(:),X2(:),X3(:)],repmat(p,(n+1)^2,1));
% Plot the distribution
Y = reshape(Y,n+1,n+1);
bar3(Y)
set(gca,'XTickLabel',0:n)
set(gca,'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.
See Also
mnrnd
Multinomial Distribution
 | mlecov | | mnrfit |  |
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
Get the Interactive Kit