# Dirichlet-multinomial distribution

Notation | [math]\displaystyle{ \mathrm{DirMult}(n,\boldsymbol{\alpha}) }[/math] | ||
---|---|---|---|

Parameters |
[math]\displaystyle{ n \gt 0 }[/math] number of trials (positive integer) [math]\displaystyle{ \alpha_1, \ldots, \alpha_{K}\gt 0 }[/math] | ||

Support |
[math]\displaystyle{ x_i \in \{0,\dots,n\} }[/math] [math]\displaystyle{ \Sigma x_i = n\! }[/math] | ||

pmf | [math]\displaystyle{ \frac{\Gamma \left(\sum \alpha_k\right) \Gamma \left(n+1\right)} {\Gamma\left(n+\sum \alpha_k\right)}\prod_{k=1}^K\frac{\Gamma(x_{k}+\alpha_{k})}{\Gamma(\alpha_{k}) \Gamma \left(x_k+1\right)} }[/math] | ||

Mean | [math]\displaystyle{ \operatorname{E}(X_i) = n\frac{\alpha_i}{\sum \alpha_k} }[/math] | ||

Variance |
[math]\displaystyle{ \operatorname{Var}(X_i) = n\frac{\alpha_i}{\sum \alpha_k}\left(1-\frac{\alpha_i}{\sum \alpha_k}\right)\left(\frac{n+\sum \alpha_k}{1+\sum \alpha_k}\right) }[/math] [math]\displaystyle{ \textstyle {\mathrm{Cov}}(X_i,X_j) = - n \frac{\alpha_i \alpha_j}{(\sum \alpha_k)^2} \left(\frac{n+\sum \alpha_k}{1+\sum \alpha_k}\right)~~(i\neq j) }[/math] | ||

MGF |
[math]\displaystyle{ \operatorname{E}(\prod\limits_{k=1}^{K} {e}^{t_k\cdot x_k}) = \frac{\Gamma(n+1) \Gamma(\sum \alpha_k)}{\Gamma(\sum \alpha_k+n)} \cdot D_n(\boldsymbol{\alpha},(e^{t_1}, ..., e^{t_K})) }[/math] with [math]\displaystyle{ D_{n}= \frac{1}{n}\sum\limits_{u=1}^{n} \left[\left(\sum\limits_{k=1}^{K} \alpha_{k} \cdot {e}^{t_k\cdot u} \right) D_{n-u}\right] , D_0=1 }[/math] ^{[1]} | ||

CF |
[math]\displaystyle{ \operatorname{E}(\prod\limits_{k=1}^{K} {e}^{i t_k\cdot x_k}) = \frac{\Gamma(n+1) \Gamma(\sum \alpha_k)}{\Gamma(\sum \alpha_k+n)} \cdot D_n(\boldsymbol{\alpha},(e^{it_1}, ..., e^{it_K})) }[/math]
^{[1]} | ||

PGF |
[math]\displaystyle{ \operatorname{E}(\prod\limits_{k=1}^{K} {z_k}^{x_k}) = \frac{\Gamma(n+1) \Gamma(\sum \alpha_k)}{\Gamma(\sum \alpha_k+n)} \cdot D_n(\boldsymbol{\alpha},\mathbf{z}) }[/math]
^{[1]} |

In probability theory and statistics, the **Dirichlet-multinomial distribution** is a family of discrete multivariate probability distributions on a finite support of non-negative integers. It is also called the **Dirichlet compound multinomial distribution** (**DCM**) or **multivariate Pólya distribution** (after George Pólya). It is a compound probability distribution, where a probability vector **p** is drawn from a Dirichlet distribution with parameter vector [math]\displaystyle{ \boldsymbol{\alpha} }[/math], and an observation drawn from a multinomial distribution with probability vector **p** and number of trials *n*. The Dirichlet parameter vector captures the prior belief about the situation and can be seen as a pseudocount: observations of each outcome that occur before the actual data is collected. The compounding corresponds to a Pólya urn scheme. It is frequently encountered in Bayesian statistics, machine learning, empirical Bayes methods and classical statistics as an overdispersed multinomial distribution.

It reduces to the categorical distribution as a special case when *n* = 1. It also approximates the multinomial distribution arbitrarily well for large *α*. The Dirichlet-multinomial is a multivariate extension of the beta-binomial distribution, as the multinomial and Dirichlet distributions are multivariate versions of the binomial distribution and beta distributions, respectively.

## Specification

### Dirichlet-multinomial as a compound distribution

The Dirichlet distribution is a conjugate distribution to the multinomial distribution. This fact leads to an analytically tractable compound distribution.
For a random vector of category counts [math]\displaystyle{ \mathbf{x}=(x_1,\dots,x_K) }[/math], distributed according to a multinomial distribution, the marginal distribution is obtained by integrating on the distribution for **p** which can be thought of as a random vector following a Dirichlet distribution:

- [math]\displaystyle{ \Pr(\mathbf{x}\mid n,\boldsymbol{\alpha})=\int_{\mathbf{p}}\mathrm{Mult}(\mathbf{x}\mid n,\mathbf{p})\mathrm{Dir}(\mathbf{p}\mid\boldsymbol{\alpha})\textrm{d}\mathbf{p} }[/math]

which results in the following explicit formula:

