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

Dirichlet Distribution: Formula, Parameters, Worked Example and Code

Dirichlet distribution defined: formula, parameter reading guide, a worked prior-to-posterior update, APA reporting, and code in Excel, R, Python and Stan.

Written and maintained by CASRAI Editorial Board

Published

On this page

The Dirichlet distribution is a probability distribution over probability vectors: it describes how likely every possible set of K proportions that are positive and sum to 1 (for example, the shares of three response categories). It is the multivariate generalization of the Beta distribution and the standard conjugate prior for categorical and multinomial counts in Bayesian analysis. This guide gives the formula, a fully worked update, reading guidance for the parameters, and short code in Excel, R, Python and Stan.

Ask CASRAI · free to tryQuestion about this guide? Ask CASRAI answers with linked sources. 2 free questions a day, no account.

Ask your first question freeSubscribe

What is the Dirichlet distribution? (definition)

A random vector θ = (θ1, …, θK) follows a Dirichlet distribution with parameter vector α = (α1, …, αK), written θ ~ Dirichlet(α), when its entries are non-negative, sum to 1, and have the density given below. Each αk must be strictly positive. The set of all valid θ is the (K−1)-dimensional simplex: a line segment for K = 2, a triangle for K = 3, a tetrahedron for K = 4.

“What is Dirichlet?” has more than one answer. The distribution described here is named after the mathematician Peter Gustav Lejeune Dirichlet, as is the Dirichlet function covered in the FAQ below, but the two are different objects. The Dirichlet process is a third, related concept: a distribution over distributions, built on the Dirichlet distribution (see the FAQ).

Dirichlet distribution formula, with every symbol explained

The probability density function is

f(θ | α) = [Γ(α0) / (Γ(α1) × … × Γ(αK))] × θ1α1−1 × … × θKαK−1

  • K: the number of categories (K ≥ 2).
  • θk: the proportion for category k, with θk ≥ 0 and Σθk = 1.
  • αk: the concentration parameter for category k, strictly greater than 0.
  • α0: the sum α1 + … + αK, the total concentration.
  • Γ: the gamma function, which generalizes the factorial (Γ(n) = (n−1)! for positive integers).

Moments, for each category i (Gelman et al., 2013, Appendix A; Bishop, 2006, section 2.2.1):

  • Mean: E[θi] = αi / α0
  • Variance: Var[θi] = αi(α0 − αi) / (α0²(α0 + 1))
  • Covariance for i ≠ j: Cov[θi, θj] = −αiαj / (α0²(α0 + 1)), always negative because the proportions must sum to 1
  • Mode, when every αi > 1: (αi − 1) / (α0 − K)

Dirichlet distribution and the Beta distribution

With K = 2 the Dirichlet distribution is the Beta distribution: (θ1, 1 − θ1) ~ Dirichlet(α1, α2) means θ1 ~ Beta(α1, α2). For any K, each single component is also Beta distributed: θi ~ Beta(αi, α0 − αi). The Beta is the conjugate prior for a binomial proportion; the Dirichlet plays the same role for a categorical or multinomial outcome. See the beta-binomial distribution for the K = 2 case in full.

Worked example: updating a Dirichlet prior with counts

Suppose respondents choose one of three options and the prior is Dirichlet(2, 2, 2), which acts like two pseudo-observations per option. Observed counts are c = (10, 5, 3), n = 18. Because the Dirichlet is conjugate to the multinomial likelihood, the posterior is Dirichlet(αk + ck) (Gelman et al., 2013, chapter 3).

  1. Posterior parameters: (2 + 10, 2 + 5, 2 + 3) = (12, 7, 5). Total α0 = 12 + 7 + 5 = 24.
  2. Posterior means: 12/24 = 0.500, 7/24 = 0.292, 5/24 = 0.208 (sum 1.000). The prior means were 2/6 = 0.333 each.
  3. Posterior variances use α0²(α0 + 1) = 576 × 25 = 14,400. Category 1: 12 × 12 / 14,400 = 0.0100, SD = 0.100. Category 2: 7 × 17 / 14,400 = 0.00826, SD = 0.091. Category 3: 5 × 19 / 14,400 = 0.00660, SD = 0.081.
  4. Covariance of categories 1 and 2: −(12 × 7) / 14,400 = −0.00583.
  5. Posterior mode (all α > 1): (11, 6, 4) / (24 − 3) = (11, 6, 4) / 21 = 0.524, 0.286, 0.190 (sum 1.000).

The posterior mean is a compromise between the prior mean and the sample proportions (10/18 = 0.556, 5/18 = 0.278, 3/18 = 0.167). The larger the counts relative to α0, the closer the posterior mean sits to the sample proportions.

Interpreting the Dirichlet distribution and its parameters

The density is a probability density over the simplex, not a probability: it tells you which proportion vectors are relatively more plausible, and probabilities come from integrating it over a region. In the symmetric case (all αk equal):

