I need to compute the Dirichlet CDF, but I can only find implementations of the PDF.
Do you guys know of any library (preferably in R
) implementing it?
Remember that, if $Y_i$ are independent $\mathrm{Gamma}(a_i,b)$, for $i=1,\dots,k$, then $$ (X_1,\dots,X_k) = \left(\frac{Y_1}{\sum_{j=1}^k Y_j}, \dots, \frac{Y_k}{\sum_{j=1}^k Y_j} \right) \sim \mathrm{Dirichlet}(a_1,\dots,a_k) \, .$$
The proof can be found on page 594 of Luc Devroye's masterpiece.
Therefore, one possibility is to compute a Monte Carlo approximation of
$$
F_{X_1,\dots,X_k}(t_1,\dots,t_k)=P\left\{X_1\leq t_1,\dots, X_k\leq t_k\right\} \, ,
$$
starting with gammas. In R
, try this:
pdirichlet <- function(a, t, N = 10^5) {
rdirichlet <- function(a) { y <- rgamma(length(a), a, 1); y / sum(y) }
x <- replicate(N, rdirichlet(a), simplify = FALSE)
mean(sapply(x, function(x) prod(x <= t)))
}
gtools
, MCMCpack
and dirmult
for example).
$\endgroup$
a <- c(6, 20,2)
how to obtain the Drichelt cdf? is t 2 by 2 matrix?
$\endgroup$
Any library? Mathematica has it. Here's the code for an example plot of a Dirichlet CDF from the documentation:
Plot3D[CDF[DirichletDistribution[{1, 3, 2}], {x, y}], {x, 0, 1}, {y, 0, 1}]
rdirichlet
. If it's only 3-variate or possibly 4-variate (the last component, of course, being redundant) it may be worth trying numerical quadrature. $\endgroup$