Dirichlet: Dirichlet distribution

Description Usage Arguments Value Value for rDirichlet Author(s) References See Also Examples

Description

Random number generation for the Dirichlet distribution D(alpha[1],...,alpha[K]).

Usage

1
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[AT]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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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 July 2, 2020, 2:48 a.m.

Related to Dirichlet in mixAK...