Commit 4a32fe95 authored by Martin Maechler's avatar Martin Maechler
Browse files

new dbinomQ() {+ outline for *unfinished* pbinomQ()}

parent f094016b
2021-03-29 Martin Maechler <maechler@stat.math.ethz.ch>
* R/Stirling-n-etc.R (dbinomQ): new; providing *exact* binomial
probabilities.
* DESCRIPTION (Version): 0.6-3 (not yet released)
2021-01-07 Martin Maechler <maechler@stat.math.ethz.ch>
* configure.ac: add definitions of CFLAGS etc as from R,
from a suggestion by Kaspar Daniel Hansen.
* DESCRIPTION (Version) : 0.6-2, released to CRAN
2020-07-30 Martin Maechler <maechler@stat.math.ethz.ch>
......
Package: gmp
Version: 0.6-2
Date: 2021-01-07
Version: 0.6-3
Date: 2021-03-29
Title: Multiple Precision Arithmetic
Author: Antoine Lucas, Immanuel Scholz, Rainer Boehme <rb-gmp@reflex-studio.de>,
Sylvain Jasson <Sylvain.Jasson@inrae.fr>,
......
......@@ -24,6 +24,8 @@ export(
"denominator", "denominator<-",
## "dim<-.bigq", "dim.bigq", "dim<-.bigz", "dim.bigz",
"div.bigq", "div.bigz", "divq.bigz",
dbinomQ, # dbinom() with exact rationals
## TODO: pbinomQ,
BernoulliQ, # Rmpfr has 'Bernoulli'; want different name
"Eulerian", "Eulerian.all",
"Stirling1", "Stirling1.all", "Stirling2", "Stirling2.all",
......
......@@ -259,3 +259,32 @@ BernoulliQ <- function(n, verbose = getOption("verbose", FALSE)) {
else
.Call(bigrational_c, lapply(n, B1))
}
## rational dbinom() probabilities
dbinomQ <- function(x, size, prob, log=FALSE) {
if(log) stop("'log=TRUE' not allowed; use log(mpfr(dbinomQ(..), precB))")
if(!is.bigq(prob)) {
warning("Calling 'as.bigq(prob)'; rather provide exact bigrational yourself")
prob <- as.bigq(prob)
}
if(!is.bigz(x)) x <- as.bigz(x)
if(!is.bigz(size)) size <- as.bigz(size)
chooseZ(size,x) * prob^x * (1 - prob)^(size - x)
}
## rational pbinom() probabilities
pbinomQ <- function(q, size, prob, lower.tail = TRUE, log.p = FALSE) {
if(log) stop("'log.p=TRUE' not allowed; use log(mpfr(pbinomQ(..), precB))")
if(!is.bigq(prob)) {
warning("Calling 'as.bigq(prob)'; rather provide exact bigrational yourself")
prob <- as.bigq(prob)
}
if(!is.bigz(q)) q <- as.bigz(q)
if(!is.bigz(size)) size <- as.bigz(size)
## FIXME need to vectorize in 'q' sum(dbinomZ(....))
.NotYetImplemented()
## FIXME 2
if(!lower.tail) .NotYetImplemented()
chooseZ(size,q) * prob^q * (1 - prob)^(size - q)
}
\name{binomQ}
\title{Exact Rational Binomial Probabilities}
\alias{dbinomQ}
%NOT YET \alias{pbinomQ}
\description{
Compute \emph{exact} binomial probabilities using (big integer and) big
rational arithmetic.
}
\usage{
dbinomQ(x, size, prob, log = FALSE)
}
%% pbinomQ(q, size, prob, lower.tail = TRUE, log.p = FALSE)
%
\arguments{
\item{x, size}{integer or big integer (\code{"\link{bigz}"}), will be
passed to \code{\link{chooseZ}()}.}
\item{prob}{the probability; should be big rational
(\code{"\link{bigq}"}); if not it is coerced with a warning.}
\item{log}{logical; must be \code{FALSE} on purpose.}
}
\value{a big rational (\code{"\link{bigq}"}) of the \code{\link{length}} of
(recycled) \code{x+size+prob}.
}
\author{Martin Maechler}
\seealso{
\code{\link{chooseZ}}; \R's (\pkg{stats} package) \code{\link{dbinom}()}.
}
%% \examples{
%% TODO
%% }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment