<< Multinomial Multinomial distfun_mnrnd >>

distfun >> distfun > Multinomial > distfun_mnpdf

distfun_mnpdf

Multinomial PDF

Calling Sequence

p = distfun_mnpdf(x,n,P)

Parameters

x :

a m-by-k matrix of doubles, integer value, positive, the m outcomes

n :

a 1-by-1 matrix of doubles, integer value, positive, the number of trials

P :

a m-by-k matrix of doubles, positive, sum to 1, the probability of the k categories

p :

a m-by-1 matrix of doubles, positive, the probability of each outcome

Description

Computes the PDF from the multinomial distribution. On input, we assume that sum(P)==1 (otherwise an error is produced). In general, we should have sum(x,"c")==n. Rows of x for sum(x,"c")>n are associated with p=0.

Each trial is classified in exactly one of k categories, where each category has a different probability. Perform n such trials.

P is the vector of probabilities is of size k. We expect that sum(P)=1 (otherwise, an error is generated). P(i) is the probability that an event will be classified into category i.

The function definition is:

\begin{eqnarray}
f(x,n,P) = \frac{n!}{x_1!\ldots x_k!} p_1^{x_1} \cdots p_k^{x_k}
\end{eqnarray}

Examples

// Compute the probability of the outcome x = [4 0 6]
n = 10
P = [0.3 0.4 0.3]
x = [4 0 6]
p = distfun_mnpdf(x,n,P)
p_expected = 0.001240029

// Plot trinomial distribution
P = [1/2 1/3 1/6]; // Outcome probabilities
n = 6; // Sample size
x1 = 0:n;
x2 = 0:n;
[X1,X2] = meshgrid(x1,x2);
X3 = n-(X1+X2);
X3(X3<0)=0;
X=[X1(:),X2(:),X3(:)];
colors=["r","g","b","c","m","y","k"]
Y = distfun_mnpdf(X,n,repmat(P,(n+1)^2,1));
Y=matrix(Y,n+1,n+1)';
scf();
for i=1:n+1
plot(x1,Y(i,:),colors(i)+"o-")
end
legend("x1="+string(0:n));
xlabel("X2")
ylabel("P")
title("Trinomial Distribution (X3=n-X1-X2)")

Authors

Bibliography

Wikipedia, Multinomial distribution function, http://en.wikipedia.org/wiki/Multinomial_distribution


Report an issue
<< Multinomial Multinomial distfun_mnrnd >>