R/rdirichlet.R

Defines functions rdirichlet

Documented in rdirichlet

#'@title Random draw from the dirichlet
#'@name rdirichlet
#'@description Same as the rdirichlet function in MCMCpack but rewritten to minimise dependencies.
#'@details Need to add log option
#'@export
rdirichlet <- function(n, alpha)
{
  l <- length(alpha)
  x <- matrix(rgamma(l * n, alpha), ncol = l, byrow = TRUE)
  sm <- x %*% rep(1, l)
  return(x/as.vector(sm))
}
artaylor85/FreqEstimationModel documentation built on Feb. 1, 2024, 6:44 p.m.