The Dirichlet distribution is a multivariate generalisation of the Beta distribution. It is the conjugate prior of the Categorical and Multinomial distributions, and describes a probability distribution over the \((k-1)\)-simplex — the set of \(k\)-dimensional vectors whose components are non-negative and sum to one.
dist_dirichlet(alpha)We recommend reading this documentation on pkgdown which renders math nicely. https://pkg.mitchelloharawild.com/distributional/reference/dist_dirichlet.html
In the following, let \(\mathbf{X} = (X_1, \ldots, X_k)\) be a
Dirichlet random variable with concentration parameter
alpha = \(\boldsymbol{\alpha} = (\alpha_1, \ldots, \alpha_k)\),
where each \(\alpha_i > 0\).
Support: \(\mathbf{x}\) on the \((k-1)\)-simplex, i.e. \(x_i \geq 0\) and \(\sum_{i=1}^k x_i = 1\).
Mean: \(E(X_i) = \frac{\alpha_i}{\alpha_0}\) where \(\alpha_0 = \sum_{i=1}^k \alpha_i\).
Variance:
$$ \mathrm{Var}(X_i) = \frac{\alpha_i(\alpha_0 - \alpha_i)}{\alpha_0^2(\alpha_0 + 1)} $$
Covariance:
$$ \mathrm{Cov}(X_i, X_j) = \frac{-\alpha_i \alpha_j}{\alpha_0^2(\alpha_0 + 1)}, \quad i \neq j $$
Probability density function (p.d.f):
$$ f(\mathbf{x}) = \frac{1}{B(\boldsymbol{\alpha})} \prod_{i=1}^k x_i^{\alpha_i - 1} $$
where \(B(\boldsymbol{\alpha}) = \frac{\prod_{i=1}^k \Gamma(\alpha_i)}{\Gamma(\alpha_0)}\) is the multivariate Beta function.
dist <- dist_dirichlet(alpha = list(c(2, 5, 3)))
dist
#> <distribution[1]>
#> [1] Dirichlet[3]
mean(dist)
#> [,1] [,2] [,3]
#> [1,] 0.2 0.5 0.3
variance(dist)
#> [,1] [,2] [,3]
#> [1,] 0.01454545 0.02272727 0.01909091
support(dist)
#> <support_region[1]>
#> [1] [0,1]^3
generate(dist, 10)
#> [[1]]
#> [,1] [,2] [,3]
#> [1,] 0.07640165 0.6758773 0.24772103
#> [2,] 0.04543086 0.7725136 0.18205558
#> [3,] 0.24312969 0.4593229 0.29754741
#> [4,] 0.01676799 0.3100204 0.67321160
#> [5,] 0.15540203 0.4438351 0.40076290
#> [6,] 0.32521161 0.5558516 0.11893680
#> [7,] 0.36690184 0.2020115 0.43108665
#> [8,] 0.15774304 0.4582181 0.38403888
#> [9,] 0.21673063 0.4360034 0.34726598
#> [10,] 0.40394363 0.5265700 0.06948634
#>
density(dist, cbind(0.2, 0.5, 0.3))
#> [1] 8.505
density(dist, cbind(0.2, 0.5, 0.3), log = TRUE)
#> [1] 2.140654