pub struct NegativeBinomial {
pub r: f64,
pub p: f64,
}Expand description
Negative Binomial distribution NegBinom(r, p).
§Examples
use rs_stats::distributions::negative_binomial::NegativeBinomial;
use rs_stats::distributions::traits::DiscreteDistribution;
let nb = NegativeBinomial::new(5.0, 0.5).unwrap();
assert!((nb.mean() - 5.0).abs() < 1e-10);Fields§
§r: f64Number of successes r > 0 (can be non-integer, i.e. the overdispersion parameter)
p: f64Success probability p ∈ (0, 1)
Implementations§
Source§impl NegativeBinomial
impl NegativeBinomial
Sourcepub fn new(r: f64, p: f64) -> StatsResult<Self>
pub fn new(r: f64, p: f64) -> StatsResult<Self>
Creates a NegBinom(r, p) distribution.
Sourcepub fn fit(data: &[f64]) -> StatsResult<Self>
pub fn fit(data: &[f64]) -> StatsResult<Self>
Method-of-moments fitting.
- mean = r(1−p)/p → p = mean/variance (requires variance > mean)
- r = mean² / (variance − mean)
Trait Implementations§
Source§impl Clone for NegativeBinomial
impl Clone for NegativeBinomial
Source§fn clone(&self) -> NegativeBinomial
fn clone(&self) -> NegativeBinomial
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for NegativeBinomial
impl Debug for NegativeBinomial
Source§impl<'de> Deserialize<'de> for NegativeBinomial
impl<'de> Deserialize<'de> for NegativeBinomial
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl DiscreteDistribution for NegativeBinomial
impl DiscreteDistribution for NegativeBinomial
Source§fn num_params(&self) -> usize
fn num_params(&self) -> usize
Number of free parameters (used for AIC / BIC).
Source§fn logpmf(&self, k: u64) -> StatsResult<f64>
fn logpmf(&self, k: u64) -> StatsResult<f64>
Natural logarithm of the PMF: ln P(X = k). Read more
Source§fn inverse_cdf(&self, p: f64) -> StatsResult<u64>
fn inverse_cdf(&self, p: f64) -> StatsResult<u64>
Quantile function: smallest k ≥ 0 such that CDF(k) ≥ p. Read more
Source§fn log_likelihood(&self, data: &[u64]) -> StatsResult<f64>
fn log_likelihood(&self, data: &[u64]) -> StatsResult<f64>
Sum of log-PMFs: Σ ln P(X = kᵢ).
Source§impl Serialize for NegativeBinomial
impl Serialize for NegativeBinomial
impl Copy for NegativeBinomial
Auto Trait Implementations§
impl Freeze for NegativeBinomial
impl RefUnwindSafe for NegativeBinomial
impl Send for NegativeBinomial
impl Sync for NegativeBinomial
impl Unpin for NegativeBinomial
impl UnsafeUnpin for NegativeBinomial
impl UnwindSafe for NegativeBinomial
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more