#------------------------------------------------
#' @title Draw from Dirichlet distribution
#'
#' @description Draw from Dirichlet distribution given a vector of shape
#' parameters.
#'
#' @param shape vector of shape parameters.
#'
#' @importFrom stats rgamma
#' @export
rdirichlet <- function(shape = rep(1,3)) {
x <- rgamma(length(shape), shape = shape, rate = max(shape))
return(x/sum(x))
}
#------------------------------------------------
#' @title Draw from Beta-binomial distribution
#'
#' @description Draw from Beta-binomial distribution.
#'
#' @param n number of draws.
#' @param k number of binomial trials.
#' @param alpha first shape parameter of beta distribution.
#' @param beta second shape parameter of beta distribution.
#'
#' @importFrom stats rbeta rbinom
#' @export
rbetabinom <- function(n = 1, k = 10, alpha = 1, beta = 1) {
p <- rbeta(n = n, shape1 = alpha, shape2 = beta)
ret <- rbinom(n = n, size = k, prob = p)
return(ret)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.