[−][src]Struct statrs::distribution::Binomial

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

Implements the Binomial distribution

Examples

```use statrs::distribution::{Binomial, Discrete};
use statrs::statistics::Mean;

let n = Binomial::new(0.5, 5).unwrap();
assert_eq!(n.mean(), 2.5);
assert_eq!(n.pmf(0), 0.03125);
assert_eq!(n.pmf(3), 0.3125);```

Methods

`impl Binomial`[src]

`pub fn new(p: f64, n: u64) -> Result<Binomial>`[src]

Constructs a new binomial distribution with a given `p` probability of success of `n` trials.

Errors

Returns an error if `p` is `NaN`, less than `0.0`, greater than `1.0`, or if `n` is less than `0`

Examples

```use statrs::distribution::Binomial;

let mut result = Binomial::new(0.5, 5);
assert!(result.is_ok());

result = Binomial::new(-0.5, 5);
assert!(result.is_err());```

`pub fn p(&self) -> f64`[src]

Returns the probability of success `p` of the binomial distribution.

Examples

```use statrs::distribution::Binomial;

let n = Binomial::new(0.5, 5).unwrap();
assert_eq!(n.p(), 0.5);```

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

Returns the number of trials `n` of the binomial distribution.

Examples

```use statrs::distribution::Binomial;

let n = Binomial::new(0.5, 5).unwrap();
assert_eq!(n.n(), 5);```

Trait Implementations

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

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

Calulcates the cumulative distribution function for the binomial distribution at `x`

Formula

`I_(1 - p)(n - x, 1 + x)`

where `I_(x)(a, b)` is the regularized incomplete beta function

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

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

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

Formula

`(n choose k) * p^k * (1 - p)^(n - k)`

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

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

Formula

`ln((n choose k) * p^k * (1 - p)^(n - k))`

`impl Min<u64> for Binomial`[src]

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

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

Formula

`0`

`impl Max<u64> for Binomial`[src]

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

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

Formula

`n`

`impl Mean<f64> for Binomial`[src]

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

Returns the mean of the binomial distribution

Formula

`p * n`

`impl Variance<f64> for Binomial`[src]

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

Returns the variance of the binomial distribution

Formula

`n * p * (1 - p)`

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

Returns the standard deviation of the binomial distribution

Formula

`sqrt(n * p * (1 - p))`

`impl Entropy<f64> for Binomial`[src]

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

Returns the entropy of the binomial distribution

Formula

`(1 / 2) * ln (2 * π * e * n * p * (1 - p))`

`impl Skewness<f64> for Binomial`[src]

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

Returns the skewness of the binomial distribution

Formula

`(1 - 2p) / sqrt(n * p * (1 - p)))`

`impl Median<f64> for Binomial`[src]

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

Returns the median of the binomial distribution

Formula

`floor(n * p)`

`impl Mode<u64> for Binomial`[src]

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

Returns the mode for the binomial distribution

Formula

`floor((n + 1) * p)`

`impl Clone for Binomial`[src]

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

Performs copy-assignment from `source`. Read more

`impl Distribution<f64> for Binomial`[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.