Hypergeometric
The Hypergeometric Distribution

Description

Calculates density, cumulative probability, quantile, and generate random sample for the hypergeometric distribution (discrete).

Usage

dhyper(x, m, n, k, log = FALSE) # density
phyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE) # probability
qhyper(p, m, n, k, lower.tail = TRUE, log.p = FALSE) # quantile
rhyper(nn, m, n, k) # random

Arguments

x, q numeric vectors in the range {max(0, k-n), min(m, k)} that specify the quantiles.
p a numeric vector in the range [0, 1] that specifies the probabilities.
nn an integer value in the range [0, Inf) that specifies the number of random samples requested. If the input value is not an integer, it is truncated. If length(nn) is greater than 1, the random function returns length(nn) random samples.
m an integer value in the range [0, Inf) that specifies the number of red balls in the urn. See Background section for details.
n an integer value in the range [0, Inf) that specifies the number of black balls in the urn. See Background section for details.
k an integer value in the range [0, m+n] that specifies the number of balls drawn, without replacement, from the urn with m red and n black balls. See Background section for details.
log a logical value. If FALSE (default), the density function returns the density itself. If TRUE, it returns the log of the density.
lower.tail a logical value. If TRUE (default), the probability supplied to the quantile function or returned by the probability function is P[X <= x]. If FALSE, it is P[X > x].
log.p a logical value. If FALSE (default), the probability supplied to the quantile function or returned by the probability function is the probability itself. If TRUE, it is the log of the probability.

Details

The distribution parameter(s) are replicated cyclically to be the same length as the input x, q, p, or the number of random samples requested.
Missing values (NAs) in the input or the distribution parameter(s) will cause the corresponding elements of the result to be missing.
Value
returns density (dhyper), cumulative probability (phyper), quantile (qhyper), or random sample (rhyper) for the hypergeometric distribution with parameters m, n, and k. The quantile is defined as the smallest value q such that Pr(hypergeometric random variate <= q) >= p.
Side Effects
If the .Random.seed dataset exists, the random sample function updates its value. The random sample function creates the .Random.seed dataset if it does not exist.
Background
The hypergeometric distribution is the discrete probability distribution of the number of red balls in a sequence of k draws without replacement from an urn with m red balls and n black balls. It has support on the integer set {max(0, k-n), min(m, k)}
Differences between TIBCO Enterprise Runtime for R and Open-source R
References
Hoel, P., Port, S. and Stone, C. (1971). Introduction to Probability Theory. Houghton-Mifflin, Boston, MA.
Johnson, N. L. and Kotz, S. (1970). Discrete Univariate Distributions, vol. 2.. Houghton-Mifflin, Boston, MA.
See Also
set.seed, Binomial
Examples
cumsum(dhyper(0:5,4,6,7))   # cumulative distribution function 
phyper(0:5,4,6,7)           # same thing
phyper(0:5,7,3,4)           # same thing, by symmetry of rows and columns 
rhyper(10,4,6,7)            # 10 random values
dhyper(rep(3,3), m=c(5,8,12), n=4, k=4) 
Package stats version 6.0.0-69
Package Index