Main Content

mnpdf

Multinomial probability density function

Description

y = mnpdf(x,P) returns the probability density of the multinomial distribution with probabilities P, evaluated at each row of x.

example

Examples

collapse all

Compute the pdf of a multinomial distribution with a sample size n. The probabilities are 1/2 for the first outcome, 1/3 for the second outcome, and 1/6 for the third outcome.

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")

Figure contains an axes object. The axes object with title Trinomial Distribution, xlabel x indexOf 1 baseline x_1, ylabel x indexOf 2 baseline x_2 contains 11 objects of type surface.

Note that the visualization does not show x3, which is determined by the constraint x1 + x2 + x3 = n.

Input Arguments

collapse all

Evaluation points, specified as a 1-by-k numeric vector or an m-by-k numeric matrix, where k is the number of multinomial bins or categories. The sample sizes for each observation (rows of x) are given by the row sums sum(x,2).

  • x must have the same number of columns as P.

  • If x is a 1-by-k vector, then mnpdf replicates x into a matrix that has the same number of rows as P.

  • If x and P are matrices, they must have the same number of rows.

Data Types: single | double

Outcome probabilities, specified as one of the following, where k is the number of multinomial bins or categories. P must have the same number of columns as x, and must contain only nonnegative scalar values.

  • A k-by-1 vector that sums to 1. In this case, mnpdf transposes P into a 1-by-k vector.

  • A 1-by-k vector. If x is a matrix, then mnpdf replicates P into a matrix with the same number of rows as x.

  • A j-by-k matrix, where each row corresponds to a multinomial probability distribution. If x is a matrix, then P and x must have the same number of rows.

If a row of P does not sum to 1, the corresponding row in y is NaN.

Data Types: single | double

Output Arguments

collapse all

pdf values, returned as a numeric column vector with the same number of rows as P. mnpdf computes each row of y using the corresponding rows of the inputs. If a row of P does not sum to 1, the corresponding row in y is NaN.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2006b