urhyper {Runuran} | R Documentation |
UNU.RAN Hypergeometric random variate generator
Description
UNU.RAN random variate generator for the Hypergeometric distribution. It also allows sampling from the truncated distribution.
[Special Generator] – Sampling Function: Hypergeometric.
Usage
urhyper(nn, m, n, k, lb=max(0,k-n), ub=min(k,m))
Arguments
nn |
number of observations. |
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. |
lb |
lower bound of (truncated) distribution. |
ub |
upper bound of (truncated) distribution. |
Details
The Hypergeometric distribution is used for sampling without
replacement. The density of this distribution with parameters
m
, n
and k
(named ,
, and
, respectively in the reference below) is given by
for .
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
).
Note
This function is a wrapper for the UNU.RAN class in R.
Compared to rhyper
, urhyper
is faster, especially for
larger sample sizes.
However, in opposition to rhyper
vector arguments are ignored,
i.e. only the first entry is used.
Author(s)
Josef Leydold and Wolfgang H\"ormann unuran@statmath.wu.ac.at.
References
W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg
See Also
runif
and .Random.seed
about random number
generation, unuran
for the UNU.RAN class, and
rhyper
for the R built-in generator.
Examples
## Create a sample of size 1000
x <- urhyper(nn=20,m=15,n=5,k=7)