- [math]\displaystyle{ \Pr(\mathbf{x}\mid n, \boldsymbol{\alpha})=\frac{\Gamma\left(\alpha_0\right)\Gamma\left(n+1\right)} {\Gamma\left(n+\alpha_0\right)}\prod_{k=1}^K\frac{\Gamma(x_{k}+\alpha_{k})}{\Gamma(\alpha_{k})\Gamma\left(x_{k}+1\right)} }[/math]

where [math]\displaystyle{ \alpha_0 }[/math] is defined as the sum [math]\displaystyle{ \alpha_0 = \sum \alpha_k }[/math]. Another form for this same compound distribution, written more compactly in terms of the beta function, *B*, is as follows:

[math]\displaystyle{ \Pr(\mathbf{x}\mid n,\boldsymbol{\alpha})=\frac{n B\left(\alpha_0,n\right)} {\prod_{k:x_k\gt 0} x_k B\left(\alpha_k,x_k \right)} . }[/math]

The latter form emphasizes the fact that zero count categories can be ignored in the calculation - a useful fact when the number of categories is very large and sparse (e.g. word counts in documents).

Observe that the pdf is the Beta-binomial distribution when [math]\displaystyle{ K=2 }[/math]. It can also be shown that it approaches the multinomial distribution as [math]\displaystyle{ \alpha_{0} }[/math] approaches infinity. The parameter [math]\displaystyle{ \alpha_{0} }[/math] governs the degree of overdispersion or burstiness relative to the multinomial. Alternative choices to denote [math]\displaystyle{ \alpha_{0} }[/math] found in the literature are S and A.

### Dirichlet-multinomial as an urn model

The Dirichlet-multinomial distribution can also be motivated via an urn model for positive integer values of the vector α, known as the Polya urn model. Specifically, imagine an urn containing balls of K colors numbering [math]\displaystyle{ \alpha_{i} }[/math] for the ith color, where random draws are made. When a ball is randomly drawn and observed, then two balls of the same color are returned to the urn. If this is performed n times, then the probability of observing the random vector [math]\displaystyle{ x }[/math] of color counts is a Dirichlet-multinomial with parameters n and α. If the random draws are with simple replacement (no balls over and above the observed ball are added to the urn), then the distribution follows a multinomial distribution and if the random draws are made without replacement, the distribution follows a multivariate hypergeometric distribution.

## Properties

### Moments

Once again, let [math]\displaystyle{ \alpha_0 = \sum \alpha_k }[/math] and let [math]\displaystyle{ p_i =\frac{\alpha_i}{\sum \alpha_k}=\frac{\alpha_i}{\alpha_0} }[/math], then the expected number of times the outcome *i* was observed over *n* trials is

- [math]\displaystyle{ \operatorname{E}(X_i) = n p_i=n\frac{\alpha_i}{\alpha_0}.\, }[/math]

The covariance matrix is as follows. Each diagonal entry is the variance of a beta-binomially distributed random variable, and is therefore

- [math]\displaystyle{ \operatorname{var}(X_i)=np_i(1-p_i)\left(\frac{n+\sum \alpha_k}{1+\sum \alpha_k}\right)=n\frac{\alpha_i}{\alpha_0}\left(1-\frac{\alpha_i}{\alpha_0}\right)\left(\frac{n+\alpha_0}{1+\alpha_0}\right).\, }[/math]

The off-diagonal entries are the covariances:

- [math]\displaystyle{ \operatorname{cov}(X_i,X_j)=-np_i p_j\left(\frac{n+\sum \alpha_k}{1+\sum \alpha_k}\right)=-n\frac{\alpha_i\alpha_j}{\alpha_0^2}\left(\frac{n+\alpha_0}{1+\alpha_0}\right)\, }[/math]

for *i*, *j* distinct.

All covariances are negative because for fixed *n*, an increase in one component of a Dirichlet-multinomial vector requires a decrease in another component.

This is a *K* × *K* positive-semidefinite matrix of rank *K* − 1.

The entries of the corresponding correlation matrix are

- [math]\displaystyle{ \rho(X_i,X_i) = 1. }[/math]

- [math]\displaystyle{ \rho(X_i,X_j) = \frac{\operatorname{cov}(X_i,X_j)}{\sqrt{\operatorname{var}(X_i)\operatorname{var}(X_j)}} = \frac{-p_i p_j(\frac{n+\alpha_0}{1+\alpha_0})}{\sqrt{p_i(1-p_i)(\frac{n+\alpha_0}{1+\alpha_0}) p_j(1-p_j)(\frac{n+\alpha_0}{1+\alpha_0})}} = -\sqrt{\frac{\alpha_i \alpha_j}{(\alpha_0-\alpha_i)(\alpha_0-\alpha_j)}}. }[/math]

The sample size drops out of this expression.

Each of the *k* components separately has a beta-binomial distribution.

The support of the Dirichlet-multinomial distribution is the set

- [math]\displaystyle{ \{(n_1,\dots,n_k)\in \mathbb{N}^{k}| n_1+\cdots+n_k=n\}.\, }[/math]

Its number of elements is

- [math]\displaystyle{ {n+k-1 \choose k-1}. }[/math]

### Matrix notation

In matrix notation,

- [math]\displaystyle{ \operatorname{E}(\mathbf{X}) = n \mathbf{p},\, }[/math]

and

- [math]\displaystyle{ \operatorname{var}(\mathbf{X}) = n \lbrace \operatorname{diag}(\mathbf{p}) - \mathbf{p}\mathbf{p}^{\rm T} \rbrace \left( \frac{n+\alpha_0}{1+ \alpha_0} \right) ,\, }[/math]

