Learn R Programming

mcsm (version 1.0)

rdirichlet: Dirichlet generator

Description

This is a random generator for Dirichlet $D(a1,...,ad)$ distributions, based on the normalisation of Gamma $gamma(ai)$ random variables.

Usage

rdirichlet(n, shape)

Arguments

n
Number of generations requested
shape
Vector of $ai$'s

Value

A $(n,length(shape))$ matrix, with one simulated vector per row.

References

Used in Chapter 7 EnteR Monte Carlo Statistical Methods

See Also

rgamma

Examples

Run this code
A=rdirichlet(10^3,rep(.5,5))
hist(A[,1],fre=FALSE,col="grey",nclass=123,xlim=c(0,1),
main="",xlab=expression(p[1]))
curve(dbeta(x,.5,4*.5),add=TRUE,col="sienna",lwd=2)

Run the code above in your browser using DataLab