R/rdirichlet.R

Defines functions rdirichlet

rdirichlet <- function(n, alpha) {
  # taken from gtools
  l <- length(alpha)
  x <- matrix(rgamma(l * n, alpha), ncol = l, byrow = TRUE)
  sm <- x %*% rep(1, l)
  res  <- x / as.vector(sm)
  res[is.nan(res)] <- 0
  res
}
ricky-kotecha/rkHMM documentation built on May 4, 2020, 12:08 a.m.