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: | 2025-01-14 03:21:48 UTC |
Source: | https://github.com/zhuxr11/cbbinom |
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.
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 )
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 )
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 |
lower.tail |
logical; if TRUE (default), probabilities are
|
p |
vector of probabilities. |
tol , max_iter
|
arguments passed on to |
n |
number of observations. If |
Derived from the continuous binomial distribution (Ilienko 2013), the continuous beta-binomial distribution is defined as:
where is the quantile,
is the size,
is the incomplete beta function.
When simplified, the distribution becomes:
where is generalized hypergeometric function,
,
,
.
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>
.
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.
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.
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
# 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)
# 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)