# [−][src]Struct statrs::distribution::Hypergeometric

`pub struct Hypergeometric { /* fields omitted */ }`

Implements the Hypergeometric distribution

# Examples

## Methods

### `impl Hypergeometric`[src]

#### `pub fn new(    population: u64,     successes: u64,     draws: u64) -> Result<Hypergeometric>`[src]

Constructs a new hypergeometric distribution with a population (N) of `population`, number of successes (K) of `successes`, and number of draws (n) of `draws`

# Errors

If `successes > population` or `draws > population`

# Examples

```use statrs::distribution::Hypergeometric;

let mut result = Hypergeometric::new(2, 2, 2);
assert!(result.is_ok());

result = Hypergeometric::new(2, 3, 2);
assert!(result.is_err());```

#### `pub fn population(&self) -> u64`[src]

Returns the population size of the hypergeometric distribution

# Examples

```use statrs::distribution::Hypergeometric;

let n = Hypergeometric::new(10, 5, 3).unwrap();
assert_eq!(n.population(), 10);```

#### `pub fn successes(&self) -> u64`[src]

Returns the number of observed successes of the hypergeometric distribution

# Examples

```use statrs::distribution::Hypergeometric;

let n = Hypergeometric::new(10, 5, 3).unwrap();
assert_eq!(n.successes(), 5);```

#### `pub fn draws(&self) -> u64`[src]

Returns the number of draws of the hypergeometric distribution

# Examples

```use statrs::distribution::Hypergeometric;

let n = Hypergeometric::new(10, 5, 3).unwrap();
assert_eq!(n.draws(), 3);```

## Trait Implementations

### `impl Univariate<u64, f64> for Hypergeometric`[src]

#### `fn cdf(&self, x: f64) -> f64`[src]

Calculates the cumulative distribution function for the hypergeometric distribution at `x`

# Formula

```1 - ((n choose k+1) * (N-n choose K-k-1)) / (N choose K) * 3_F_2(1,
k+1-K, k+1-n; k+2, N+k+2-K-n; 1)```

and `p_F_q` is the [generalized hypergeometric function](https://en.wikipedia. org/wiki/Generalized_hypergeometric_function)

### `impl Discrete<u64, f64> for Hypergeometric`[src]

#### `fn pmf(&self, x: u64) -> f64`[src]

Calculates the probability mass function for the hypergeometric distribution at `x`

# Formula

`(K choose x) * (N-K choose n-x) / (N choose n)`

where `N` is population, `K` is successes, and `n` is draws

#### `fn ln_pmf(&self, x: u64) -> f64`[src]

Calculates the log probability mass function for the hypergeometric distribution at `x`

# Formula

`ln((K choose x) * (N-K choose n-x) / (N choose n))`

where `N` is population, `K` is successes, and `n` is draws

### `impl Min<u64> for Hypergeometric`[src]

#### `fn min(&self) -> u64`[src]

Returns the minimum value in the domain of the hypergeometric distribution representable by a 64-bit integer

# Formula

`max(0, n + K - N)`

where `N` is population, `K` is successes, and `n` is draws

### `impl Max<u64> for Hypergeometric`[src]

#### `fn max(&self) -> u64`[src]

Returns the maximum value in the domain of the hypergeometric distribution representable by a 64-bit integer

# Formula

`min(K, n)`

where `K` is successes and `n` is draws

### `impl Mean<f64> for Hypergeometric`[src]

#### `fn mean(&self) -> f64`[src]

Returns the mean of the hypergeometric distribution

# Panics

If `N` is `0`

# Formula

`K * n / N`

where `N` is population, `K` is successes, and `n` is draws

### `impl CheckedMean<f64> for Hypergeometric`[src]

#### `fn checked_mean(&self) -> Result<f64>`[src]

Returns the mean of the hypergeometric distribution

# Errors

If `N` is `0`

# Formula

`K * n / N`

where `N` is population, `K` is successes, and `n` is draws

### `impl Variance<f64> for Hypergeometric`[src]

#### `fn variance(&self) -> f64`[src]

Returns the variance of the hypergeometric distribution

# Panics

If `N <= 1`

# Formula

`n * (K / N) * ((N - K) / N) * ((N - n) / (N - 1))`

where `N` is population, `K` is successes, and `n` is draws

#### `fn std_dev(&self) -> f64`[src]

Returns the standard deviation of the hypergeometric distribution

# Panics

If `N <= 1`

# Formula

`sqrt(n * (K / N) * ((N - K) / N) * ((N - n) / (N - 1)))`

where `N` is population, `K` is successes, and `n` is draws

### `impl CheckedVariance<f64> for Hypergeometric`[src]

#### `fn checked_variance(&self) -> Result<f64>`[src]

Returns the variance of the hypergeometric distribution

# Errors

If `N <= 1`

# Formula

`n * (K / N) * ((N - K) / N) * ((N - n) / (N - 1))`

where `N` is population, `K` is successes, and `n` is draws

#### `fn checked_std_dev(&self) -> Result<f64>`[src]

Returns the standard deviation of the hypergeometric distribution

# Errors

If `N <= 1`

# Formula

`sqrt(n * (K / N) * ((N - K) / N) * ((N - n) / (N - 1)))`

where `N` is population, `K` is successes, and `n` is draws

### `impl Skewness<f64> for Hypergeometric`[src]

#### `fn skewness(&self) -> f64`[src]

Returns the skewness of the hypergeometric distribution

# Panics

If `N <= 2`

# Formula

```((N - 2K) * (N - 1)^(1 / 2) * (N - 2n)) / ([n * K * (N - K) * (N -
n)]^(1 / 2) * (N - 2))```

where `N` is population, `K` is successes, and `n` is draws

### `impl CheckedSkewness<f64> for Hypergeometric`[src]

#### `fn checked_skewness(&self) -> Result<f64>`[src]

Returns the skewness of the hypergeometric distribution

# Errors

If `N <= 2`

# Formula

```((N - 2K) * (N - 1)^(1 / 2) * (N - 2n)) / ([n * K * (N - K) * (N -
n)]^(1 / 2) * (N - 2))```

where `N` is population, `K` is successes, and `n` is draws

### `impl Mode<u64> for Hypergeometric`[src]

#### `fn mode(&self) -> u64`[src]

Returns the mode of the hypergeometric distribution

# Formula

`floor((n + 1) * (k + 1) / (N + 2))`

where `N` is population, `K` is successes, and `n` is draws

### `impl Clone for Hypergeometric`[src]

#### `fn clone_from(&mut self, source: &Self)`1.0.0[src]

Performs copy-assignment from `source`. Read more

### `impl Distribution<f64> for Hypergeometric`[src]

#### `fn sample_iter<R>(&'a self, rng: &'a mut R) -> DistIter<'a, Self, R, T> where    R: Rng, `[src]

Create an iterator that generates random values of `T`, using `rng` as the source of randomness. Read more

## Blanket Implementations

### `impl<T> ToOwned for T where    T: Clone, `[src]

#### `type Owned = T`

The resulting type after obtaining ownership.

### `impl<T, U> TryFrom<U> for T where    U: Into<T>, `[src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

### `impl<T, U> TryInto<U> for T where    U: TryFrom<T>, `[src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.