Skip to content

Commit

Permalink
version 1.0-5
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Klaschka authored and gaborcsardi committed Aug 20, 2015
1 parent af0f2bb commit d46d120
Show file tree
Hide file tree
Showing 13 changed files with 530 additions and 57 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2015-08-20 1.0-5 - So called Vos-Hudson adjustment implemented.
- DESCRIPTION corrected.
- Imports from stats added to NAMESPACE.
- Documentation edited.

2014-05-07 1.0-4 Algorithms improved:
- An incorrect (and, fortunately, almost never used) branch
removed from binom.blaker.lower.limit.R.
Expand Down
16 changes: 7 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
Package: BlakerCI
Type: Package
Title: Blaker's binomial confidence limits
Version: 1.0-4
Date: 2014-05-07
Title: Blaker's Binomial Confidence Limits
Version: 1.0-5
Date: 2015-08-20
Author: Jan Klaschka
Maintainer: Jan Klaschka <klaschka@cs.cas.cz>
Description: Fast and accurate calculation of
Blaker's binomial confidence limits
(and some related stuff)
License: GPL-2
Description: Fast and accurate calculation of Blaker's binomial confidence limits (and some related stuff).
License: GPL-3
LazyLoad: yes
Packaged: 2014-05-06 19:54:43 UTC; klaschka
NeedsCompilation: no
Packaged: 2015-08-20 15:45:10 UTC; klaschka
Repository: CRAN
Date/Publication: 2014-05-07 23:35:18
Date/Publication: 2015-08-20 19:52:46
19 changes: 12 additions & 7 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
eeeb878922147817fc8fd6028f2cf6f9 *ChangeLog
a73e4e800296623ff377abfd0438bcba *DESCRIPTION
76b309ced09fde087399bf426fe6bbaa *NAMESPACE
9677a0469d8f43c4c0bda58d24473b77 *ChangeLog
aeff792d2d47edf07c21f9f1f67a3a86 *DESCRIPTION
622d97f1a2f90799930a4cd04c5a3258 *NAMESPACE
8f41fbda3173ebf87f028f2479cbd70b *R/binom.blaker.VHadj.acc.R
7bd74de7a2337bd2e96a08a9ba3f7c94 *R/binom.blaker.VHadj.limits.R
b81d0a0e4af032ee3c7a781fcce33e29 *R/binom.blaker.VHadj.lower.limit.R
38f9b537d00dba55ae6a2717721bdbdd *R/binom.blaker.acc.R
e31a8b5ad8ee890e82fa31bc5777b9f4 *R/binom.blaker.acc.single.p.R
cfa0c40d1cbd95045c3400212df7a4d6 *R/binom.blaker.limits.R
83a0de528aa33eb2acae2965b561638b *R/binom.blaker.lower.limit.R
afd954c6de1e31cad77d458048675f81 *man/BlakerCI-internal.Rd
f9d6fb28066f558da9f6a32c779c3e29 *man/BlakerCI-package.Rd
ed48c280ca2556fcbb9e607e263c0985 *man/binom.blaker.acc.Rd
db02a5c5631ff08520055cf56e1dfd95 *man/binom.blaker.limits.Rd
f65871c4eefefd0a087c3baed147f43d *man/BlakerCI-internal.Rd
dc046f448f61ede62eb7e81f31ac9965 *man/BlakerCI-package.Rd
c7739d5ea97fd342138aa25528d5dc4f *man/binom.blaker.VHadj.acc.Rd
158ec2cc80c7eccf4fb4209e7726b8a2 *man/binom.blaker.VHadj.limits.Rd
f1a7c77709703911bc5b6306381576d0 *man/binom.blaker.acc.Rd
0b2164dd6cd538fc2278ca83bb9ce32f *man/binom.blaker.limits.Rd
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export(binom.blaker.lower.limit,binom.blaker.limits,binom.blaker.acc.single.p,binom.blaker.acc)
importFrom("stats", "pbinom", "qbinom", "qbeta", "pbeta")
export(binom.blaker.lower.limit,binom.blaker.limits,binom.blaker.acc.single.p,binom.blaker.acc,
binom.blaker.VHadj.lower.limit,binom.blaker.VHadj.limits,binom.blaker.VHadj.acc)
42 changes: 42 additions & 0 deletions R/binom.blaker.VHadj.acc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
binom.blaker.VHadj.acc <- function(x,n,p,type=c("orig","unimod"),acc.tol=1e-10,nmax=n+1000,int.eps=1e-12,...) {
if (n < 1 || x < 0 || x > n) stop("Parameters n = ",n,", x = ",x, " wrong!")
if (acc.tol <= 0) stop("Numerical tolerance ",acc.tol," nonpositive!")
type <- match.arg(type)
if (type != "orig" && type != "unimod") stop("Unknown type ",type,"!")
m <- length(p)
if (m < 1) stop("Empty vector p!")
acc <- binom.blaker.acc(x,n,p,type=type,acc.tol=acc.tol,...=...)
nn <- n+1
ind.susp <- 1:length(p)
ind.susp1 <- ind.susp[p[ind.susp] <= x/n]
ind.susp2 <- ind.susp[p[ind.susp] > x/n]
repeat {
if (nn > nmax) {
warning("n = ", n, ", x = ", x,": Upper limit of ", nmax,
" too low, Vos-Hudson adjustment may be incomplete.")
break
}
xx <- x*nn/n
aa1 <- pmin(2*pbeta(p[ind.susp1],xx,nn-xx+1),1)
aa2 <- pmin(2*pbeta(1-p[ind.susp2],nn-xx,xx+1),1)
ind.susp1 <- ind.susp1[aa1 > acc[ind.susp1]]
ind.susp2 <- ind.susp2[aa2 > acc[ind.susp2]]
if (length(ind.susp1) + length(ind.susp2) < 1) break
acc.nn.L <- numeric(0)
acc.nn.R <- numeric(0)
if (length(ind.susp1) > 0) {
x.star <- ceiling(xx-int.eps)
acc.nn.L <- binom.blaker.acc(x.star,nn,p[ind.susp1],type=type,acc.tol=acc.tol,...=...)
}
if (length(ind.susp2) > 0) {
x.star <- floor(xx+int.eps)
acc.nn.R <- binom.blaker.acc(x.star,nn,p[ind.susp2],type=type,acc.tol=acc.tol,...=...)
}
acc.nn <- c(acc.nn.L,acc.nn.R)
ind.susp <- c(ind.susp1,ind.susp2)
acc[ind.susp] <- pmax(acc[ind.susp],acc.nn)
nn <- nn+1
}

acc
}
8 changes: 8 additions & 0 deletions R/binom.blaker.VHadj.limits.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
binom.blaker.VHadj.limits <- function(x,n,level=.95,tol=1e-10,...) {
if (n < 1 || x < 0 || x > n) stop("Parameters n = ",n,", x = ",x, " wrong!")
if (level <= 0 || level >= 1) stop("Confidence level ",level," out of (0, 1)!")
if (tol <= 0) stop("Numerical tolerance ",tol," nonpositive!")
lower <- binom.blaker.VHadj.lower.limit(x,n,level,tol,...)
upper <- 1 - binom.blaker.VHadj.lower.limit(n-x,n,level,tol,...)
return(c(lower,upper))
}
23 changes: 23 additions & 0 deletions R/binom.blaker.VHadj.lower.limit.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
binom.blaker.VHadj.lower.limit <- function(x,n,level,tol=1e-10,maxiter=100,nmax=n+1000,int.eps=1e-10) {
if (x <=0) return(0)
if (x>0) {
lower <- binom.blaker.lower.limit(x,n,level,tol,maxiter)
alpha <- 1-level
nn <- n
p <- x/n
repeat {
nn <- nn+1
xstar <- nn*p
if (qbeta(alpha/2,xstar,nn-xstar+1) > lower) break
if (nn > nmax) {
warning("n = ", n, ", x = ", x,": Upper limit of ", nmax,
" too low, Vos-Hudson adjustment may be incomplete.")
break
}
xx <- ceiling(xstar-int.eps)
ll <- binom.blaker.lower.limit(xx,nn,level,tol,maxiter)
lower <- min(lower,ll)
}
}
return(lower)
}
36 changes: 29 additions & 7 deletions man/BlakerCI-internal.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
\alias{BlakerCI-internal}
\alias{binom.blaker.lower.limit}
\alias{binom.blaker.acc.single.p}
\alias{binom.blaker.VHadj.lower.limit}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
Internal functions, not expected to be called by the user.
}
\description{
Calculation of the lower Blaker's confidence limit
(\code{binom.blaker.lower.limit})
and a single acceptability value -- unmodified or \sQuote{unimodalized}
Calculation of the lower Blaker's confidence limit
as defined by Blaker (\code{binom.blaker.lower.limit}),
or with so called Vos-Hudson adjustment (\code{binom.blaker.VHadj.lower.limit});
a single acceptability value, optionally \dQuote{unimodalized}
(\code{binom.blaker.acc.single.p}).
}
\usage{
binom.blaker.lower.limit(x, n, level, tol = 1e-10, maxiter=100)
binom.blaker.VHadj.lower.limit(x,n,level,tol=1e-10,maxiter=100,
nmax=n+1000,int.eps=1e-10)
binom.blaker.acc.single.p(x, n, p, type = "orig", acc.tol = 1e-10,
output = "acc", maxiter=100)
}
Expand All @@ -35,7 +39,8 @@ binom.blaker.acc.single.p(x, n, p, type = "orig", acc.tol = 1e-10,
point (single value between 0 and 1) where to calculate the acceptability.
}
\item{type}{
"orig", or "unimod" -- either unmodified, or unimodalized acceptability \cr
\code{"orig"}, or \code{"unimod"} -- either unmodified, or unimodalized
acceptability \cr
(see \code{\link{binom.blaker.acc}}).
}
\item{acc.tol}{
Expand All @@ -52,19 +57,35 @@ binom.blaker.acc.single.p(x, n, p, type = "orig", acc.tol = 1e-10,
Maximum number of interval halving iterations during the search
for a confidence limit (\code{binom.blaker.lower.limit}) or
a discontinuity point of the acceptability function
(\code{binom.blaker.acc.single.p} with \code{type} \code{=} \code{"unimod"}).
(\code{binom.blaker.acc.single.p} with \code{type = "unimod"}).
When the required accuracy is not reached in \code{maxiter} steps --
typically when too small \code{tol} or \code{acc.tol}
exceeds capabilities of machine arithmetic -- last step's result
is returned with warning.
}

\item{nmax}{
Pairs \code{(y, m)} of number of trials and number of successes
are allowed to contribute to the Vos-Hudson adjustment for only
\code{m} up to \code{nmax}. Warning is returned when greater
numbers of trials are suspect to have influence.
}
\item{int.eps}{
Maximum expected error of machine representation of integers
calculated via multiplication and division from reals.
(Used in order to round numbers correctly if they happen
to be integer, e. g.
\code{ceiling(xx - int.eps)} is calculated instead of
\code{ceiling(xx)}.)
}

}
%\details{
%% ~~ If necessary, more details than the description above ~~
%}
\value{
For \code{binom.blaker.lower.limit}, a single number --
For \code{binom.blaker.lower.limit} and
\code{binom.blaker.VHadj.lower.limit}, a single number --
the lower confidence limit. \cr
For \code{binom.blaker.acc.single.p} -- depending on the
\code{output} parameter -- a single acceptability value, or a single
Expand All @@ -83,7 +104,8 @@ Jan Klaschka \email{klaschka@cs.cas.cz}
%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
\code{\link{binom.blaker.limits}}, \code{\link{binom.blaker.acc}}.
\code{\link{binom.blaker.limits}}, \code{\link{binom.blaker.VHadj.limits}},\cr
\code{\link{binom.blaker.acc}}, \code{\link{binom.blaker.VHadj.acc}}.
}
%\examples{
%}
Expand Down
8 changes: 4 additions & 4 deletions man/BlakerCI-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ confidence limits.
\tabular{ll}{
Package: \tab BlakerCI\cr
Type: \tab Package\cr
Version: \tab 1.0-4\cr
Date: \tab 2014-05-07\cr
License: \tab GPL-2\cr
Version: \tab 1.0-5\cr
Date: \tab 2015-08-20\cr
License: \tab GPL-3\cr
LazyLoad: \tab yes\cr
}
}
Expand Down Expand Up @@ -55,7 +55,7 @@ Maintainer: Jan Klaschka \email{klaschka@cs.cas.cz}
\section{Acknowledgement}{
This work was accomplished with institutional support RVO:67985807.
Previous versions were supported by grant 205/09/1079 from
Versions up to 1.0-2 were supported by grant 205/09/1079 from
The Czech Science Foundation.
%
%I am grateful to Petr Savicky for a valuable e-mail
Expand Down

0 comments on commit d46d120

Please sign in to comment.