Learn R Programming

CARrampsOcl (version 0.1.4)

rdirichlet: Generate random samples from dirichlet distribution.

Description

Generate random samples from dirichlet distribution.

Usage

rdirichlet(n, parms)

Arguments

n
number of vectors to be drawn
parms
vector of parameters of dirichlet distribution

Value

  • n draws from the dirichlet density with parameters in parms

Examples

Run this code
## The function is currently defined as
function (n, parms) 
{
# generate n random vectors from dirichlet
# rejection envelope

    l <- length(parms)
    x <- matrix(rgamma(l * n, parms), ncol = l, byrow = TRUE)
    sm <- x %*% rep(1, l)
    return(x/as.vector(sm))
  }

Run the code above in your browser using DataLab