Density function and random generation for Dirichlet distribution withparameter vector alpha.
Usage
rdirichlet(n, alpha)
ddirichlet(x, alpha, log = FALSE, tol = 1e-10)
Arguments
n
number of random variables to be generated.
alpha
vector of Dirichlet hyper parameter.
x
vector (or matrix) of points in sample space.
log
logical; if TRUE, natural logarithm of density is returned.
tol
tolerance of vectors not summing to 1 and negative values.
Value
rdirichlet returns a matrix, each row of which is an independent drawfrom a Dirichlet distribution with parameter vector alpha.
ddirichlet returns a vector, each entry being the density of thecorresponding row of x. If x is a vector, then the outputwill have length 1.
Details
If x is a matrix, each row is taken to be a different point whosedensity is to be evaluated. If the number of columns in (or length of, in thecase of a vector) x is one less than the length of alpha, theremaining column (or entry) is assumed to make the vector sum to 1.
The k-dimensional Dirichlet distribution has density
$$\frac{\Gamma\left(\sum_i \alpha_i\right)}{\prod_i \Gamma(\alpha_i)} \prod_{i=1}^k x_i^{\alpha_i-1}$$
assuming that $x_i > 0$ and $\sum_i x_i = 1$, and zero otherwise.
If the sum of row entries in x differs from 1 by more than tol,or any entry takes a value less than -tol, the density is assumed to bezero.