Learn R Programming

bayess (version 1.6)

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))

Value

returns a \((n,k)\) matrix of Dirichlet simulations

Arguments

n

number of simulations

par

parameters of the Dirichlet distribution, whose length determines the value of k

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