R/power_series_distributions.R

Defines functions pf_geometric pf_logarithmic pf_ztp

Documented in pf_geometric pf_logarithmic pf_ztp

#' Zero-truncated Poisson probability function
#'
#' @param n Function support, with \eqn{n = 1, 2, \cdots}.
#' @param theta Theta parameter, such that \eqn{\theta > 0}.
#'
#' @return Calculated probability (vector)
#' @export
#'
#' @examples
#' sapply(
#'    X = 1L:1000L,
#'    FUN = function(i)
#'    pf_ztp(n = i, theta = 1.2)
#' ) %>% sum
pf_ztp <- function(n, theta) {
  theta ^ n / ((exp(theta) - 1) * factorial(n))
}

#' Logarithmic probability function
#' @param n Function support, with \eqn{n = 1, 2, \cdots}.
#' @param theta A probability value, i.e, \eqn{0 < \theta < 1}.
#'
#' @return Calculated probability (vector)
#' @export
#'
#' @examples
#' sapply(
#'      X = 1L:1000L,
#'      FUN = function(i)
#'      pf_logarithmic(n = i, theta = 0.5)
#' ) %>% sum
pf_logarithmic <- function(n, theta) {

  f <- function(theta) {
    -theta^n / (n * log(1 - theta))
  }

  if(n == 0) {
    (1 - theta) + theta * f(0)
  } else {
    f(theta)
  }
}

#' Geometric probability function
#' @param n Function support, with \eqn{n = 1, 2, \cdots}.
#' @param theta A probability value, i.e, \eqn{0 < \theta < 1}.
#'
#' @return Calculated probability (vector)
#' @export
#'
#' @examples
#' sapply(
#'    X = 1L:1000L,
#'    FUN = function(i)
#'    pf_geometric(n = i, theta = 0.5)
#' ) %>% sum
pf_geometric <- function(n, theta) {
   theta * (1 - theta)^(n - 1)
}
prdm0/MarshallOlkinPSG documentation built on Dec. 22, 2021, 9:51 a.m.