Dirichlet: Dirichlet distribution

DirichletR Documentation

Dirichlet distribution

Description

Random number generation for the Dirichlet distribution D(\alpha_1,\dots,\alpha_K).

Usage

rDirichlet(n, alpha=c(1, 1))

Arguments

n

number of observations to be sampled.

alpha

parameters of the Dirichlet distribution (‘prior sample sizes’).

Value

Some objects.

Value for rDirichlet

A matrix with sampled values.

Author(s)

Arnošt Komárek arnost.komarek@mff.cuni.cz

References

Devroye, L. (1986). Non-Uniform Random Variate Generation. New York: Springer-Verlag, Chap. XI.

Gelman, A., Carlin, J. B., Stern, H. S., and Rubin, D. B. (2004). Bayesian Data Analysis. Second Edition. Boca Raton: Chapman and Hall/CRC, pp. 576, 582.

See Also

rbeta.

Examples

set.seed(1977)

alpha <- c(1, 2, 3)
Mean <- alpha/sum(alpha)
Var <- -(alpha %*% t(alpha))
diag(Var) <- diag(Var) + alpha*sum(alpha)
Var <- Var/(sum(alpha)^2*(1+sum(alpha)))
x <- rDirichlet(1000, alpha=alpha)
x[1:5,]

apply(x, 1, sum)[1:5]           ### should be all ones
rbind(Mean, apply(x, 2, mean))

var(x)
print(Var)

mixAK documentation built on Sept. 25, 2023, 5:08 p.m.

Related to Dirichlet in mixAK...