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

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

Generate a random sample from the binomial distribution using r as the source of randomness where the range of values is [0.0, n].

Examples

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

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

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

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

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

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

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

This example is not tested
n

impl Mean<f64> for Binomial[src]

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

Returns the mean of the binomial distribution

Formula

This example is not tested
p * n

impl Variance<f64> for Binomial[src]

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

Returns the variance of the binomial distribution

Formula

This example is not tested
n * p * (1 - p)

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

Returns the standard deviation of the binomial distribution

Formula

This example is not tested
sqrt(n * p * (1 - p))

impl Entropy<f64> for Binomial[src]

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

Returns the entropy of the binomial distribution

Formula

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

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

This example is not tested
floor(n * p)

impl Mode<u64> for Binomial[src]

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

Returns the mode for the binomial distribution

Formula

This example is not tested
floor((n + 1) * p)

impl Copy for Binomial[src]

impl Clone for Binomial[src]

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

Performs copy-assignment from source. Read more

impl PartialEq<Binomial> for Binomial[src]

impl Debug for Binomial[src]

impl IndependentSample<f64> for Binomial[src]

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

impl Sample<f64> for Binomial[src]

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

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

Auto Trait Implementations

impl Send for Binomial

impl Unpin for Binomial

impl Sync for Binomial

impl UnwindSafe for Binomial

impl RefUnwindSafe for Binomial

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]