Skip to main content
v2026.11,858 entries · CC-BY 4.0

Multinomial Distribution: Formula, Worked Example and Code

The multinomial distribution gives the probability of a set of counts across k categories. Formula, worked example, mean and variance, and code.

Written and maintained by CASRAI Editorial Board

Last updated

The multinomial distribution gives the probability of observing a particular set of counts when you run a fixed number of independent trials and each trial lands in exactly one of several categories. It generalises the binomial distribution from two outcomes to k outcomes. This page shows the formula with every symbol defined, a worked example computed by hand and checked against software, the mean and variance of each count, and short snippets for Excel, R and Python.

What is the multinomial distribution?

The multinomial distribution describes the counts across k categories after n independent trials, when every trial falls into exactly one category and the probability of each category stays the same from trial to trial. Rolling a die 60 times and tallying how often each face appears, or classifying 200 survey responses as agree, neutral or disagree, are standard settings. With k = 2 it is the binomial distribution. It is a distribution over a vector of counts, not over a single number.

Multinomial distribution formula

The probability mass function (PMF) is:

P(X₁ = x₁, …, X_k = x_k) = n! / (x₁! x₂! … x_k!) × p₁^x₁ × p₂^x₂ × … × p_k^x_k

  • n: the number of trials (fixed in advance).
  • k: the number of categories.
  • x₁, …, x_k: the observed counts in each category. They are non-negative integers and must sum to n.
  • p₁, …, p_k: the probability that a single trial falls in each category. They must sum to 1.
  • n! / (x₁! … x_k!): the multinomial coefficient, the number of distinct orderings of the trials that produce those counts.

This is the form documented for scipy.stats.multinomial, whose parameters are the number of trials n and a vector p of category probabilities that “should sum to 1” (SciPy documentation, scipy.stats.multinomial).

Multinomial probability example, worked by hand

Suppose each of 8 independent trials lands in category A with probability 0.3, category B with probability 0.2, or category C with probability 0.5. What is the probability of exactly 1 result in A, 3 in B and 4 in C?

  1. Check the inputs: n = 8, counts 1 + 3 + 4 = 8, and probabilities 0.3 + 0.2 + 0.5 = 1.
  2. Multinomial coefficient: 8! / (1! × 3! × 4!) = 40,320 / (1 × 6 × 24) = 40,320 / 144 = 280.
  3. Probability part: 0.3¹ × 0.2³ × 0.5⁴ = 0.3 × 0.008 × 0.0625 = 0.00015.
  4. Multiply: 280 × 0.00015 = 0.042.

The same inputs in the SciPy documentation’s example give 0.042, matching the hand result.

Mean, variance and covariance of the counts

Each count X_j on its own follows a binomial distribution with parameters n and p_j (R documentation for dmultinom). So the mean of X_j is n × p_j and its variance is n × p_j × (1 − p_j). For the example above:

Category p Mean n × p Variance n × p × (1 − p)
A 0.3 8 × 0.3 = 2.4 8 × 0.3 × 0.7 = 1.68
B 0.2 8 × 0.2 = 1.6 8 × 0.2 × 0.8 = 1.28
C 0.5 8 × 0.5 = 4.0 8 × 0.5 × 0.5 = 2.00

Because the counts must sum to n, they are negatively related: a higher count in one category leaves fewer trials for the others. The covariance between two different counts is −n × p_i × p_j, which is also what SciPy’s cov method returns; for A and B above it is −8 × 0.3 × 0.2 = −0.48.

Relationship to the binomial distribution

With two categories, the multinomial reduces to the binomial. The SciPy documentation shows this numerically: with n = 7 and p = (0.4, 0.6), the multinomial probability of counts (3, 4) is 0.290304, the same value as the binomial probability of 3 successes in 7 trials with p = 0.4. Do not confuse this distribution with multinomial logistic regression, which is a model for predicting a categorical outcome from predictors rather than a distribution of counts.

Interpreting the result

