##' Density of the Borel distribution
##'
##' @param x vector of quantiles; integer.
##' @param mu mu parameter (the poisson mean); non-negative.
##' @param log logical; if TRUE, probabilities p are given as log(p).
##' @return probability mass.
##' @author Sebastian Funk
dborel <- function(x, mu, log = FALSE) {
checkmate::assert_numeric(
x, lower = 1, upper = Inf
)
checkmate::assert_number(
mu, lower = 0, finite = TRUE, na.ok = FALSE
)
ld <- -mu * x + (x - 1) * log(mu * x) - lgamma(x + 1)
if (!log) ld <- exp(ld)
return(ld)
}
##' Random number generator from the Borel distribution
##'
##' Random numbers are generated by simulating from a Poisson branching process
##' @param n number of random variates to generate.
##' @param mu mu parameter (the Poisson mean).
##' @param infinite any number to treat as infinite; simulations will be stopped
##' if this number is reached
##' @return vector of random numbers
##' @author Sebastian Funk
rborel <- function(n, mu, infinite = Inf) {
checkmate::assert_number(
n, lower = 1, finite = TRUE, na.ok = FALSE
)
checkmate::assert_number(
mu, lower = 0, finite = TRUE, na.ok = FALSE
)
chain_sim(n, "pois", "size", infinite = infinite, lambda = mu)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.