Struct statrs::distribution::Geometric[][src]

pub struct Geometric { /* fields omitted */ }

Implements the Geometric distribution

Examples

use statrs::distribution::{Geometric, Discrete};
use statrs::statistics::Mean;

let n = Geometric::new(0.3).unwrap();
assert_eq!(n.mean(), 1.0 / 0.3);
assert_eq!(n.pmf(1), 0.3);
assert_eq!(n.pmf(2), 0.21);

Implementations

impl Geometric[src]

pub fn new(p: f64) -> Result<Geometric>[src]

Constructs a new shifted geometric distribution with a probability of p

Errors

Returns an error if p is not in (0, 1]

Examples

use statrs::distribution::Geometric;

let mut result = Geometric::new(0.5);
assert!(result.is_ok());

result = Geometric::new(0.0);
assert!(result.is_err());

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

Returns the probability p of the geometric distribution

Examples

use statrs::distribution::Geometric;

let n = Geometric::new(0.5).unwrap();
assert_eq!(n.p(), 0.5);

Trait Implementations

impl Clone for Geometric[src]

impl Copy for Geometric[src]

impl Debug for Geometric[src]

impl Discrete<u64, f64> for Geometric[src]

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

Calculates the probability mass function for the geometric distribution at x

Formula

(1 - p)^(x - 1) * p

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

Calculates the log probability mass function for the geometric distribution at x

Formula

ln((1 - p)^(x - 1) * p)

impl Distribution<f64> for Geometric[src]

impl Entropy<f64> for Geometric[src]

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

Returns the entropy of the geometric distribution

Formula

(-(1 - p) * log_2(1 - p) - p * log_2(p)) / p

impl Max<u64> for Geometric[src]

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

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

Formula

2^63 - 1

impl Mean<f64> for Geometric[src]

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

Returns the mean of the geometric distribution

Formula

1 / p

impl Median<f64> for Geometric[src]

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

Returns the median of the geometric distribution

Remarks

Returns 1 if p is 1

Formula

ceil(-1 / log_2(1 - p))

impl Min<u64> for Geometric[src]

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

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

Formula

1

impl Mode<u64> for Geometric[src]

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

Returns the mode of the geometric distribution

Formula

1

impl PartialEq<Geometric> for Geometric[src]

impl Skewness<f64> for Geometric[src]

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

Returns the skewness of the geometric distribution

Formula

(2 - p) / sqrt(1 - p)

impl StructuralPartialEq for Geometric[src]

impl Univariate<u64, f64> for Geometric[src]

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

Calculates the cumulative distribution function for the geometric distribution at x

Formula

1 - (1 - p) ^ (x + 1)

impl Variance<f64> for Geometric[src]

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

Returns the standard deviation of the geometric distribution

Formula

(1 - p) / p^2

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

Returns the standard deviation of the geometric distribution

Remarks

Returns NAN if p is 1

Formula

sqrt(1 - p) / p

Auto Trait Implementations

impl RefUnwindSafe for Geometric

impl Send for Geometric

impl Sync for Geometric

impl Unpin for Geometric

impl UnwindSafe for Geometric

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]