Concentration α What the distribution does
α < 1 Mass moves toward the corners and edges of the simplex: draws are sparse, with a few large proportions and the rest near 0.
α = 1 Uniform over the simplex. Every valid proportion vector is equally dense, yet each single component is still pulled below 1/K: with K = 10 a component exceeds 1/10 only about 39% of the time (Stan Development Team, Functions Reference).
α > 1 Mass moves toward the centre: draws cluster near equal proportions.
Very large α (for example 1,000) Draws are almost exactly 1/K for every component.

In the asymmetric case, the ratios αk/α0 set the prior mean and the overall size of α0 sets how strongly that prior holds, which is why α is read as pseudocounts.

Assumptions and common mistakes

  • Every α must be positive. Software rejects zero or negative values (NumPy raises a ValueError for negative α).
  • Components are not independent. They must sum to 1, so they are negatively correlated. Placing separate Beta priors on each category does not give a valid probability vector.
  • Fixed K. The distribution assumes the categories are known in advance. If new categories can appear, a Dirichlet process is the usual extension.
  • Alpha = 1 is not “uninformative” for every summary. It is flat on the simplex but implies marginals concentrated below 1/K for large K; run a prior sensitivity analysis when the choice could matter.
  • Density at the boundary. The Stan reference gives density 0 if any θ is exactly 0 or 1, so do not pass such values to the log density.

How to report a Dirichlet prior and posterior (APA style)

Report the prior parameters, the data, the posterior and a summary. Example: “A Dirichlet(2, 2, 2) prior was updated with observed counts of 10, 5, and 3 (N = 18), yielding a Dirichlet(12, 7, 5) posterior with posterior means of .50, .29, and .21 for the three options.” Proportions that cannot exceed 1 are written without a leading zero in APA style. For credible intervals and other summaries see summarizing a posterior distribution, and for the broader framework Bayesian vs frequentist statistics.

How to sample or calculate it in Excel, R, Python and Stan

A Dirichlet draw can be built by drawing independent Gamma(αk, 1) values and dividing each by their sum (NumPy documentation, Generator.dirichlet). See the gamma distribution guide for that distribution.

Excel

Row of gammas, e.g. A1:C1:  =GAMMA.INV(RAND(), 12, 1)   =GAMMA.INV(RAND(), 7, 1)   =GAMMA.INV(RAND(), 5, 1)
Proportions, e.g. A2:      =A1/SUM($A$1:$C$1)   (fill right)

R (base)

alpha <- c(12, 7, 5)
g <- rgamma(length(alpha), shape = alpha, rate = 1)
theta <- g / sum(g)

Python (NumPy)

import numpy as np
rng = np.random.default_rng(1)
draws = rng.dirichlet((12, 7, 5), size=10000)   # shape (10000, 3)
draws.mean(axis=0)   # close to [0.500, 0.292, 0.208]

Stan

parameters { simplex[3] theta; }
model {
  theta ~ dirichlet([2, 2, 2]');
  y ~ multinomial(theta);   // y is an int array of length 3 in data
}

Frequently asked questions

What is Dirichlet?

It usually refers to the Dirichlet distribution above, a distribution over proportion vectors. The name also appears in the Dirichlet function and the Dirichlet process, which are separate concepts.

What is the distribution of a graph, and what does the PDF tell you?

For K = 3 a Dirichlet density is drawn as a heat map on a triangle whose corners are the three categories; brighter areas are proportion vectors with higher density. The PDF gives relative plausibility, not a probability. Probabilities are areas (integrals) of the density over a region of the simplex.

Is the Dirichlet function Riemann integrable?

No. The Dirichlet function equals 1 at rational numbers and 0 at irrational numbers. Every subinterval contains both kinds of numbers, so every upper sum equals the interval length and every lower sum is 0, and the two never converge. It is Lebesgue integrable, with integral 0, because the rationals have measure zero. It has no connection to the distribution.

How is the Dirichlet distribution different from the Dirichlet process?

The distribution has a fixed number of categories K. The Dirichlet process is a distribution over probability distributions that can have unboundedly many categories; its finite-dimensional marginals are Dirichlet distributions.

When should I use it instead of a Beta distribution?

Use the Beta for one proportion with two outcomes and the Dirichlet when there are three or more mutually exclusive categories. Related: categorical distribution.

Sources

  • Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., & Rubin, D. B. (2013). Bayesian data analysis (3rd ed.). CRC Press. Chapter 3 and Appendix A.
  • Bishop, C. M. (2006). Pattern recognition and machine learning. Springer. Section 2.2.1.
  • Stan Development Team. Stan functions reference, Dirichlet distribution: mc-stan.org (read 2026-11-07).
  • NumPy documentation, numpy.random.Generator.dirichlet: numpy.org (read 2026-11-07).

Follow CASRAI

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

Ask CASRAI · free to try

Ask about Dirichlet Distribution: Formula, Parameters, Worked Example and Code

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

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 open 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 →