Dirichlet {DirichletReg} R Documentation

## The Dirichlet Distribution

### Description

Density function and random number generation for the Dirichlet distribution

### Usage

rdirichlet(n, alpha)

ddirichlet(x, alpha, log = FALSE, sum.up = FALSE)

ddirichlet_R(x, alpha, log = FALSE, sum.up = FALSE)


### Arguments

 n number of random observations to draw x a matrix containing observations alpha the Dirichlet distribution's parameters. Can be a vector (one set of parameters for all observations) or a matrix (a different set of parameters for each observation), see “Details” log if TRUE, logarithmic densities are returned sum.up if TRUE, the (log-)likelihood is returned

### Details

The Dirichlet distribution is a multidimensional generalization of the Beta distribution where each dimension is governed by an \alpha-parameter. Formally this is

% \mathcal{D}(\alpha_i)=\left[\left.\Gamma(\sum_{i}\alpha_i)\right/\prod_i\Gamma(\alpha_i)\right]\prod_{i}y_i^{\alpha_i-1}% 

Usually, alpha is a vector thus the same parameters will be used for all observations. If alpha is a matrix, a complete set of \alpha-parameters must be supplied for each observation.

log returns the logarithm of the densities (therefore the log-likelihood) and sum.up returns the product or sum and thereby the likelihood or log-likelihood.

Dirichlet (log-)densities are by default computed using C-routines (ddirichlet_log_vector and ddirichlet_log_matrix), a version only using R is provided by ddirichlet_R. Caution: Although .C() can be used to call the C routines directly, R will crash or produce wrong values, if, e.g., data types are not set properly.

### Value

 rdirichlet returns a matrix with random numbers according to the supplied alpha vector or matrix. ddirichlet returns a vector of densities (if sum.up = FALSE) or the (log-)likelihood (if sum.up = TRUE) for the given data and alphas. Returns NaN if any element of alpha is \leq0. ddirichlet_R as ddirichlet, only implemented purely in R.

Marco J. Maier

### Examples

X1 <- rdirichlet(100, c(5, 5, 10))

a.mat <- cbind(1:10, 5, 10:1)
a.mat
X2 <- rdirichlet(10, a.mat)
# note how the probabilities in the first an last column relate to a.mat
round(X2, 2)

ddirichlet(X1, c(5, 5, 10))
ddirichlet(X2, a.mat)

ddirichlet(X2[1:3,], c(1, 2, -1))
ddirichlet(X2[1:3,], c(1, 2, -1), sum.up = TRUE)


[Package DirichletReg version 0.7-1 Index]