pdfHyperGeo

Purpose

Computes the probability mass function for the hypergeometric distribution.

Format

p = pdfHyperGeo(x, m, k, n)
Parameters:
  • x (NxK matrix, Nx1 vector or scalar) – must be a positive number and < m

  • m (NxK matrix, Nx1 vector or scalar) – The size of the population from which draws will be made. ExE conformable with x. m must be > x, k and n.

  • k (NxK matrix, Nx1 vector or scalar) – The number of marked items. ExE conformable with x.

  • n (NxK matrix, Nx1 vector or scalar) – The number of items drawn from the population. ExE conformable with x. \(0 < k < m\).

Returns:

p (NxK matrix, Nx1 vector or scalar) – The probability of drawing x marked items.

Examples

You are given 50 hard drives, 4 of which are known to be bad. What is the probability of drawing exactly 1 bad hard drive if you randomly select 6 drives?

p = pdfHyperGeo(1, 50, 4, 6);

After running the code above, p is equal to:

0.34504559

Continuing with the example above, what are the probabilities of drawing exactly 2 or exactly 4 bad hard drives?

x = { 2, 4 };
p = pdfHyperGeo(x, 50, 4, 6);

After running the code above, p is equal to:

0.061615284
6.5132436e-05

Remarks

The probability density function for the hypergeometric distribution is defined as:

\(P\left( x \middle| m,k,n \right)\text{ = }\) \(\frac{\left( \left. \begin{matrix} k \\ x \\ \end{matrix} \right)\left( \left. \begin{matrix} {m - k} \\ {n - x} \\ \end{matrix} \right) \right. \right.}{\begin{pmatrix} m \\ n \\ \end{pmatrix}}\)

For invalid inputs, pdfHyperGeo() will return a scalar error code which, when its value is assessed by function scalerr(), corresponds to the invalid input. If the first input is out of range, scalerr() will return a 1; if the second is out of range, scalerr() will return a 2; etc.