Dirichlet: The Dirichlet Distribution

DirichletR Documentation

The Dirichlet Distribution

Description

Density function and random generation for Dirichlet distribution with parameter vector alpha.

Usage

ddirichlet(x, alpha, log = FALSE, tol = 1e-10) 
rdirichlet(n, alpha)

Arguments

x

vector (or matrix) of points in sample space.

alpha

vector of Dirichlet hyper parameters.

log

logical; if TRUE, natural logarithm of density is returned.

tol

tolerance of vectors not summing to 1 and negative values.

n

number of random variables to be generated.

Details

If x is a matrix, each row is taken to be a different point whose density is to be evaluated. If the number of columns in (or length of, in the alpha, 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, is assumed to be

Value

rdirichlet returns a matrix, each row of which is an independent draw alpha.

ddirichlet returns a vector, each entry being the density of the corresponding row of x. If x is a vector, then the output will have length 1.

Author(s)

Robin Evans

References

https://en.wikipedia.org/wiki/Dirichlet_distribution

Examples


x = rdirichlet(10, c(1,2,3))
x

# Find densities at random points.
ddirichlet(x, c(1,2,3))
# Last column to be inferred.
ddirichlet(x[,c(1,2)], c(1,2,3))
ddirichlet(x, matrix(c(1,2,3), 10, 3, byrow=TRUE))


rje42/rje documentation built on April 3, 2024, 11:08 p.m.