cbinom: The Continuous Binomial Distribution

Description Usage Arguments Details Value References Examples

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

1
2
3
4
  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_p(x, N - x + 1)/B(x, N - x + 1)

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

B_p(x, N - x + 1) = integral_0^p (t^(x-1)(1-t)^(y-1))dt

is the incomplete beta function and

B(x, N - x + 1) = integral_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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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))

Example output

 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
               [,1]          [,2]
 [1,]  0.000000e+00 1.583005e-288
 [2,] 9.419130e-246 9.419130e-246
 [3,] 5.715670e-216 5.715670e-216
 [4,] 6.006038e-191 6.006038e-191
 [5,] 4.469776e-169 4.469776e-169
 [6,] 1.353617e-149 1.353617e-149
 [7,] 4.640570e-132 4.640570e-132
 [8,] 3.524571e-116 3.524571e-116
 [9,] 9.521109e-102 9.521109e-102
[10,]  1.298846e-88  1.298846e-88
[11,]  1.170900e-76  1.170900e-76
[12,]  8.621538e-66  8.621538e-66
[13,]  6.147479e-56  6.147479e-56
[14,]  4.877437e-47  4.877437e-47
[15,]  4.829049e-39  4.829049e-39
[16,]  6.563465e-32  6.563465e-32
[17,]  1.326321e-25  1.326321e-25
[18,]  4.260300e-20  4.260300e-20
[19,]  2.300462e-15  2.300462e-15
[20,]  2.187914e-11  2.187914e-11
[21,]  3.808997e-08  3.808997e-08
[22,]  1.252414e-05  1.252414e-05
[23,]  7.972703e-04  7.972703e-04
[24,]  1.001264e-02  1.001264e-02
[25,]  2.513686e-02  2.513686e-02
[26,]  1.271486e-02  1.271486e-02
[27,]  1.299327e-03  1.299327e-03
[28,]  2.675923e-05  2.675926e-05
[29,]  1.102228e-07  1.102451e-07
[30,]  8.963849e-11  5.551115e-11
[31,]  1.412868e-14  0.000000e+00
[32,]  4.211748e-19  0.000000e+00
[33,]  2.302143e-24  0.000000e+00
[34,]  2.221006e-30  0.000000e+00
[35,]  3.611136e-37  0.000000e+00
[36,]  9.361002e-45  0.000000e+00
[37,]  3.620812e-53  0.000000e+00
[38,]  1.930880e-62  0.000000e+00
[39,]  1.291557e-72  0.000000e+00
[40,]  9.672704e-84  0.000000e+00
[41,]  7.068202e-96  0.000000e+00
[42,] 4.258123e-109  0.000000e+00
[43,] 1.715125e-123  0.000000e+00
[44,] 3.541420e-139  0.000000e+00
[45,] 2.652905e-156  0.000000e+00
[46,] 4.524708e-175  0.000000e+00
[47,] 9.091233e-196  0.000000e+00
[48,] 7.918313e-219  0.000000e+00
[49,] 5.483576e-245  0.000000e+00
[50,] 8.301217e-276  0.000000e+00
[51,] 9.881313e-318  0.000000e+00

cbinom documentation built on April 28, 2021, 5:09 p.m.