[][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 Distribution<f64> for Hypergeometric[src]

fn sample<R: Rng>(&self, r: &mut R) -> f64[src]

Generates a random sample from the hypergeometric distribution using r as the source of randomness

Examples

use rand::StdRng;
use statrs::distribution::{Hypergeometric, Distribution};

let mut r = rand::StdRng::new().unwrap();
let n = Hypergeometric::new(10, 5, 3).unwrap();
print!("{}", n.sample::<StdRng>(&mut r));

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

This example is not tested
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

This example is not tested
(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

This example is not tested
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

This example is not tested
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

This example is not tested
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

This example is not tested
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

This example is not tested
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

This example is not tested
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

This example is not tested
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

This example is not tested
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

This example is not tested
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

This example is not tested
((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

This example is not tested
((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

This example is not tested
floor((n + 1) * (k + 1) / (N + 2))

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

impl Copy for Hypergeometric[src]

impl Clone for Hypergeometric[src]

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

Performs copy-assignment from source. Read more

impl PartialEq<Hypergeometric> for Hypergeometric[src]

impl Debug for Hypergeometric[src]

impl IndependentSample<f64> for Hypergeometric[src]

fn ind_sample<R: Rng>(&self, r: &mut R) -> f64[src]

Generate a random independent sample from a hypergeometric distribution using r as the source of randomness. Refer here for implementation details

impl Sample<f64> for Hypergeometric[src]

fn sample<R: Rng>(&mut self, r: &mut R) -> f64[src]

Generate a random sample from a hypergeometric distribution using r as the source of randomness. Refer here for implementation details

Auto Trait Implementations

impl Send for Hypergeometric

impl Unpin for Hypergeometric

impl Sync for Hypergeometric

impl UnwindSafe for Hypergeometric

impl RefUnwindSafe for Hypergeometric

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

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.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]