Package 'cbinom'

Title: Continuous Analog of a Binomial Distribution
Description: Implementation of the d/p/q/r family of functions for a continuous analog to the standard discrete binomial with continuous size parameter and continuous support with x in [0, size + 1], following Ilienko (2013) <arXiv:1303.5990>.
Authors: Dan Dalthorp
Maintainer: Dan Dalthorp <[email protected]>
License: GPL (>= 2)
Version: 1.6
Built: 2024-11-04 04:02:58 UTC
Source: https://github.com/ddalthorp/cbinom

Help Index


Continuous Analog of a Binomial Distribution

Description

Implementation of the d/p/q/r family of functions for a continuous analog to the standard discrete binomial with continuous size parameter and continuous support with x in [0, size + 1].

Details

Included in the package are functions dcbinom(x, size, prob, log = FALSE), pcbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE), qcbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE), and rcbinom(n, size, prob. Usage closely parallels that of the binom family of functions in the stats R package.

Author(s)

Dan Dalthorp <[email protected]>

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

See Also

pcbinom


The Continuous Binomial Distribution

Description

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

Heuristically speaking, this distribution spreads the standard probability mass (dbinom) 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 binomial but shifted slightly to the right. The support of the continuous binomial is [0, size + 1], and the mean is approximately size * prob + 1/2.

Usage

dcbinom(x, size, prob, log = FALSE)
  pcbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE)
  qcbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE)
  rcbinom(n, size, prob)

Arguments

x, q

vector of quantiles.

p

vector of probabilities.

n

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

size

the size parameter.

prob

the prob parameter.

log, log.p

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

lower.tail

logical; if TRUE (default), probabilities are P[X <= x], otherwise, P[X > x]

Details

The cbinom package is an implementation of Ilienko's (2013) continuous binomial distribution.

The continuous binomial distribution with size = N and prob = p has cumulative distribution function

F(x)=B(x,N+1x,p)B(x,N+1x)F(x) = \frac{B(x, N + 1 - x, p)}{B(x, N + 1 - x)}

for x in [0, N + 1], where

B(x,N+1x,p)=p1tx1(1t)y1dt{B(x, N + 1 - x, p) = \int_{p}^{1} t^{x-1}(1-t)^{y-1}dt}

is the incomplete beta function and

B(x,N+1x)=01tx1(1t)y1dt{B(x, N + 1 - x) = \int_{0}^{1} t^{x-1}(1-t)^{y-1}dt}

is the beta function (or beta(x, N - x + 1) in R). The CDF can be expressed in R as F(x) = 1 - pbeta(prob, x, size - x + 1) and the mean calculated as integrate(function(x) pbeta(prob, x, size - x + 1), lower = 0, upper = size + 1).

If an element of x is not in [0, N + 1], the result of dcbinom is zero. The PDF dcbinom(x, size, prob) is computed via numerical differentiation of the CDF = 1 - pbeta(prob, x, size - x + 1).

Value

dcbinom is the density, pcbinom is the distribution function, qcbinom is the quantile function, and rcbinom generates random deviates.

The length of the result is determined by n for rbinom, 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.

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

require(graphics)
# Compare continous binomial to a standard binomial
size <- 20
prob <- 0.2
x <- 0:20
xx <- seq(0, 21, length = 200)
plot(x, pbinom(x, size, prob), xlab = "x", ylab = "P(X <= x)")
lines(xx, pcbinom(xx, size, prob))
legend('bottomright', legend = c("standard binomial", "continuous binomial"),
  pch = c(1, NA), lty = c(NA, 1))
mtext(side = 3, line = 1.5, text = "pcbinom resembles pbinom but continuous and shifted")
pbinom(x, size, prob) - pcbinom(x + 1, size, prob)

# Use "log = TRUE" for more accuracy in the tails and an extended range:
n <- 1000
k <- seq(0, n, by = 20)
cbind(exp(dcbinom(k, n, .481, log = TRUE)), dcbinom(k, n, .481))