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

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);

Implementations

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 Clone for Binomial[src]

impl Copy for Binomial[src]

impl Debug for Binomial[src]

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

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 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 Median<f64> for Binomial[src]

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

Returns the median of the binomial distribution

Formula

floor(n * p)

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 Mode<u64> for Binomial[src]

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

Returns the mode for the binomial distribution

Formula

floor((n + 1) * p)

impl PartialEq<Binomial> for Binomial[src]

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 StructuralPartialEq for Binomial[src]

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 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))

Auto Trait Implementations

impl RefUnwindSafe for Binomial

impl Send for Binomial

impl Sync for Binomial

impl Unpin for Binomial

impl UnwindSafe for Binomial

Blanket Implementations

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

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

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

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

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

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]