Dirichlet {lca}R Documentation

The Dirichlet Distribution

Description

Density function and random generation for Dirichlet distribution with parameter 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, log density is returned.
tol Tolerance of vectors not summing to 1 and negative values.

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 case of a vector) x is one less than the length of alpha, the remaining column (or entry) is assumed to make the vector sum to 1.

The k-dimensional Dirichlet distribution has density

Gamma (alpha_1 + ... + alpha_k)*(Gamma(alpha_1)*...*Gamma(alpha_k))^{-1}*x_1^{alpha_1-1}*...*x_k^{alpha_k-1}

assuming that x_i > 0x_i > 0 and x_1 + ... + x_k = 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 be zero.

Value

rdirichlet returns a matrix, each row of which is an independent draw from a Dirichlet distribution with parameter vector 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

http://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))

[Package lca version 0.2 Index]