Struct statrs::distribution::Binomial [−][src]
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]
fn sample<R: Rng + ?Sized>(&self, r: &mut R) -> f64
[src]
pub fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T> where
R: Rng,
[src]
R: Rng,
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]
impl Median<f64> for Binomial
[src]
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]
impl PartialEq<Binomial> for Binomial
[src]
impl Skewness<f64> for Binomial
[src]
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]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,