phyperR | R Documentation |
An R version of the first phyper()
algorithm in R, which was
used up to svn rev 30227
on 2004-07-09.
phyperR(q, m, n, k, lower.tail=TRUE, log.p=FALSE)
q |
vector of quantiles representing the number of white balls drawn without replacement from an urn which contains both black and white balls. |
m |
the number of white balls in the urn. |
n |
the number of black balls in the urn. |
k |
the number of balls drawn from the urn, hence must be in |
lower.tail |
logical; if TRUE (default), probabilities are
|
log.p |
logical; if TRUE, probabilities p are given as log(p). |
a numeric vector similar to phyper(q, m, n, k)
.
The original argument list in C
was (x, NR, NB, n)
where
there were red and black balls in the urn.
Note that we have vectorized a translation to R of the original C code.
Martin Maechler
phyper
and our phyperR2()
for the pure R
version of the newer (Welinder) phyper()
algorithm
m <- 9:12; n <- 7:10; k <- 10
x <- 0:(k+1) # length 12
## confirmation that recycling + lower.tail, log.p now work:
for(lg in c(FALSE,TRUE))
for(lt in c(FALSE, TRUE)) {
cat("(lower.tail = ", lt, " -- log = ", lg,"):\n", sep="")
withAutoprint({
(rr <-
cbind(x, m, n, k, # recycling (to 12 rows)
ph = phyper (x, m, n, k, lower.tail=lt, log.p=lg),
phR = phyperR(x, m, n, k, lower.tail=lt, log.p=lg)))
all.equal(rr[,"ph"], rr[,"phR"], tol = 0)
## saw 4.706e-15 1.742e-15 7.002e-12 1.086e-15 [x86_64 Lnx]
stopifnot(all.equal(rr[,"ph"], rr[,"phR"],
tol = if(lg && !lt) 2e-11 else 2e-14))
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.