pub struct NegativeBinomial { /* private fields */ }Expand description
Negative binomial distribution with target successes r and success probability p.
Models the “number of failures before the r-th success” in a sequence of independent Bernoulli trials. The CDF reduces to the incomplete Β: Pr[F ≤ s] = Iₚ(r, s + 1).
§Notes
Entropy is not implemented.
§Example
use cdflib::NegativeBinomial;
use cdflib::traits::{Discrete, DiscreteCdf};
let nb = NegativeBinomial::new(5, 0.5);
// Probability of 3 or fewer failures before 5th success
let cdf = nb.cdf(3);
// Compute success probability given Pr[F ≤ 5] = 0.9 and r = 10
let pr = NegativeBinomial::search_pr(0.9, 0.1, 10, 5).unwrap();Implementations§
Source§impl NegativeBinomial
impl NegativeBinomial
Sourcepub fn try_new(r: u64, pr: f64) -> Result<Self, NegativeBinomialError>
pub fn try_new(r: u64, pr: f64) -> Result<Self, NegativeBinomialError>
Fallible counterpart of new returning a
NegativeBinomialError instead of panicking.
Sourcepub fn search_r(
p: f64,
q: f64,
pr: f64,
s: u64,
) -> Result<f64, NegativeBinomialError>
pub fn search_r( p: f64, q: f64, pr: f64, s: u64, ) -> Result<f64, NegativeBinomialError>
Returns the target number of successes r satisfying Pr[F ≤ s] = p given the success probability.
Mirrors CDFLIB’s cdfnbn with which = 3. Caller passes both
p and q = 1 − p; consistency is enforced within 3ε.
Sourcepub fn search_pr(
p: f64,
q: f64,
r: u64,
s: u64,
) -> Result<f64, NegativeBinomialError>
pub fn search_pr( p: f64, q: f64, r: u64, s: u64, ) -> Result<f64, NegativeBinomialError>
Returns the success probability pr satisfying Pr[F ≤ s] = p given r.
Mirrors CDFLIB’s cdfnbn with which = 4 (cdflib.f90:5400-5430).
Caller passes both p and q = 1 − p; consistency is enforced
within 3ε. When p > q the search runs on ompr = 1 − pr
(F90’s variable-switch precision strategy) and returns pr = 1 − ompr.
Source§impl NegativeBinomial
impl NegativeBinomial
Sourcepub fn inverse_ccdf(&self, q: f64) -> Result<f64, NegativeBinomialError>
pub fn inverse_ccdf(&self, q: f64) -> Result<f64, NegativeBinomialError>
Returns the real-valued s such that cdf(s) = 1 − q on the smooth continuous extension via Iₚᵣ(r, s+1).
Mirrors CDFLIB’s cdfnbn with which = 2 (cdflib.f90:5335-5380):
single dinvr loop, residual cum-p if p≤q else ccum-q.
Trait Implementations§
Source§impl Clone for NegativeBinomial
impl Clone for NegativeBinomial
Source§fn clone(&self) -> NegativeBinomial
fn clone(&self) -> NegativeBinomial
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NegativeBinomial
impl Debug for NegativeBinomial
Source§impl Discrete for NegativeBinomial
impl Discrete for NegativeBinomial
Source§impl DiscreteCdf for NegativeBinomial
impl DiscreteCdf for NegativeBinomial
Source§type Error = NegativeBinomialError
type Error = NegativeBinomialError
Source§fn inverse_cdf(&self, p: f64) -> Result<u64, NegativeBinomialError>
fn inverse_cdf(&self, p: f64) -> Result<u64, NegativeBinomialError>
Source§impl Mean for NegativeBinomial
impl Mean for NegativeBinomial
Source§impl PartialEq for NegativeBinomial
impl PartialEq for NegativeBinomial
Source§fn eq(&self, other: &NegativeBinomial) -> bool
fn eq(&self, other: &NegativeBinomial) -> bool
self and other values to be equal, and is used by ==.