qbinomR {DPQ} | R Documentation |
Pure R Implementation of R's qbinom() with Tuning Parameters
Description
A pure R implementation, including many tuning parameter arguments, of R's own Rmathlib C code algorithm, but with more flexibility.
It is using Vectorize(qbinomR1, *)
where the hidden
qbinomR1
works for numbers (aka ‘scalar’, length one)
arguments only, the same as the C code.
Usage
qbinomR(p, size, prob, lower.tail = TRUE, log.p = FALSE,
yLarge = 4096, # was hard wired to 1e5
incF = 1/64, # was hard wired to .001
iShrink = 8, # was hard wired to 100
relTol = 1e-15,# was hard wired to 1e-15
pfEps.n = 8, # was hard wired to 64: "fuzz to ensure left continuity"
pfEps.L = 2, # was hard wired to 64: " " ..
fpf = 4, # *MUST* be >= 1 (did not exist previously)
trace = 0)
Arguments
p , size , prob , lower.tail , log.p |
|
yLarge |
when |
incF |
a positive “increment factor” (originally hardwired to
0.001), used only when |
iShrink |
a positive increment shrinking factor, used only when
|
relTol |
relative tolerance, |
pfEps.n |
fuzz factor to ensure left continuity in the normal
case |
pfEps.L |
fuzz factor to ensure left continuity in case
|
fpf |
factor |
trace |
logical (or integer) specifying if (and how much) output should be produced from the algorithm. |
Details
as mentioned on qbinom
help page,
qbinom
uses the Cornish–Fisher Expansion to include a skewness
correction to a normal approximation, thus defining y := Fn(p, size, prob, ..)
.
The following (root finding) binary search is tweaked by the
yLarge, ..., fpf
arguments.
Value
a numeric vector like p
recycled to the common lengths of
p
, size
, and prob
.
Author(s)
Martin Maechler
See Also
Examples
set.seed(12)
pr <- (0:16)/16 # supposedly recycled
x10 <- rbinom(500, prob=pr, size = 10); p10 <- pbinom(x10, prob=pr, size= 10)
x1c <- rbinom(500, prob=pr, size = 100); p1c <- pbinom(x1c, prob=pr, size=100)
## stopifnot(exprs = {
table( x10 == (qp10 <- qbinom (p10, prob=pr, size= 10) ))
table( qp10 == (qp10R <- qbinomR(p10, prob=pr, size= 10) )); summary(warnings()) # 30 x NaN
table( x1c == (qp1c <- qbinom (p1c, prob=pr, size=100) ))
table( qp1c == (qp1cR <- qbinomR(p1c, prob=pr, size=100) )); summary(warnings()) # 30 x NaN
## })