with **p**^{T} = the row vector transpose of the column vector **p**. Letting

- [math]\displaystyle{ \alpha_0 = \frac{1-\rho^2}{\rho^2}\, }[/math], we can write alternatively

- [math]\displaystyle{ \operatorname{var}(\mathbf{X}) = n \lbrace \operatorname{diag}(\mathbf{p}) - \mathbf{p}\mathbf{p}^{\rm T} \rbrace (1+\rho^2(n-1)) ,\, }[/math]

The parameter [math]\displaystyle{ \rho \! }[/math] is known as the "intra class" or "intra cluster" correlation. It is this positive correlation which gives rise to overdispersion relative to the multinomial distribution.

### Aggregation

If

- [math]\displaystyle{ X = (X_1, \ldots, X_K)\sim\operatorname{DM}(\alpha_1,\cdots,\alpha_K) }[/math]

then, if the random variables with subscripts *i* and *j* are dropped from the vector and replaced by their sum,

- [math]\displaystyle{ X' = (X_1, \ldots, X_i + X_j, \ldots, X_K)\sim\operatorname{DM} \left(\alpha_1,\cdots,\alpha_i+\alpha_j,\cdots,\alpha_K \right). }[/math]

This aggregation property may be used to derive the marginal distribution of [math]\displaystyle{ X_i }[/math].

## Likelihood function

Conceptually, we are making *N* independent draws from a categorical distribution with *K* categories. Let us represent the independent draws as random categorical variables [math]\displaystyle{ z_n }[/math] for [math]\displaystyle{ n = 1 \dots N }[/math]. Let us denote the number of times a particular category [math]\displaystyle{ k }[/math] has been seen (for [math]\displaystyle{ k = 1 \dots K }[/math]) among all the categorical variables as [math]\displaystyle{ n_k }[/math], and [math]\displaystyle{ \sum_k n_k = N }[/math]. Then, we have two separate views onto this problem:

- A set of [math]\displaystyle{ N }[/math] categorical variables [math]\displaystyle{ z_1,\dots,z_N }[/math].
- A single vector-valued variable [math]\displaystyle{ \mathbf{x}=(n_1,\dots,n_K) }[/math], distributed according to a multinomial distribution.

The former case is a set of random variables specifying each *individual* outcome, while the latter is a variable specifying the *number* of outcomes of each of the *K* categories. The distinction is important, as the two cases have correspondingly different probability distributions.

The parameter of the categorical distribution is [math]\displaystyle{ \mathbf{p} = (p_1,p_2,\dots,p_K), }[/math] where [math]\displaystyle{ p_k }[/math] is the probability to draw value [math]\displaystyle{ k }[/math]; [math]\displaystyle{ \mathbf{p} }[/math] is likewise the parameter of the multinomial distribution [math]\displaystyle{ P(\mathbf{x}|\mathbf{p}) }[/math]. Rather than specifying [math]\displaystyle{ \mathbf{p} }[/math] directly, we give it a conjugate prior distribution, and hence it is drawn from a Dirichlet distribution with parameter vector [math]\displaystyle{ \boldsymbol\alpha=(\alpha_1,\alpha_2,\ldots,\alpha_K) }[/math].

By integrating out [math]\displaystyle{ \mathbf{p} }[/math], we obtain a compound distribution. However, the form of the distribution is different depending on which view we take.

### For a set of individual outcomes

#### Joint distribution

For categorical variables [math]\displaystyle{ \mathbb{Z}=z_1,\dots,z_N }[/math], the marginal joint distribution is obtained by integrating out [math]\displaystyle{ \mathbf{p} }[/math]:

- [math]\displaystyle{ \Pr(\mathbb{Z}\mid\boldsymbol{\alpha})=\int_{\mathbf{p}}\Pr(\mathbb{Z}\mid \mathbf{p})\Pr(\mathbf{p}\mid\boldsymbol{\alpha})\textrm{d}\mathbf{p} }[/math]

which results in the following explicit formula:

- [math]\displaystyle{ \Pr(\mathbb{Z}\mid\boldsymbol{\alpha})=\frac{\Gamma\left(A\right)} {\Gamma\left(N+A\right)}\prod_{k=1}^K\frac{\Gamma(n_{k}+\alpha_{k})}{\Gamma(\alpha_{k})} }[/math]

where [math]\displaystyle{ \Gamma }[/math] is the gamma function, with

- [math]\displaystyle{ A=\sum_k \alpha_k\text{ and }N=\sum_k n_k\text{, and where }n_k=\text{number of }z_n\text{'s with the value }k. }[/math]

Note the absence of the multinomial coefficient due to the formula being about the probability of a sequence of categorical variables instead of a probability on the counts within each category.

Although the variables [math]\displaystyle{ z_1,\dots,z_N }[/math] do not appear explicitly in the above formula, they enter in through the [math]\displaystyle{ n_k }[/math] values.^{[clarification needed]}

#### Conditional distribution

Another useful formula, particularly in the context of Gibbs sampling, asks what the conditional density of a given variable [math]\displaystyle{ z_n }[/math] is, conditioned on all the other variables (which we will denote [math]\displaystyle{ \mathbb{Z}^{(-n)} }[/math]). It turns out to have an extremely simple form:

- [math]\displaystyle{ \Pr(z_n=k\mid\mathbb{Z}^{(-n)},\boldsymbol{\alpha}) \propto n_k^{(-n)} + \alpha_k }[/math]

where [math]\displaystyle{ n_k^{(-n)} }[/math] specifies the number of counts of category [math]\displaystyle{ k }[/math] seen in all variables other than [math]\displaystyle{ z_n }[/math].

It may be useful to show how to derive this formula. In general, conditional distributions are proportional to the corresponding joint distributions, so we simply start with the above formula for the joint distribution of all the [math]\displaystyle{ z_1,\dots,z_N }[/math] values and then eliminate any factors not dependent on the particular [math]\displaystyle{ z_n }[/math] in question. To do this, we make use of the notation [math]\displaystyle{ n_k^{(-n)} }[/math] defined above, and

- [math]\displaystyle{ n_j= \begin{cases} n_j^{(-n)}, & \text{if }j\not=k \\ n_j^{(-n)}+1, & \text{if }j=k \end{cases} }[/math]

We also use the fact that

- [math]\displaystyle{ \Gamma(n+1) = n\Gamma(n) }[/math]

Then:

- [math]\displaystyle{ \begin{align} & \Pr(z_n=k\mid\mathbb{Z}^{(-n)},\boldsymbol{\alpha})\\ \propto\ & \Pr(z_n=k,\mathbb{Z}^{(-n)}\mid\boldsymbol{\alpha}) \\ =\ &\ \frac{\Gamma\left(A\right)}{\Gamma\left(N+A\right)}\prod_{j=1}^K\frac{\Gamma(n_{j}+\alpha_{j})}{\Gamma(\alpha_{j})} \\ \propto\ & \prod_{j=1}^K\Gamma(n_{j}+\alpha_{j}) \\ =\ & \Gamma(n_{k}+\alpha_{k})\prod_{j\not=k}\Gamma(n_{j}+\alpha_{j}) \\ =\ & \Gamma(n_k^{(-n)}+1+\alpha_{k})\prod_{j\not=k}\Gamma(n_j^{(-n)}+\alpha_{j}) \\ =\ & (n_k^{(-n)}+\alpha_{k}) \Gamma(n_k^{(-n)}+\alpha_{k})\prod_{j\not=k}\Gamma(n_j^{(-n)}+\alpha_{j}) \\ =\ & (n_k^{(-n)}+\alpha_{k}) \prod_{j}\Gamma(n_j^{(-n)}+\alpha_{j}) \\ \propto\ & n_k^{(-n)}+\alpha_{k}\\ \end{align} }[/math]

In general, it is not necessary to worry about the normalizing constant at the time of deriving the equations for conditional distributions. The normalizing constant will be determined as part of the algorithm for sampling from the distribution (see Categorical distribution). However, when the conditional distribution is written in the simple form above, it turns out that the normalizing constant assumes a simple form:

- [math]\displaystyle{ \sum_k \left( n_k^{(-n)} + \alpha_k \right) = A + \sum_k n_k^{(-n)} = A + N - 1 }[/math]

Hence

- [math]\displaystyle{ \Pr(z_n=k\mid\mathbb{Z}^{(-n)},\boldsymbol{\alpha}) = \frac{n_k^{(-n)} + \alpha_k}{A + N - 1} }[/math]

This formula is closely related to the Chinese restaurant process, which results from taking the limit as [math]\displaystyle{ K \to \infty }[/math].

#### In a Bayesian network

In a larger Bayesian network in which categorical (or so-called "multinomial") distributions occur with Dirichlet distribution priors as part of a larger network, all Dirichlet priors can be collapsed provided that the only nodes depending on them are categorical distributions. The collapsing happens for each Dirichlet-distribution node separately from the others, and occurs regardless of any other nodes that may depend on the categorical distributions. It also occurs regardless of whether the categorical distributions depend on nodes additional to the Dirichlet priors (although in such a case, those other nodes must remain as additional conditioning factors). Essentially, all of the categorical distributions depending on a given Dirichlet-distribution node become connected into a single Dirichlet-multinomial joint distribution defined by the above formula. The joint distribution as defined this way will depend on the parent(s) of the integrated-out Dirichet prior nodes, as well as any parent(s) of the categorical nodes other than the Dirichlet prior nodes themselves.

In the following sections, we discuss different configurations commonly found in Bayesian networks. We repeat the probability density from above, and define it using the symbol [math]\displaystyle{ \operatorname{DirMult}(\mathbb{Z}\mid\boldsymbol{\alpha}) }[/math]:

- [math]\displaystyle{ \Pr(\mathbb{Z}\mid\boldsymbol{\alpha})=\operatorname{DirMult}(\mathbb{Z}\mid\boldsymbol{\alpha})=\frac{\Gamma\left(\sum_k \alpha_k\right)} {\Gamma\left(\sum_k n_k+\alpha_k\right)}\prod_{k=1}^K\frac{\Gamma(n_{k}+\alpha_{k})}{\Gamma(\alpha_{k})} }[/math]

##### Multiple Dirichlet priors with the same hyperprior

Imagine we have a hierarchical model as follows:

- [math]\displaystyle{ \begin{array}{lcl} \boldsymbol\alpha &\sim& \text{some distribution} \\ \boldsymbol\theta_{d=1 \dots M} &\sim& \operatorname{Dirichlet}_K(\boldsymbol\alpha) \\ z_{d=1 \dots M,n=1 \dots N_d} &\sim& \operatorname{Categorical}_K(\boldsymbol\theta_d) \end{array} }[/math]

In cases like this, we have multiple Dirichet priors, each of which generates some number of categorical observations (possibly a different number for each prior). The fact that they are all dependent on the same hyperprior, even if this is a random variable as above, makes no difference. The effect of integrating out a Dirichlet prior links the categorical variables attached to that prior, whose joint distribution simply inherits any conditioning factors of the Dirichlet prior. The fact that multiple priors may share a hyperprior makes no difference:

- [math]\displaystyle{ \Pr(\mathbb{Z}\mid\boldsymbol\alpha) = \prod_d \operatorname{DirMult}(\mathbb{Z}_d\mid\boldsymbol\alpha) }[/math]

where [math]\displaystyle{ \mathbb{Z}_d }[/math] is simply the collection of categorical variables dependent on prior *d*.

Accordingly, the conditional probability distribution can be written as follows:

- [math]\displaystyle{ \Pr(z_{dn}=k\mid\mathbb{Z}^{(-dn)},\boldsymbol\alpha)\ \propto\ n_{k,d}^{(-n)} + \alpha_k }[/math]

where [math]\displaystyle{ n_{k,d}^{(-n)} }[/math] specifically means the number of variables *among the set* [math]\displaystyle{ \mathbb{Z}_d }[/math], excluding [math]\displaystyle{ z_{dn} }[/math] itself, that have the value [math]\displaystyle{ k }[/math] .

It is necessary to count **only** the variables having the value *k* that are tied together to the variable in question through having the same prior. We do **not** want to count any other variables also having the value *k*.

##### Multiple Dirichlet priors with the same hyperprior, with dependent children

Now imagine a slightly more complicated hierarchical model as follows:

- [math]\displaystyle{ \begin{array}{lcl} \boldsymbol\alpha &\sim& \text{some distribution} \\ \boldsymbol\theta_{d=1 \dots M} &\sim& \operatorname{Dirichlet}_K(\boldsymbol\alpha) \\ z_{d=1 \dots M,n=1 \dots N_d} &\sim& \operatorname{Categorical}_K(\boldsymbol\theta_d) \\ \boldsymbol\phi &\sim& \text{some other distribution} \\ w_{d=1 \dots M,n=1 \dots N_d} &\sim& \operatorname{F}(w_{dn}\mid z_{dn},\boldsymbol\phi) \end{array} }[/math]

This model is the same as above, but in addition, each of the categorical variables has a child variable dependent on it. This is typical of a mixture model.

Again, in the joint distribution, only the categorical variables dependent on the same prior are linked into a single Dirichlet-multinomial:

- [math]\displaystyle{ \Pr(\mathbb{Z},\mathbb{W}\mid\boldsymbol\alpha,\boldsymbol\phi) = \prod_d \operatorname{DirMult}(\mathbb{Z}_d\mid\boldsymbol\alpha) \prod_{d=1}^{M} \prod_{n=1}^{N_d} \operatorname{F}(w_{dn}\mid z_{dn},\boldsymbol\phi) }[/math]

The conditional distribution of the categorical variables dependent only on their parents and ancestors would have the identical form as above in the simpler case. However, in Gibbs sampling it is necessary to determine the conditional distribution of a given node [math]\displaystyle{ z_{dn} }[/math] dependent not only on [math]\displaystyle{ \mathbb{Z}^{(-dn)} }[/math] and ancestors such as [math]\displaystyle{ \alpha }[/math] but on *all* the other parameters.

The simplified expression for the conditional distribution is derived above simply by rewriting the expression for the joint probability and removing constant factors. Hence, the same simplification would apply in a larger joint probability expression such as the one in this model, composed of Dirichlet-multinomial densities plus factors for many other random variables dependent on the values of the categorical variables.

This yields the following:

- [math]\displaystyle{ \Pr(z_{dn}=k\mid\mathbb{Z}^{(-dn)},\mathbb{W},\boldsymbol\alpha,\boldsymbol\phi)\ \propto\ (n_{k,d}^{(-n)} + \alpha_k) \operatorname{F}(w_{dn}\mid z_{dn},\boldsymbol\phi) }[/math]

Here the probability density of [math]\displaystyle{ \operatorname{F} }[/math] appears directly. To do random sampling over [math]\displaystyle{ z_{dn} }[/math], we would compute the unnormalized probabilities for all *K* possibilities for [math]\displaystyle{ z_{dn} }[/math] using the above formula, then normalize them and proceed as normal using the algorithm described in the categorical distribution article.

Correctly speaking, the additional factor that appears in the conditional distribution is derived not from the model specification but directly from the joint distribution. This distinction is important when considering models where a given node with Dirichlet-prior parent has multiple dependent children, particularly when those children are dependent on each other (e.g. if they share a parent that is collapsed out). This is discussed more below.

##### Multiple Dirichlet priors with shifting prior membership

Now imagine we have a hierarchical model as follows:

- [math]\displaystyle{ \begin{array}{lcl} \boldsymbol\theta &\sim& \text{some distribution} \\ z_{n=1 \dots N} &\sim& \operatorname{Categorical}_K(\boldsymbol\theta) \\ \boldsymbol\alpha &\sim& \text{some distribution} \\ \boldsymbol\phi_{k=1 \dots K} &\sim& \operatorname{Dirichlet}_V(\boldsymbol\alpha) \\ w_{n=1 \dots N} &\sim& \operatorname{Categorical}_V(\boldsymbol\phi_{z_{n}}) \\ \end{array} }[/math]

Here we have a tricky situation where we have multiple Dirichlet priors as before and a set of dependent categorical variables, but the relationship between the priors and dependent variables isn't fixed, unlike before. Instead, the choice of which prior to use is dependent on another random categorical variable. This occurs, for example, in topic models, and indeed the names of the variables above are meant to correspond to those in latent Dirichlet allocation. In this case, the set [math]\displaystyle{ \mathbb{W} }[/math] is a set of words, each of which is drawn from one of [math]\displaystyle{ K }[/math] possible topics, where each topic is a Dirichlet prior over a vocabulary of [math]\displaystyle{ V }[/math] possible words, specifying the frequency of different words in the topic. However, the topic membership of a given word isn't fixed; rather, it's determined from a set of latent variables [math]\displaystyle{ \mathbb{Z} }[/math]. There is one latent variable per word, a [math]\displaystyle{ K }[/math] -dimensional categorical variable specifying the topic the word belongs to.

In this case, all variables dependent on a given prior are tied together (i.e. correlated) in a group, as before — specifically, all words belonging to a given topic are linked. In this case, however, the group membership shifts, in that the words are not fixed to a given topic but the topic depends on the value of a latent variable associated with the word. However, the definition of the Dirichlet-multinomial density doesn't actually depend on the number of categorical variables in a group (i.e. the number of words in the document generated from a given topic), but only on the counts of how many variables in the group have a given value (i.e. among all the word tokens generated from a given topic, how many of them are a given word). Hence, we can still write an explicit formula for the joint distribution:

- [math]\displaystyle{ \Pr(\mathbb{W}\mid\boldsymbol\alpha,\mathbb{Z}) = \prod_{k=1}^K \operatorname{DirMult}(\mathbb{W}_k\mid\mathbb{Z},\boldsymbol\alpha) = \prod_{k=1}^K \left[\frac{\Gamma\left(\sum_v \alpha_v\right)} {\Gamma\left(\sum_v n_v^{k}+\alpha_v\right)}\prod_{v=1}^V\frac{\Gamma(n_v^{k}+\alpha_{v})}{\Gamma(\alpha_{v})} \right] }[/math]

Here we use the notation [math]\displaystyle{ n_v^{k} }[/math] to denote the number of word tokens whose value is word symbol *v* and which belong to topic *k*.

The conditional distribution still has the same form:

- [math]\displaystyle{ \Pr(w_n=v\mid\mathbb{W}^{(-n)},\mathbb{Z},\boldsymbol\alpha)\ \propto\ n_v^{k,(-n)} + \alpha_v }[/math]

Here again, **only** the categorical variables for words belonging to a given topic are linked (even though this linking will depend on the assignments of the latent variables), and hence the word counts need to be over **only** the words generated by a given topic. Hence the symbol [math]\displaystyle{ n_v^{k,(-n)} }[/math], which is the count of words tokens having the word symbol *v*, but **only** among those generated by topic *k*, and excluding the word itself whose distribution is being described.

(The reason why excluding the word itself is necessary, and why it even makes sense at all, is that in a Gibbs sampling context, we repeatedly resample the values of each random variable, after having run through and sampled all previous variables. Hence the variable will already have a value, and we need to exclude this existing value from the various counts that we make use of.)

##### A combined example: LDA topic models

We now show how to combine some of the above scenarios to demonstrate how to Gibbs sample a real-world model, specifically a smoothed latent Dirichlet allocation (LDA) topic model.

The model is as follows:

- [math]\displaystyle{ \begin{array}{lcl} \boldsymbol\alpha &\sim& \text{A Dirichlet hyperprior, either a constant or a random variable} \\ \boldsymbol\beta &\sim& \text{A Dirichlet hyperprior, either a constant or a random variable} \\ \boldsymbol\theta_{d=1 \dots M} &\sim& \operatorname{Dirichlet}_K(\boldsymbol\alpha) \\ \boldsymbol\phi_{k=1 \dots K} &\sim& \operatorname{Dirichlet}_V(\boldsymbol\beta) \\ z_{d=1 \dots M,n=1 \dots N_d} &\sim& \operatorname{Categorical}_K(\boldsymbol\theta_d) \\ w_{d=1 \dots M,n=1 \dots N_d} &\sim& \operatorname{Categorical}_V(\boldsymbol\phi_{z_{dn}}) \\ \end{array} }[/math]

Essentially we combine the previous three scenarios: We have categorical variables dependent on multiple priors sharing a hyperprior; we have categorical variables with dependent children (the latent variable topic identities); and we have categorical variables with shifting membership in multiple priors sharing a hyperprior. In the standard LDA model, the words are completely observed, and hence we never need to resample them. (However, Gibbs sampling would equally be possible if only some or none of the words were observed. In such a case, we would want to initialize the distribution over the words in some reasonable fashion — e.g. from the output of some process that generates sentences, such as a machine translation model — in order for the resulting posterior latent variable distributions to make any sense.)

Using the above formulas, we can write down the conditional probabilities directly:

- [math]\displaystyle{ \begin{array}{lcl} \Pr(w_{dn}=v\mid\mathbb{W}^{(-dn)},\mathbb{Z},\boldsymbol\beta)\ &\propto\ & \#\mathbb{W}_v^{k,(-dn)} + \beta_v \\ \Pr(z_{dn}=k\mid\mathbb{Z}^{(-dn)},w_{dn}=v,\mathbb{W}^{(-dn)},\boldsymbol\alpha)\ &\propto\ &(\#\mathbb{Z}_k^{d,(-dn)} + \alpha_k) \Pr(w_{dn}=v\mid\mathbb{W}^{(-dn)},\mathbb{Z},\boldsymbol\beta) \\ \end{array} }[/math]

Here we have defined the counts more explicitly to clearly separate counts of words and counts of topics:

- [math]\displaystyle{ \begin{array}{lcl} \#\mathbb{W}_v^{k,(-dn)} &=& \text{number of words having value }v\text{ among topic }k\text{ excluding }w_{dn} \\ \#\mathbb{Z}_k^{d,(-dn)} &=& \text{number of topics having value }k\text{ among document }d\text{ excluding }z_{dn} \\ \end{array} }[/math]

As in the scenario above with categorical variables with dependent children, the conditional probability of those dependent children appears in the definition of the parent's conditional probability. In this case, each latent variable has only a single dependent child word, so only one such term appears. (If there were multiple dependent children, all would have to appear in the parent's conditional probability, regardless of whether there was overlap between different parents and the same children, i.e. regardless of whether the dependent children of a given parent also have other parents. In a case where a child has multiple parents, the conditional probability for that child appears in the conditional probability definition of each of its parents.)

The definition above specifies only the *unnormalized* conditional probability of the words, while the topic conditional probability requires the *actual* (i.e. normalized) probability. Hence we have to normalize by summing over all word symbols:

- [math]\displaystyle{ \begin{array}{rcl} \Pr(z_{dn}=k\mid\mathbb{Z}^{(-dn)},w_{dn}=v,\mathbb{W}^{(-dn)},\boldsymbol\alpha)\ &\propto\ &\bigl(\#\mathbb{Z}_k^{d,(-dn)} + \alpha_k\bigr) \dfrac{\#\mathbb{W}_v^{k,(-dn)} + \beta_v}{\sum_{v'=1}^{V} (\#\mathbb{W}_{v'}^{k,(-dn)} + \beta_{v'})} \\ && \\ &=& \bigl(\#\mathbb{Z}_k^{d,(-dn)} + \alpha_k\bigr) \dfrac{\#\mathbb{W}_v^{k,(-dn)} + \beta_v}{\#\mathbb{W}^{k} + B - 1} \end{array} }[/math]

where

- [math]\displaystyle{ \begin{array}{lcl} \#\mathbb{W}^{k} &=& \text{number of words generated by topic }k \\ B &=& \sum_{v=1}^{V} \beta_v \\ \end{array} }[/math]

It's also worth making another point in detail, which concerns the second factor above in the conditional probability. Remember that the conditional distribution in general is derived from the joint distribution, and simplified by removing terms not dependent on the domain of the conditional (the part on the left side of the vertical bar). When a node [math]\displaystyle{ z }[/math] has dependent children, there will be one or more factors [math]\displaystyle{ \operatorname{F}(\dots\mid z) }[/math] in the joint distribution that are dependent on [math]\displaystyle{ z }[/math]. *Usually* there is one factor for each dependent node, and it has the same density function as the distribution appearing the mathematical definition. However, if a dependent node has another parent as well (a co-parent), and that co-parent is collapsed out, then the node will become dependent on all other nodes sharing that co-parent, and in place of multiple terms for each such node, the joint distribution will have only one joint term. We have exactly that situation here. Even though [math]\displaystyle{ z_{dn} }[/math] has only one child [math]\displaystyle{ w_{dn} }[/math], that child has a Dirichlet co-parent that we have collapsed out, which induces a Dirichlet-multinomial over the entire set of nodes [math]\displaystyle{ \mathbb{W}^{k} }[/math].

It happens in this case that this issue does not cause major problems, precisely because of the one-to-one relationship between [math]\displaystyle{ z_{dn} }[/math] and [math]\displaystyle{ w_{dn} }[/math]. We can rewrite the joint distribution as follows:

- [math]\displaystyle{ \begin{array}{lcl} p(\mathbb{W}^{k}\mid z_{dn}) &=& p(w_{dn}\mid\mathbb{W}^{k,(-dn)},z_{dn})\,p(\mathbb{W}^{k,(-dn)}\mid z_{dn}) \\ &=& p(w_{dn}\mid\mathbb{W}^{k,(-dn)},z_{dn})\,p(\mathbb{W}^{k,(-dn)}) \\ &\sim& p(w_{dn}\mid\mathbb{W}^{k,(-dn)},z_{dn}) \end{array} }[/math]

where in the set [math]\displaystyle{ \mathbb{W}^{k,(-dn)} }[/math] (i.e. the set of nodes [math]\displaystyle{ \mathbb{W}^{k} }[/math] excluding [math]\displaystyle{ w_{dn} }[/math] ), none of the nodes have [math]\displaystyle{ z_{dn} }[/math] as a parent. Hence it can be eliminated as a conditioning factor (line 2), meaning that the entire factor can be eliminated from the conditional distribution (line 3).

##### A second example: Naive Bayes document clustering

Here is another model, with a different set of issues. This is an implementation of an unsupervised Naive Bayes model for document clustering. That is, we would like to classify documents into multiple categories (e.g. "spam" or "non-spam", or "scientific journal article", "newspaper article about finance", "newspaper article about politics", "love letter") based on textual content. However, we don't already know the correct category of any documents; instead, we want to cluster them based on mutual similarities. (For example, a set of scientific articles will tend to be similar to each other in word use but very different from a set of love letters.) This is a type of unsupervised learning. (The same technique can be used for doing semi-supervised learning, i.e. where we know the correct category of some fraction of the documents and would like to use this knowledge to help in clustering the remaining documents.)

The model is as follows:

- [math]\displaystyle{ \begin{array}{lcl} \boldsymbol\alpha &\sim& \text{A Dirichlet hyperprior, either a constant or a random variable} \\ \boldsymbol\beta &\sim& \text{A Dirichlet hyperprior, either a constant or a random variable} \\ \boldsymbol\theta_{d=1 \dots M} &\sim& \operatorname{Dirichlet}_K(\boldsymbol\alpha) \\ \boldsymbol\phi_{k=1 \dots K} &\sim& \operatorname{Dirichlet}_V(\boldsymbol\beta) \\ z_{d=1 \dots M} &\sim& \operatorname{Categorical}_K(\boldsymbol\theta_d) \\ w_{d=1 \dots M,n=1 \dots N_d} &\sim& \operatorname{Categorical}_V(\boldsymbol\phi_{z_{d}}) \\ \end{array} }[/math]

In many ways, this model is very similar to the LDA topic model described above, but it assumes one topic per document rather than one topic per word, with a document consisting of a mixture of topics. This can be seen clearly in the above model, which is identical to the LDA model except that there is only one latent variable per document instead of one per word. Once again, we assume that we are collapsing all of the Dirichlet priors.

The conditional probability for a given word is almost identical to the LDA case. Once again, all words generated by the same Dirichlet prior are interdependent. In this case, this means the words of all documents having a given label — again, this can vary depending on the label assignments, but all we care about is the total counts. Hence:

- [math]\displaystyle{ \begin{array}{lcl} \Pr(w_{dn}=v\mid\mathbb{W}^{(-dn)},\mathbb{Z},\boldsymbol\beta)\ &\propto\ & \#\mathbb{W}_v^{k,(-dn)} + \beta_v \\ \end{array} }[/math]

where

- [math]\displaystyle{ \begin{array}{lcl} \#\mathbb{W}_v^{k,(-dn)} &=& \text{number of words having value }v\text{ among documents with label }k\text{ excluding }w_{dn} \\ \end{array} }[/math]

However, there is a critical difference in the conditional distribution of the latent variables for the label assignments, which is that a given label variable has multiple children nodes instead of just one — in particular, the nodes for all the words in the label's document. This relates closely to the discussion above about the factor [math]\displaystyle{ \operatorname{F}(\dots\mid z_d) }[/math] that stems from the joint distribution. In this case, the joint distribution needs to be taken over all words in all documents containing a label assignment equal to the value of [math]\displaystyle{ z_d }[/math], and has the value of a Dirichlet-multinomial distribution. Furthermore, we cannot reduce this joint distribution down to a conditional distribution over a single word. Rather, we can reduce it down only to a smaller joint conditional distribution over the words in the document for the label in question, and hence we cannot simplify it using the trick above that yields a simple sum of expected count and prior. Although it is in fact possible to rewrite it as a product of such individual sums, the number of factors is very large, and is not clearly more efficient than directly computing the Dirichlet-multinomial distribution probability.

## Related distributions

The one-dimensional version of the Dirichlet-multinomial distribution is known as the Beta-binomial distribution.

The Dirichlet-multinomial distribution has a relationship with the negative binomial distribution analogous to the relationship of the multinomial distribution with the Poisson distribution.^{[2]}

## Uses

The Dirichlet-multinomial distribution is used in automated document classification and clustering, genetics, economy, combat modeling, and quantitative marketing.

## See also

- Beta-binomial distribution
- Chinese restaurant process
- Dirichlet process
- Generalized Dirichlet distribution
- Krichevsky–Trofimov estimator
- Dirichlet negative multinomial distribution

## References

### Citations

- ↑
^{1.0}^{1.1}^{1.2}Glüsenkamp, T. (2018). "Probabilistic treatment of the uncertainty from the finite size of weighted Monte Carlo data".*EPJ Plus***133**(6): 218. doi:10.1140/epjp/i2018-12042-x. Bibcode: 2018EPJP..133..218G. - ↑ Theorem 1 of Zhou, M. (2018). "Nonparametric Bayesian Negative Binomial Factor Analysis".
*Bayesian Analysis***13**(4): 1065–1093. doi:10.1214/17-BA1070.

### Sources

- Elkan, C. (2006) Clustering documents with an exponential-family approximation of the Dirichlet compound multinomial distribution. ICML, 289–296.
- Johnson, N. L., Kotz, S. and Balakrishnan, N. (1997) Discrete multivariate distributions (Vol. 165). New York: Wiley.
- Kvam, P. and Day, D. (2001) The multivariate Polya distribution in combat modeling. Naval Research Logistics, 48, 1–17.
- Madsen, R. E., Kauchak, D. and Elkan, C. (2005) Modeling Word Burstiness Using the Dirichlet Distribution. ICML, 545–552.
- Minka, T. (2003) Estimating a Dirichlet distribution. Technical report Microsoft Research. Includes Matlab code for fitting distributions to data.
- Mosimann, J. E. (1962) On the compound multinomial distribution, the multivariate β-distribution, and correlations among proportions. Biometrika, 49(1–2), 65–82.
- Wagner, U. and Taudes, A. (1986) A Multivariate Polya Model of Brand Choice and Purchase Incidence. Marketing Science, 5(3), 219–244.

Original source: https://en.wikipedia.org/wiki/Dirichlet-multinomial distribution.
Read more |