R/simulate_hp.R

Defines functions simulate_hp

Documented in simulate_hp

#' The simulate_hp
#'
#' @description
#' Auxiliar function to generate a single observation for HYPERPO.
#'
#' @param mu a single value of the mu parameter.
#' @param sigma a single value of the sigma parameter.
#'
#' @return
#' a single value for the HYPERPO distribution.
#'
#' @export
#' @useDynLib DiscreteDists
#' @importFrom Rcpp sourceCpp
simulate_hp <- function(sigma, mu) {
  pochammer <- function(a, r) if (r == 0) 1 else prod(a:(a + r - 1))
  u <- stats::runif(1)
  y <- 0
  p <- 0
  value <- f11_cpp(gamma=sigma, lambda=mu)
  while (p < u) {
    p <- p + mu ^ y / (value * pochammer(sigma, y))
    y <- y + 1
  }
  y - 1
}

Try the DiscreteDists package in your browser

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

DiscreteDists documentation built on Sept. 14, 2024, 1:07 a.m.