Title: | Clopper-Pearson Confidence Interval and Generalized Binomial Distribution |
---|---|
Description: | Density, distribution function, quantile function and random generation for the Generalized Binomial Distribution. Functions to compute the Clopper-Pearson Confidence Interval and the required sample size. Enhanced model for burn-in studies, where failures are tackled by countermeasures. |
Authors: | Horst Lewitschnig, David Lenzi |
Maintainer: | Horst Lewitschnig <[email protected]> |
License: | GPL-3 |
Version: | 1.2.1 |
Built: | 2024-11-26 06:44:40 UTC |
Source: | CRAN |
Density, distribution function, quantile function, and random generation for the Generalized Binomial Distribution. Also included are functions to compute the Clopper-Pearson confidence interval limits for the standard case, for an enhanced model, and the required sample size for a given target probability for both models.
This package originates from semiconductor manufacturing but can also be used for other purposes. The functions are based on the paper Decision-Theoretical Model for Failures which are Tackled by Countermeasures, Kurz et al. (2014).
The generalized binomial distribution is defined as the sum of independent, not identically binomial distributed random variables. That means, they have different success probabilities, and they can have different sample sizes.
Example: A person has to drive routes at each working day. The probabilities for a radar control on these routes are
for the first route,
for the second route and
for the third route. The person has to drive route
and route
one time per day and route
two times per day. What are the probabilities to have
more than
controls at
working days?
Knowing that the number of controls is binomially distributed for each route: ~
,
~
,
~
Thus the sum of these binomially distributed random variables has a generalized binomial distribution with parameters .
,
~
In this example the probabilities ,
,
,
can be computed straightforward.
See the examples for the results.
Consider now a burn-in study in which failures are observed. The number of failures is binomially distributed. Thus, the Clopper-Pearson confidence interval limits can be used to obtain a confidence interval for the failure probability.
If failures occur, countermeasures should be implemented with a type specific effectivity. Consider the case of different failure types. That leads to more than one countermeasure. Each countermeasure can have a different effectivity. The probability for solving a certain number of failures can be computed with the generalized binomial distribution. It gives the likelihoods for various possible outcome scenarios, if the countermeasures would have been introduced from the beginning on. Based on the model in Kurz et al. (2014), confidence intervals can be computed.
The generalized binomial distribution described here is also known as Poisson-binomial distribution.
Horst Lewitschnig, David Lenzi.
Maintainer: Horst Lewitschnig <[email protected]>
D.Kurz, H.Lewitschnig, J.Pilz, Decision-Theoretical Model for Failures which are Tackled by Countermeasures, IEEE Transactions on Reliability, Vol. 63, No. 2, June 2014.
K.J. Klauer, Kriteriumsorientierte Tests, Verlag fuer Psychologie, Hogrefe, 1987, Goettingen, p. 208 ff.
M.Fisz, Wahrscheinlichkeitsrechnung und mathematische Statistik, VEB Deutscher Verlag der Wissenschaften, 1973, p. 164 ff.
C.J.Clopper and E.S. Pearson, The use of confidence or fiducial limits illustrated in the case of the binomial, Biometrika, vol. 26, 404-413, 1934.
## n1=100, n2=100, n3=200, p1=0.001, p2=0.005, p3=0.01 dgbinom(c(0:2),size=c(100,100,200),prob=c(0.001,0.005,0.01)) # 0.07343377 0.19260317 0.25173556 pgbinom(2,size=c(100,100,200),prob=c(0.001,0.005,0.01),lower.tail=FALSE) # 0.4822275 ## n=110000 tested devices, 2 failures divided in 2 failure types k1=1, k2=1. ## 2 countermeasures with effectivities p1=0.5, p2=0.8 cm.clopper.pearson.ci(110000,size=c(1,1), cm.effect=c(0.5,0.8)) # Confidence.Interval = upper # Lower.limit = 0 # Upper.limit = 3.32087e-05 # alpha = 0.1 ## target failure probability p=0.00001, 2 failures divided in 2 failure types k1=1, k2=1. ## 2 countermeasures with effectivities p1=0.5, p2=0.8 cm.n.clopper.pearson(0.00001,size=c(1,1), cm.effect=c(0.5,0.8)) # 365299
## n1=100, n2=100, n3=200, p1=0.001, p2=0.005, p3=0.01 dgbinom(c(0:2),size=c(100,100,200),prob=c(0.001,0.005,0.01)) # 0.07343377 0.19260317 0.25173556 pgbinom(2,size=c(100,100,200),prob=c(0.001,0.005,0.01),lower.tail=FALSE) # 0.4822275 ## n=110000 tested devices, 2 failures divided in 2 failure types k1=1, k2=1. ## 2 countermeasures with effectivities p1=0.5, p2=0.8 cm.clopper.pearson.ci(110000,size=c(1,1), cm.effect=c(0.5,0.8)) # Confidence.Interval = upper # Lower.limit = 0 # Upper.limit = 3.32087e-05 # alpha = 0.1 ## target failure probability p=0.00001, 2 failures divided in 2 failure types k1=1, k2=1. ## 2 countermeasures with effectivities p1=0.5, p2=0.8 cm.n.clopper.pearson(0.00001,size=c(1,1), cm.effect=c(0.5,0.8)) # 365299
Computing upper, lower or two-sided Clopper-Pearson confidence limits for a given confidence level.
clopper.pearson.ci(k, n, alpha = 0.1, CI = "upper")
clopper.pearson.ci(k, n, alpha = 0.1, CI = "upper")
k |
number of failures/successes. |
n |
number of trials. |
alpha |
significance level for the |
CI |
indicates the kind of the confidence interval, options: "upper" (default), "lower", "two.sided". |
Computes the confidence limits for the of a binomial distribution.
Confidence intervals are obtained by the definition of Clopper and Pearson.
The two-sided interval for
is
, for
it is
.
A data frame containing the kind of the confidence interval, upper and lower limits and the used significance level alpha
.
D.Kurz, H.Lewitschnig, J.Pilz, Decision-Theoretical Model for Failures which are Tackled by Countermeasures, IEEE Transactions on Reliability, Vol. 63, No. 2, June 2014.
Thulin, Mans, The cost of using exact confidence intervals for a binomial proportion, Electronic Journal of Statistics, vol. 8, pp. 817-840, 2014.
C.J.Clopper and E.S. Pearson, The use of confidence or fiducial limits illustrated in the case of the binomial, Biometrika, vol. 26, pp. 404-413, 1934.
clopper.pearson.ci(5,100000,alpha=0.05) # Confidence.Interval = upper # Lower.limit = 0 # Upper.limit = 0.0001051275 # alpha = 0.05 clopper.pearson.ci(5,100000,CI="two.sided") # Confidence.Interval = two.sided # Lower.limit = 1.97017e-05 # Upper.limit = 0.0001051275 # alpha = 0.1
clopper.pearson.ci(5,100000,alpha=0.05) # Confidence.Interval = upper # Lower.limit = 0 # Upper.limit = 0.0001051275 # alpha = 0.05 clopper.pearson.ci(5,100000,CI="two.sided") # Confidence.Interval = two.sided # Lower.limit = 1.97017e-05 # Upper.limit = 0.0001051275 # alpha = 0.1
Provides the extended Clopper-Pearson confidence limits for a failure model, where countermeasures are introduced.
cm.clopper.pearson.ci(n, size, cm.effect, alpha = 0.1, CI = "upper", uniroot.lower = 0, uniroot.upper = 1, uniroot.maxiter = 1e+05, uniroot.tol = 1e-10)
cm.clopper.pearson.ci(n, size, cm.effect, alpha = 0.1, CI = "upper", uniroot.lower = 0, uniroot.upper = 1, uniroot.maxiter = 1e+05, uniroot.tol = 1e-10)
n |
sample size. |
size |
vector of the number of failures for each type. |
cm.effect |
vector of the success probabilities to solve a failure for each type. Corresponds to the probabilities |
alpha |
significance level for the |
CI |
indicates the kind of the confidence interval, options: "upper" (default), "lower", "two.sided". |
uniroot.lower |
The value of the |
uniroot.upper |
The value of the |
uniroot.maxiter |
The value of the |
uniroot.tol |
The value of the |
This is an extension of the Clopper-Pearson confidence interval, where different outcome scenarios of the random sampling are weighted by generalized binomial probabilities. The weights are the probabilities for observing failures after the introduction of countermeasures.
Computes the confidence limits for the
of a binomial distribution, where
is the failure probability. The failures are tackled by countermeasures for specific failure types with different effectivity.
See the references for further information.
A data frame containing the kind of the confidence interval, upper and lower limits and the used significance level alpha
.
D.Kurz, H.Lewitschnig, J.Pilz, Decision-Theoretical Model for Failures which are Tackled by Countermeasures, IEEE Transactions on Reliability, Vol. 63, No. 2, June 2014.
uniroot
, dgbinom
, clopper.pearson.ci
## n=110000 tested devices, 2 failures divided in 2 failure types k1=1, k2=1. ## 2 countermeasures with effectivities p1=0.5, p2=0.8 cm.clopper.pearson.ci(110000,size=c(1,1),cm.effect=c(0.5,0.8)) # Confidence.Interval = upper # Lower.limit = 0 # Upper.limit = 3.32087e-05 # alpha = 0.1
## n=110000 tested devices, 2 failures divided in 2 failure types k1=1, k2=1. ## 2 countermeasures with effectivities p1=0.5, p2=0.8 cm.clopper.pearson.ci(110000,size=c(1,1),cm.effect=c(0.5,0.8)) # Confidence.Interval = upper # Lower.limit = 0 # Upper.limit = 3.32087e-05 # alpha = 0.1
Provides the required sample size with respect to the extended upper Clopper-Pearson limit for a failure model, where countermeasures are introduced.
cm.n.clopper.pearson(p, size, cm.effect, alpha = 0.1, uniroot.lower = k + 1, uniroot.upper = 1e+100, uniroot.tol = 1e-10, uniroot.maxiter = 1e+05)
cm.n.clopper.pearson(p, size, cm.effect, alpha = 0.1, uniroot.lower = k + 1, uniroot.upper = 1e+100, uniroot.tol = 1e-10, uniroot.maxiter = 1e+05)
p |
target probability. |
size |
vector of the number of failures for each type. |
cm.effect |
vector of the success probabilities to solve a failure for each type. Corresponds to the probabilities |
alpha |
significance level for the |
uniroot.lower |
The value of the |
uniroot.upper |
The value of the |
uniroot.maxiter |
The value of the |
uniroot.tol |
The value of the |
Provides the required sample size with respect to the extended upper Clopper-Pearson limit. It applies for the case that failures are tackled by countermeasures. That means countermeasures with different effectivities for each failure type are introduced. See the references for further information.
The value for the required sample size.
D.Kurz, H.Lewitschnig, J.Pilz, Decision-Theoretical Model for Failures which are Tackled by Countermeasures, IEEE Transactions on Reliability, Vol. 63, No. 2, June 2014.
uniroot
,dgbinom
,cm.clopper.pearson.ci
,n.clopper.pearson
## target failure probability p=0.00001, 2 failures divided in 2 failure types k1=1, k2=1. ## 2 countermeasures with effectivities p1=0.5, p2=0.8 cm.n.clopper.pearson(0.00001,size=c(1,1),cm.effect=c(0.5,0.8)) # 365299
## target failure probability p=0.00001, 2 failures divided in 2 failure types k1=1, k2=1. ## 2 countermeasures with effectivities p1=0.5, p2=0.8 cm.n.clopper.pearson(0.00001,size=c(1,1),cm.effect=c(0.5,0.8)) # 365299
Density, distribution function, quantile function and random generation for the generalized binomial distribution with parameter vectors size
and prob
.
dgbinom(x, size, prob, log = FALSE) pgbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE) qgbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE) rgbinom(N, size, prob)
dgbinom(x, size, prob, log = FALSE) pgbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE) qgbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE) rgbinom(N, size, prob)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
N |
number of observations. |
size |
vector of the number of trials for each type. |
prob |
vector of the success probabilities for each type. |
log , log.p
|
logical; if TRUE probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are |
The generalized binomial distribution with size
= and
prob
= is the sum of
binomially distributed random variables with different
(and, in case, with different
):
Z=,
~
(
size
,prob
), with ~
.
Since the sum of Bernoulli distributed random variables is binomially distributed, can be also defined as:
Z=, with
~
.
The pmf is obtained by an algorithm which is based on the convolution of Bernoulli distributions. See the references below for further information.
The quantile is defined as the smallest value such that
, where F is the cumulative distribution function.
rgbinom
uses the inversion method (see Devroye, 1986).
dgbinom
gives the pmf, pgbinom
gives the cdf, qgbinom
gives the quantile function and rgbinom
generates random deviates.
If size
contains just one trial number and prob
one success probability, then the generalized binomial distribution results in the binomial distribution.
The generalized binomial distribution described here is also known as Poisson-binomial distribution. See the link below to the package poibin
for further information.
D.Kurz, H.Lewitschnig, J.Pilz, Decision-Theoretical Model for Failures which are Tackled by Countermeasures, IEEE Transactions on Reliability, Vol. 63, No. 2, June 2014.
K.J. Klauer, Kriteriumsorientierte Tests, Verlag fuer Psychologie, Hogrefe, 1987, Goettingen, p. 208 ff.
M.Fisz, Wahrscheinlichkeitsrechnung und mathematische Statistik, VEB Deutscher Verlag der Wissenschaften, 1973, p. 164 ff.
L.Devroye, Non-Uniform Random Variate Generation, Springer-Verlag, 1986, p. 85 ff.
ppoibin
, for another implementation of this distribution. dbinom
## n=10 defect devices, divided in 3 failure types n1=2, n2=5, n3=3. ## 3 countermeasures with effectivities p1=0.8, p2=0.7, p3=0.3 are available. ## use dgbinom() to get the probabilities for x=0,...,10 failures solved. dgbinom(x=c(0:10),size=c(2,5,3),prob=c(0.8,0.7,0.3)) ## generation of N=100000 random values rgbinom(100000,size=c(2,5,3),prob=c(0.8,0.7,0.3)) ## n1=100, n2=100, n3=200, p1=0.001, p2=0.005, p3=0.01 dgbinom(c(0:2),size=c(100,100,200),prob=c(0.001,0.005,0.01)) # 0.07343377 0.19260317 0.25173556 pgbinom(2,size=c(100,100,200),prob=c(0.001,0.005,0.01),lower.tail=FALSE) # 0.4822275
## n=10 defect devices, divided in 3 failure types n1=2, n2=5, n3=3. ## 3 countermeasures with effectivities p1=0.8, p2=0.7, p3=0.3 are available. ## use dgbinom() to get the probabilities for x=0,...,10 failures solved. dgbinom(x=c(0:10),size=c(2,5,3),prob=c(0.8,0.7,0.3)) ## generation of N=100000 random values rgbinom(100000,size=c(2,5,3),prob=c(0.8,0.7,0.3)) ## n1=100, n2=100, n3=200, p1=0.001, p2=0.005, p3=0.01 dgbinom(c(0:2),size=c(100,100,200),prob=c(0.001,0.005,0.01)) # 0.07343377 0.19260317 0.25173556 pgbinom(2,size=c(100,100,200),prob=c(0.001,0.005,0.01),lower.tail=FALSE) # 0.4822275
Provides the required sample size with respect to the one-sided upper Clopper-Pearson limit.
n.clopper.pearson(k, p, alpha = 0.1, uniroot.lower = k + 1, uniroot.upper = 1e+100, uniroot.maxiter = 1e+05, uniroot.tol = 1e-10)
n.clopper.pearson(k, p, alpha = 0.1, uniroot.lower = k + 1, uniroot.upper = 1e+100, uniroot.maxiter = 1e+05, uniroot.tol = 1e-10)
k |
number of failures. |
p |
target probability. |
alpha |
significance level for the |
uniroot.lower |
The value of the |
uniroot.upper |
The value of the |
uniroot.maxiter |
The value of the |
uniroot.tol |
The value of the |
Provides the required sample size with respect to the upper Clopper-Pearson limit for a given target failure probability at a certain confidence level.
The value for the required sample size.
D.Kurz, H.Lewitschnig, J.Pilz, Decision-Theoretical Model for Failures which are Tackled by Countermeasures, IEEE Transactions on Reliability, Vol. 63, No. 2, June 2014.
## target failure probability p=0.0002, 8 failures n.clopper.pearson(8,0.0002) # 64972
## target failure probability p=0.0002, 8 failures n.clopper.pearson(8,0.0002) # 64972