Description Usage Arguments Details Value Note Author(s) References See Also Examples
The mass and distribution functions of the sum of k independent binomial random variables, with possibly different probabilities.
1 2 3 4 |
x |
Vector of values at which to evaluate the mass function of the sum of the k binomial variates |
size |
Vector of the number of trials |
prob |
Vector of the probabilities of success |
log, log.p |
logical; if TRUE, probabilities p are given as log(p) (see Note). |
verbose |
|
method |
A character string that uniquely indicates the method. |
q |
Vector of quantiles (value at which to evaluate the distribution function) of the sum of the k binomial variates |
size[1]
and prob[1]
are the size and probability of the first
binomial variate, size[2]
and prob[2]
are the size and
probability of the second binomial variate, etc.
If the elements of prob
are all the same, then pbinom
or
dbinom
is used. Otherwise, repeating convolutions of the k
binomials are used to calculate the mass or the distribution functions.
dkbinom
gives the mass function, pkbinom
gives the
distribution function.
When log.p
or log
is TRUE
, these functions do
not have the same precision as dbinom
or pbinom
when the
probabilities are very small, i.e, the values tend to go to -Inf
more quickly.
Landon Sego and Alex Venzin
The Butler method is based on the exact algorithm discussed by: Butler, Ken and Stephens, Michael. (1993) The Distribution of a Sum of Binomial Random Variables. Technical Report No. 467, Department of Statistics, Stanford University. http://www.dtic.mil/dtic/tr/fulltext/u2/a266969.pdf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # A sum of 3 binomials...
dkbinom(c(0, 4, 7), c(3, 4, 2), c(0.3, 0.5, 0.8))
dkbinom(c(0, 4, 7), c(3, 4, 2), c(0.3, 0.5, 0.8), method = "b")
pkbinom(c(0, 4, 7), c(3, 4, 2), c(0.3, 0.5, 0.8))
pkbinom(c(0, 4, 7), c(3, 4, 2), c(0.3, 0.5, 0.8), method = "b")
# Compare the output of the 3 methods
pkbinom(4, c(3, 4, 2), c(0.3, 0.5, 0.8), method = "fft")
pkbinom(4, c(3, 4, 2), c(0.3, 0.5, 0.8), method = "butler")
pkbinom(4, c(3, 4, 2), c(0.3, 0.5, 0.8), method = "naive")
# Some inputs
n <- c(30000, 40000, 20000)
p <- c(0.02, 0.01, 0.005)
# Compare timings
x1 <- timeIt(pkbinom(1100, n, p, method = "butler"))
x2 <- timeIt(pkbinom(1100, n, p, method = "naive"))
x3 <- timeIt(pkbinom(1100, n, p, method = "fft"))
pvar(x1, x1 - x2, x2 - x3, x1 - x3, digits = 12)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.