R/dirichlet.R

#==================================================================================================#
# Dirichlet distribution
#==================================================================================================#

#' @title Uniform Dirichlet distribution
#'
#' @author Ryan Thompson <ryan.thompson1@unsw.edu.au>
#'
#' @description Random number generation for the uniform Dirichlet distribution (having all
#' concentration parameters set to one).
#'
#' @param n the number of observations
#' @param d the number of dimensions
#'
#' @return A matrix; each row is a random draw and each column is a dimension.
#'
#' @export

rudirichlet <- \(n, d) {
  x <- stats::rexp(n * d)
  x <- matrix(x, n, d)
  x <- x / rowSums(x)
  return(x)
}

Try the familial package in your browser

Any scripts or data that you put into this service are public.

familial documentation built on July 9, 2023, 7:27 p.m.