![]() |
Stan Math Library
5.0.0
Automatic Differentiation
|
return_type_t< T_prior_size > stan::math::dirichlet_multinomial_lpmf | ( | const std::vector< int > & | ns, |
const T_prior_size & | alpha | ||
) |
The log of the Dirichlet-Multinomial probability for the given integer vector n and a vector of prior sample sizes, \alpha.
Each element of \alpha must be greater than 0. Each element of n must be greater than or equal to 0.
Suppose that n = (n_1, \ldots, n_K) has a Dirichlet-multinomial distribution with prior sample size \alpha = (\alpha_1,\ldots,\alpha_K) (also called the intensity):
(n_1,\ldots,n_K)\sim\mbox{DirMult}(\alpha_1,\ldots,\alpha_K)
Write N = n_1 + \cdots + n_K and \alpha_0 = \alpha_1 + \cdots + \alpha_K, then the log probability mass function is given by
\log(p(n_1, \ldots, n_K\,|\,\alpha_1,\ldots,\alpha_K))=\log\left( \frac{\Gamma(\alpha_0)\Gamma(N+1)}{\Gamma(\alpha_0 + N)} \prod_{k=1}^K \frac{\Gamma(n_k + \alpha_k)}{\Gamma(\alpha_k) \Gamma(n_k+1)} \right)\\ = \log(N) + \log(B(\alpha_0, N)) - \sum_{k : n_k > 0} \bigl(\log(n_k) + \log(B(\alpha_k, n_k))\bigr)
The second identity is only valid for N > 0. For N=0, we have \log(p(n\,|\,\alpha)) = 0.
T_prior_size | type of prior sample sizes |
ns | A vector of integers. |
alpha | Prior sample sizes (or intensity vector). |
std::domain_error | if any element of alpha is less than or equal to 0, or infinite. |
std::domain_error | any element of ns is less than 0. |
Definition at line 60 of file dirichlet_multinomial_lpmf.hpp.