Learn R Programming

bayess (version 1.4)

rdirichlet: Random generator for the Dirichlet distribution

Description

This function simulates a sample from a Dirichlet distribution on the $k$ dimensional simplex with arbitrary parameters. The simulation is based on a renormalised vector of gamma variates.

Usage

rdirichlet(n = 1, par = rep(1, 2))

Arguments

n
number of simulations
par
parameters of the Dirichlet distribution, whose length determines the value of k

Value

returns a $n by k$ matrix of Dirichlet simulations

Details

Surprisingly, there is no default Dirichlet distribution generator in the R base packages like MASS or stats. This function can be used in full generality, apart from the book (Chapter 6).

Examples

Run this code
apply(rdirichlet(10,rep(3,5)),2,mean)

Run the code above in your browser using DataLab