Struct rv::dist::NegBinomial[][src]

pub struct NegBinomial { /* fields omitted */ }
Expand description

Negative Binomial distribution NBin(r, p).

Notes

This crate uses the parameterization found on Wolfram Mathworld, which is also the parameterization used in scipy.

Parameters

  • r: The number of successes before the trials are stopped
  • p: The success probability

Implementations

Create a new Negative Binomial distribution

Create a new Negative Binomial distribution without input validation.

Get the value of the r parameter

Change the value of the r parameter

Example

use rv::dist::NegBinomial;

let mut nbin = NegBinomial::new(4.0, 0.8).unwrap();

assert!((nbin.r() - 4.0).abs() < 1E-10);

nbin.set_r(2.5).unwrap();

assert!((nbin.r() - 2.5).abs() < 1E-10);

Will error for invalid values

assert!(nbin.set_r(2.0).is_ok());
assert!(nbin.set_r(1.0).is_ok());

// r must be >= 1.0
assert!(nbin.set_r(0.99).is_err());

assert!(nbin.set_r(std::f64::INFINITY).is_err());
assert!(nbin.set_r(std::f64::NEG_INFINITY).is_err());
assert!(nbin.set_r(std::f64::NAN).is_err());

Set the value of r without input validation

Get the value of the p parameter

Change the value of the p parameter

Example

use rv::dist::NegBinomial;

let mut nbin = NegBinomial::new(4.0, 0.8).unwrap();

assert!((nbin.p() - 0.8).abs() < 1E-10);

nbin.set_p(0.51).unwrap();

assert!((nbin.p() - 0.51).abs() < 1E-10);

Will error for invalid values

// OK values in [0, 1]
assert!(nbin.set_p(0.51).is_ok());
assert!(nbin.set_p(0.0).is_ok());
assert!(nbin.set_p(1.0).is_ok());

// Too low, not in [0, 1]
assert!(nbin.set_p(-0.1).is_err());

// Too high, not in [0, 1]
assert!(nbin.set_p(-1.1).is_err());

assert!(nbin.set_p(std::f64::INFINITY).is_err());
assert!(nbin.set_p(std::f64::NEG_INFINITY).is_err());
assert!(nbin.set_p(std::f64::NAN).is_err());

Set the value of p without input validation

Trait Implementations

The value of the Cumulative Density Function at x Read more

Survival function, 1 - CDF(x)

The value of the Cumulative Density Function at x Read more

Survival function, 1 - CDF(x)

The value of the Cumulative Density Function at x Read more

Survival function, 1 - CDF(x)

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Probability mass function (PMF) at x Read more

Natural logarithm of the probability mass function (PMF) Read more

Probability mass function (PMF) at x Read more

Natural logarithm of the probability mass function (PMF) Read more

Probability mass function (PMF) at x Read more

Natural logarithm of the probability mass function (PMF) Read more

Returns None if the mean is undefined

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Probability function Read more

Single draw from the Rv Read more

Multiple draws of the Rv Read more

Probability function Read more

Create a never-ending iterator of samples Read more

Probability function Read more

Single draw from the Rv Read more

Multiple draws of the Rv Read more

Probability function Read more

Create a never-ending iterator of samples Read more

Probability function Read more

Single draw from the Rv Read more

Multiple draws of the Rv Read more

Probability function Read more

Create a never-ending iterator of samples Read more

Returns true if x is in the support of the Rv Read more

Returns true if x is in the support of the Rv Read more

Returns true if x is in the support of the Rv Read more

Returns None if the variance is undefined

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more

Checks if self is actually part of its subset T (and can be converted to it).

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

The inclusion map: converts self to the equivalent element of its superset.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.