The PMF value is the probability of that exact combination of counts, not of “about” those counts. A value of 0.042 means that, if the model is right, about 4.2% of repeated sets of 8 trials would give exactly (1, 3, 4). Individual outcome probabilities are often small because the probability is spread over many possible count combinations.

What you see What it means
PMF near 0 That exact set of counts is rare under the stated p values. It is not by itself evidence against the model, because every individual combination can be rare.
Observed count far from n × p_j That category is over- or under-represented relative to the model; compare the gap with the standard deviation √(n × p_j × (1 − p_j)).
Counts do not sum to n The PMF is not defined; recheck the data or the value of n.

To test whether observed category counts fit hypothesised probabilities across all categories at once, the usual tool is the chi-square test; the guide on how to choose a statistical test places it among the alternatives.

Assumptions and common mistakes

  • Fixed number of trials. n is set in advance, not determined by the data.
  • Independent trials. One trial’s outcome does not change the next. Sampling without replacement from a small population breaks this.
  • Constant category probabilities. The same p applies to every trial.
  • Mutually exclusive, exhaustive categories. Each trial lands in exactly one category and the p values sum to 1.
  • Mistake: counts that do not add up to n. The PMF only applies when x₁ + … + x_k = n.
  • Mistake: treating the counts as independent. They are negatively correlated, so variances of the individual counts cannot simply be combined as if independent.
  • Mistake: probabilities that do not sum to 1. Software handles this differently. SciPy replaces the last element of p with the leftover probability, while R’s dmultinom normalises prob internally to sum to 1. The same input can therefore give different answers in the two tools.

How to report it (APA example)

Report the model, its parameters and the computed probability in one sentence, then the source of the p values. Example wording:

Assuming 8 independent trials with category probabilities of .30, .20 and .50, the multinomial probability of observing counts of 1, 3 and 4 was .042.

Follow your journal’s style guide for number formatting and say whether the p values came from theory or from earlier data.

How to calculate it in Excel, R or Python

Excel

=MULTINOMIAL(1,3,4)*0.3^1*0.2^3*0.5^4

MULTINOMIAL(1,3,4) returns the coefficient 280; the powers supply the probability part. Result: 0.042. The longhand equivalent is =FACT(8)/(FACT(1)*FACT(3)*FACT(4))*0.3^1*0.2^3*0.5^4.

R

dmultinom(x = c(1, 3, 4), prob = c(0.3, 0.2, 0.5))
# 0.042
rmultinom(10, size = 8, prob = c(0.3, 0.2, 0.5))  # 10 simulated draws, one per column

dmultinom takes the vector of counts and normalises prob internally; size defaults to the sum of the counts. rmultinom returns a K × n matrix of integer counts in which each column sums to size.

Python

from scipy.stats import multinomial

rv = multinomial(8, [0.3, 0.2, 0.5])
print(rv.pmf([1, 3, 4]))   # 0.042 (floating point shows 0.04200000000000007)
print(rv.cov())            # covariance matrix of the counts

Frequently asked questions

What is the difference between binomial and multinomial distributions?

The binomial counts successes across two possible outcomes; the multinomial counts how many trials land in each of k categories. With k = 2 they give the same probabilities.

Do the probabilities have to sum to 1?

Yes. The category probabilities must sum to 1 because each trial lands in exactly one category. If they do not, SciPy and R each adjust the input in a different way, so supply values that sum to 1.

Is the multinomial distribution the same as multinomial logistic regression?

No. The distribution gives probabilities for counts across categories. Multinomial logistic regression models how predictors change the probability of a categorical outcome; it uses the multinomial distribution for its outcome but is a different tool.

What is the mean of a multinomial distribution?

The expected count in category j is n × p_j, because each count is binomial with parameters n and p_j.

Sources

See also the research methods hub and the guide to levels of measurement, since multinomial counts describe nominal categories.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Multinomial Distribution: Formula, Worked Example and Code

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.