Package 'cbbinom'

Title: Continuous Analog of a Beta-Binomial Distribution
Description: Implementation of the d/p/q/r family of functions for a continuous analog to the standard discrete beta-binomial with continuous size parameter and continuous support with x in [0, size + 1].
Authors: Xiurui Zhu [aut, cre]
Maintainer: Xiurui Zhu <[email protected]>
License: MIT + file LICENSE
Version: 0.2.0
Built: 2024-10-18 12:34:01 UTC
Source: CRAN

Help Index


The Continuous Beta-Binomial Distribution

Description

Density, distribution function, quantile function and random generation for a continuous analog to the beta-binomial distribution with parameters size, alpha and beta. The usage and help pages are modeled on the d-p-q-r families of functions for the commonly-used distributions in the stats package.

Usage

dcbbinom(x, size, alpha = 1, beta = 1, ncp = 0, log = FALSE, prec = NULL)

pcbbinom(
  q,
  size,
  alpha = 1,
  beta = 1,
  ncp = 0,
  lower.tail = TRUE,
  log.p = FALSE,
  prec = NULL
)

qcbbinom(
  p,
  size,
  alpha = 1,
  beta = 1,
  ncp = 0,
  lower.tail = TRUE,
  log.p = FALSE,
  prec = NULL,
  tol = 1e-06,
  max_iter = 10000L
)

rcbbinom(
  n,
  size,
  alpha = 1,
  beta = 1,
  ncp = 0,
  prec = NULL,
  tol = 1e-06,
  max_iter = 10000L
)

Arguments

x, q

vector of quantiles.

size

number of trials (zero or more).

alpha, beta

non-negative parameters of the Beta distribution.

ncp

non-centrality parameter.

log, log.p

logical; if TRUE, probabilities p are given as log(p).

prec

arguments passed on to genhypergeo, vectorized and recycled along with distribution parameters.

lower.tail

logical; if TRUE (default), probabilities are P[Xx]P[X \le x], otherwise, P[X>x]P[X > x].

p

vector of probabilities.

tol, max_iter

arguments passed on to uniroot, vectorized and recycled along with distribution parameters.

n

number of observations. If length(n) > 1, the length is taken to be the number required.

Details

Derived from the continuous binomial distribution (Ilienko 2013), the continuous beta-binomial distribution is defined as:

P(xn,α,β)=01B1p(n+1x,x)B(n+1x,x)pα1(1p)β1B(α,β)dp,P(x|n,\alpha,\beta)=\int_0^1\frac{B_{1-p}(n+1-x,x)}{B(n+1-x,x)}\frac{p^{\alpha-1}(1-p)^{\beta-1}}{B(\alpha,\beta)}dp,

where xx is the quantile, nn is the size, Bp(a,b)=0pua1(1u)b1duB_p(a,b)=\int_0^p{u^{a-1}(1-u)^{b-1}du} is the incomplete beta function.

When simplified, the distribution becomes:

P(xn,α,β)=Γ(n+1)B(n+1x+β,α)Γ(x)Γ(n+2x)B(α,β)3F2(a;b;z),P(x|n,\alpha,\beta)=\frac{\Gamma(n+1)B(n+1-x+\beta,\alpha)}{\Gamma(x)\Gamma(n+2-x)B(\alpha,\beta)}{}_3F_2(a;b;z),

where 3F2(a;b;z){}_3F_2(a;b;z) is generalized hypergeometric function, a={1x,n+1x,n+1x+β}a=\{1-x,n+1-x,n+1-x+\beta\}, b={n+2x,n+1x+α+β}b=\{n+2-x,n+1-x+\alpha+\beta\}, z=1z=1.

Heuristically speaking, this distribution spreads the standard probability mass at integer x to the interval [x, x + 1] in a continuous manner. As a result, the distribution looks like a smoothed version of the standard, discrete beta-binomial but shifted slightly to the right. The support of the continuous beta-binomial is [0, size + 1], and the mean is approximately size * alpha / (alpha + beta) + 1/2.

Supplying ncp != 0 moves the support of beta-binomial to [ncp, size + 1 + ncp]. For example, to build a continuous beta-binomial with approximately non-shifted mean, use ncp = -0.5.

These functions are also available in Rcpp as cbbinom::cpp_[d/p/q/r]cbbinom(), and their non-vectorized versions in Rcpp as cbbinom::[d/p/q/r]cbbinom_(). To use them, please use [[Rcpp::depends(cbbinom)]] and #include <cbbinom.h>.

Value

dcbbinom gives the density, pcbbinom the distribution function, qcbbinom the quantile function, and rcbbinom generates random deviates.

Invalid arguments will result in return value NaN, with a warning.

The length of the result is determined by n for rcbbinom, and is the maximum of the lengths of the numerical arguments for the other functions.

The numerical arguments other than n are recycled to the length of the result. Only the first elements of the logical arguments are used.

Note

Change log:

  • 0.1.0 Xiurui Zhu - Initiate the function.

  • 0.2.0 Xiurui Zhu - Re-implement distribution function with BH package, add NULL default tolerance, and add precision parameters.

References

Ilienko, Andreii (2013). Continuous counterparts of Poisson and binomial distributions and their properties. Annales Univ. Sci. Budapest., Sect. Comp. 39: 137-147. http://ac.inf.elte.hu/Vol_039_2013/137_39.pdf

Examples

# Density function
dcbbinom(x = 5, size = 10, alpha = 2, beta = 4)
# Distribution function
(test_val <- pcbbinom(q = 5, size = 10, alpha = 2, beta = 4))
# Quantile function
qcbbinom(p = test_val, size = 10, alpha = 2, beta = 4)
# Random generation
set.seed(1111L)
rcbbinom(n = 10L, size = 10, alpha = 2, beta = 4)