Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

HyperGeometric

Create a HyperGeometric distribution


Description

To understand the HyperGeometric distribution, consider a set of r objects, of which m are of the type I and n are of the type II. A sample with size k (k<r) with no replacement is randomly chosen. The number of observed type I elements observed in this sample is set to be our random variable X. For example, consider that in a set of 20 car parts, there are 4 that are defective (type I). If we take a sample of size 5 from those car parts, the probability of finding 2 that are defective will be given by the HyperGeometric distribution (needs double checking).

Usage

HyperGeometric(m, n, k)

Arguments

m

The number of type I elements available.

n

The number of type II elements available.

k

The size of the sample taken.

Details

We recommend reading this documentation on https://alexpghayes.github.io/distributions3, where the math will render with additional detail and much greater clarity.

In the following, let X be a HyperGeometric random variable with success probability p = p = m/(m+n).

Support: x \in { \{\max{(0, k-(n-m)}, …, \min{(k,m)}}\}

Mean: \frac{km}{n+m} = kp

Variance: \frac{km(n)(n+m-k)}{(n+m)^2 (n+m-1)} = kp(1-p)(1 - \frac{k-1}{m+n-1})

Probability mass function (p.m.f):

P(X = x) = \frac{{m \choose x}{n \choose k-x}}{{m+n \choose k}}

Cumulative distribution function (c.d.f):

P(X ≤ k) \approx Φ\Big(\frac{x - kp}{√{kp(1-p)}}\Big)

Moment generating function (m.g.f):

Not useful.

Value

A HyperGeometric object.

See Also

Examples

set.seed(27)

X <- HyperGeometric(4, 5, 8)
X

random(X, 10)

pdf(X, 2)
log_pdf(X, 2)

cdf(X, 4)
quantile(X, 0.7)

distributions3

Probability Distributions as S3 Objects

v0.1.1
MIT + file LICENSE
Authors
Alex Hayes [aut, cre] (<https://orcid.org/0000-0002-4985-5160>), Ralph Moller-Trane [aut], Emil Hvitfeldt [ctb] (<https://orcid.org/0000-0002-0679-1945>), Daniel Jordan [ctb], Bruna Wundervald [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.