UNU.RAN random variate generator for the Hypergeometric distribution. It also allows sampling from the truncated distribution.
[Special Generator] -- Sampling Function: Hypergeometric.
urhyper(nn, m, n, k, lb=max(0,k-n), ub=min(k,m))
number of observations.
the number of white balls in the urn.
the number of black balls in the urn.
the number of balls drawn from the urn.
lower bound of (truncated) distribution.
upper bound of (truncated) distribution.
Josef Leydold and Wolfgang H\"ormann unuran@statmath.wu.ac.at.
The Hypergeometric distribution is used for sampling without
replacement. The density of this distribution with parameters
m
, n
and k
(named \(Np\), \(N-Np\), and
\(n\), respectively in the reference below) is given by
$$
p(x) = \left. {m \choose x}{n \choose k-x} \right/ {m+n \choose k}
$$
for \(x = 0, \ldots, k\).
The generation algorithm uses guide table based inversion. The parameters
lb
and ub
can be used to generate variates from
the Hypergeometric distribution truncated to the interval (lb
,ub
).
W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg
runif
and .Random.seed
about random number
generation, unuran
for the UNU.RAN class, and
rhyper
for the R built-in generator.
## Create a sample of size 1000
x <- urhyper(nn=20,m=15,n=5,k=7)
Run the code above in your browser using DataLab