packages

stats::dist

On this page

Probability distributions as types. Each is built by a new that checks its parameters (throwing InvalidParameter), never panics afterwards, and implements Distribution (sampling) and either Continuous or Discrete (density, CDF, quantile, moments). The functions take one point; for an array use the broadcast call form Normal::pdf.(d, xs).

Structs

BernoulliSource

pub struct Bernoulli

The Bernoulli distribution: 1 with probability p, else 0.

nabi
use stats::{Bernoulli, Discrete};

let d = try Bernoulli::new(0.3);
assert(d.pmf(1) == 0.3 && d.cdf(0) == 0.7 && d.var() == 0.21);
  • pub fn new(p: f64) throws (StatsError) -> Bernoulli§

    Source

    Bernoulli(p), 0 <= p <= 1.

  • pub fn p(self) -> f64§

    Source

    The probability of 1.

  • pub fn fit<X: Sample>(x: X) throws (StatsError) -> Bernoulli§

    Source

    The maximum-likelihood fit: the share of ones. Values must be 0 or 1.

    nabi
    assert((try stats::Bernoulli::fit([1, 0, 0, 1])).p() == 0.5);
    
Trait implementations 2

BetaSource

pub struct Beta

The beta distribution with shapes a, b > 0 on [0, 1]. The CDF is the regularized incomplete beta function; draws from two gamma deviates.

nabi
use stats::{Beta, Continuous};

let d = try Beta::new(2.0, 3.0);
assert(d.mean() == 0.4);
assert((d.cdf(0.4) - 0.5248).abs() < 1e-15);
  • pub fn new(a: f64, b: f64) throws (StatsError) -> Beta§

    Source

    Beta(a, b); both finite and positive.

  • pub fn a(self) -> f64§

    Source

    The first shape.

  • pub fn b(self) -> f64§

    Source

    The second shape.

Trait implementations 2

BinomialSource

pub struct Binomial

The binomial distribution: the number of successes in n >= 0 independent trials of probability p. The PMF and CDF go through the incomplete beta function's factor and continued fraction, so both tails keep their relative accuracy for large n.

nabi
use stats::{Binomial, Discrete};

let d = try Binomial::new(20, 0.3);
assert((d.cdf(4) - 0.2375077788776017).abs() < 1e-15);
assert(d.mean() == 6.0);
  • pub fn new(n: i64, p: f64) throws (StatsError) -> Binomial§

    Source

    Binomial(n, p), n >= 0, 0 <= p <= 1.

  • pub fn trials(self) -> i64§

    Source

    The number of trials.

  • pub fn p(self) -> f64§

    Source

    The success probability.

  • pub fn fit<X: Sample>(x: X, n: i64) throws (StatsError) -> Binomial§

    Source

    The maximum-likelihood p for counts out of n trials each: sum(x) / (n * len(x)).

    nabi
    assert((try stats::Binomial::fit([3, 5, 4], 10)).p() == 0.4);
    
Trait implementations 2

CauchySource

pub struct Cauchy

The Cauchy (Lorentz) distribution with location x0 and scale gamma > 0: Student's t with one degree of freedom, shifted and scaled. It has no mean or variance (both NaN).

nabi
use stats::{Cauchy, Continuous};

let d = try Cauchy::new(0.0, 1.0);
assert(d.cdf(1.0) == 0.75 && d.ppf(0.75) == 1.0000000000000002);
  • pub fn new(x0: f64, gamma: f64) throws (StatsError) -> Cauchy§

    Source

    Cauchy(x0, gamma); x0 finite, gamma finite and > 0.

  • pub fn location(self) -> f64§

    Source

    The location (the median).

  • pub fn scale(self) -> f64§

    Source

    The scale (half the interquartile range).

Trait implementations 2

ChiSquaredSource

pub struct ChiSquared

The chi-squared distribution with k > 0 degrees of freedom (Gamma(k / 2, 2)); k need not be an integer.

nabi
use stats::{ChiSquared, Continuous};

let d = try ChiSquared::new(3.0);
assert((d.sf(7.814727903251178) - 0.05).abs() < 1e-15);
  • pub fn new(k: f64) throws (StatsError) -> ChiSquared§

    Source

    Chi-squared with k degrees of freedom (finite, > 0).

  • pub fn df(self) -> f64§

    Source

    The degrees of freedom.

Trait implementations 2

ExponentialSource

pub struct Exponential

The exponential distribution with rate lambda > 0 (mean 1 / lambda; SciPy's expon(scale=1/lambda)).

nabi
use stats::{Continuous, Exponential};

let d = try Exponential::new(2.0);
assert(d.mean() == 0.5);
assert((d.cdf(1.0) - (1.0 - (-2.0).exp())).abs() < 1e-16);
  • pub fn new(lambda: f64) throws (StatsError) -> Exponential§

    Source

    The exponential distribution with rate lambda (finite, > 0).

  • pub fn rate(self) -> f64§

    Source

    The rate.

  • pub fn fit<X: Sample>(x: X) throws (StatsError) -> Exponential§

    Source

    The maximum-likelihood fit lambda = 1 / mean(x); values must be >= 0 and not all 0.

    nabi
    assert((try stats::Exponential::fit([1.0, 2.0, 3.0])).rate() == 0.5);
    
Trait implementations 2

FisherFSource

pub struct FisherF

The F distribution with d1, d2 > 0 degrees of freedom: the ratio of two scaled chi-squared variables. CDF I_x(d1 / 2, d2 / 2) with x = d1 f / (d1 f + d2).

nabi
use stats::{Continuous, FisherF};

let d = try FisherF::new(3.0, 20.0);
assert((d.sf(3.0983912121407795) - 0.05).abs() < 1e-14);
  • pub fn new(d1: f64, d2: f64) throws (StatsError) -> FisherF§

    Source

    F(d1, d2); both finite and positive.

  • pub fn df1(self) -> f64§

    Source

    The numerator degrees of freedom.

  • pub fn df2(self) -> f64§

    Source

    The denominator degrees of freedom.

Trait implementations 2

GammaSource

pub struct Gamma

The gamma distribution with shape k > 0 and scale theta > 0 (mean k theta). The CDF is the regularized incomplete gamma function; draws by Marsaglia and Tsang (2000).

nabi
use stats::{Continuous, Gamma};

let d = try Gamma::new(2.0, 3.0);
assert(d.mean() == 6.0 && d.var() == 18.0);
assert((d.cdf(6.0) - 0.5939941502901619).abs() < 1e-15);
  • pub fn new(k: f64, theta: f64) throws (StatsError) -> Gamma§

    Source

    Gamma(k, theta); both finite and positive.

  • pub fn shape(self) -> f64§

    Source

    The shape.

  • pub fn scale(self) -> f64§

    Source

    The scale.

  • pub fn fit<X: Sample>(x: X) throws (StatsError) -> Gamma§

    Source

    The maximum-likelihood fit. The shape solves ln k - psi(k) = ln mean(x) - mean(ln x) by Newton's method from Minka's (2002) start; then theta = mean / k. Values must be positive and not all equal.

    nabi
    let d = try stats::Gamma::fit([1.0, 2.0, 3.0, 4.0, 5.0]);
    assert((d.shape() - 3.701643810008814).abs() < 1e-10); // SciPy: gamma.fit(x, floc=0)
    
Trait implementations 2

GeometricSource

pub struct Geometric

The geometric distribution on 1, 2, 3, ...: the number of trials of probability p up to and including the first success (SciPy's geom). P(X = k) = (1 - p)^(k - 1) p.

nabi
use stats::{Discrete, Geometric};

let d = try Geometric::new(0.25);
assert(d.pmf(2) == 0.1875 && d.mean() == 4.0);
assert(d.ppf(0.25) == 1 && d.ppf(0.4375) == 2);
  • pub fn new(p: f64) throws (StatsError) -> Geometric§

    Source

    Geometric(p), 0 < p <= 1.

  • pub fn p(self) -> f64§

    Source

    The success probability.

  • pub fn fit<X: Sample>(x: X) throws (StatsError) -> Geometric§

    Source

    The maximum-likelihood fit p = 1 / mean(x); values are trial counts >= 1.

    nabi
    assert((try stats::Geometric::fit([1, 3, 4])).p() == 0.375);
    
Trait implementations 2

LaplaceSource

pub struct Laplace

The Laplace distribution with location mu and scale b > 0: density e^(-|x - mu| / b) / (2 b).

nabi
use stats::{Continuous, Laplace};

let d = try Laplace::new(0.0, 1.0);
assert(d.cdf(0.0) == 0.5 && d.var() == 2.0);
assert((d.ppf(0.25) + 2.0.ln()).abs() < 1e-16);
  • pub fn new(mu: f64, b: f64) throws (StatsError) -> Laplace§

    Source

    Laplace(mu, b); mu finite, b finite and > 0.

  • pub fn location(self) -> f64§

    Source

    The location.

  • pub fn scale(self) -> f64§

    Source

    The scale.

  • pub fn fit<X: Sample>(x: X) throws (StatsError) -> Laplace§

    Source

    The maximum-likelihood fit: the median, and the mean absolute deviation from it.

    nabi
    let d = try stats::Laplace::fit([1.0, 2.0, 3.0, 10.0, 4.0]);
    assert(d.location() == 3.0 && d.scale() == 2.2);
    
Trait implementations 2

LogNormalSource

pub struct LogNormal

The log-normal distribution: X = e^Y with Y ~ N(mu, sigma^2) (SciPy's lognorm(s=sigma, scale=e^mu)).

nabi
use stats::{Continuous, LogNormal};

let d = try LogNormal::new(0.0, 1.0);
assert(d.median() == 1.0);
assert((d.mean() - 0.5.exp()).abs() < 1e-15);
  • pub fn new(mu: f64, sigma: f64) throws (StatsError) -> LogNormal§

    Source

    The log-normal of N(mu, sigma^2); mu finite, sigma > 0.

  • pub fn mu(self) -> f64§

    Source

    The mean of ln X.

  • pub fn sigma(self) -> f64§

    Source

    The standard deviation of ln X.

  • pub fn fit<X: Sample>(x: X) throws (StatsError) -> LogNormal§

    Source

    The maximum-likelihood fit: the mean and population standard deviation of ln x. Every value must be positive.

    nabi
    let d = try stats::LogNormal::fit([1.0, 10.0, 100.0]);
    assert((d.mu() - 10.0.ln()).abs() < 1e-15);
    
Trait implementations 2

MultinomialSource

pub struct Multinomial

The multinomial distribution: the counts in each of k categories after n independent draws with probabilities p. A draw is a vector of k counts summing to n (conditional binomials).

nabi
use stats::Multinomial;

let d = try Multinomial::new(4, [0.5, 0.25, 0.25]);
assert((try d.pmf([2, 1, 1]) - 0.1875).abs() < 1e-16);
assert(d.mean()[0] == 2.0);
  • pub fn new<P: Sample>(n: i64, p: P) throws (StatsError) -> Multinomial§

    Source

    Multinomial(n, p): n >= 0, p non-negative and summing to 1 within 1e-9 (then rescaled to sum to 1 exactly up to rounding).

  • pub fn trials(self) -> i64§

    Source

    The number of draws.

  • pub fn p(self) -> Vector<f64>§

    Source

    The category probabilities.

  • pub fn categories(self) -> usize§

    Source

    The number of categories.

  • pub fn logpmf<X: Sample>(self, x: X) throws (StatsError) -> f64§

    Source

    ln P(X = x) for a vector of counts x; -inf when the counts do not sum to n, are negative or not whole. Throws ShapeMismatch when x has the wrong length.

    nabi
    let d = try stats::Multinomial::new(2, [0.5, 0.5]);
    assert((try d.logpmf([1, 1]) - 0.5.ln()).abs() < 1e-15);
    
  • pub fn pmf<X: Sample>(self, x: X) throws (StatsError) -> f64§

    Source

    P(X = x); 0 where logpmf is -inf. Throws ShapeMismatch when x has the wrong length.

  • pub fn mean(self) -> Vector<f64>§

    Source

    n p.

  • pub fn cov(self) -> Matrix<f64>§

    Source

    The covariance n (diag(p) - p p^T).

    nabi
    let d = try stats::Multinomial::new(10, [0.5, 0.5]);
    assert(d.cov()[0, 0] == 2.5 && d.cov()[0, 1] == -2.5);
    
  • pub fn fit(x: Matrix<f64>) throws (StatsError) -> Multinomial§

    Source

    The maximum-likelihood fit from rows of counts (one observation per row, each summing to the same n): p is the column sums over the grand total.

    nabi
    use core::array::Matrix;
    
    let x: Matrix<f64> = [[1, 2, 1], [3, 0, 1]];
    let d = try stats::Multinomial::fit(x);
    assert(d.trials() == 4 && d.p()[0] == 0.5);
    
Trait implementations 1

MultivariateNormalSource

pub struct MultivariateNormal

The multivariate normal distribution with mean mu and covariance sigma (symmetric positive definite), through its Cholesky factor sigma = L L^T (linalg): the density by one triangular solve and ln det sigma = 2 sum ln L_ii, a draw as mu + L z.

nabi
use core::array::{Matrix, Vector};
use stats::MultivariateNormal;

let mu: Vector<f64> = [0, 0];
let s: Matrix<f64> = [[2, 1], [1, 2]];
let d = try MultivariateNormal::new(mu, s);
let x: Vector<f64> = [0, 0];
assert((try d.logpdf(x) - (-(2.0 * 3.141592653589793).ln() - 0.5 * 3.0.ln())).abs() < 1e-15);
  • pub fn new(mu: Vector<f64>, sigma: Matrix<f64>) throws (StatsError) -> MultivariateNormal§

    Source

    N(mu, sigma). Throws ShapeMismatch unless sigma is k x k for k = len(mu), NotFinite for NaN or infinity, Singular when sigma is not positive definite.

  • pub fn dim(self) -> usize§

    Source

    The dimension.

  • pub fn mean(self) -> Vector<f64>§

    Source

    The mean vector.

  • pub fn cov(self) -> Matrix<f64>§

    Source

    The covariance matrix.

  • pub fn l(self) -> Matrix<f64>§

    Source

    The Cholesky factor L of the covariance.

  • pub fn logdet(self) -> f64§

    Source

    ln det sigma.

  • pub fn logpdf(self, x: Vector<f64>) throws (StatsError) -> f64§

    Source

    The log density at x: -(k ln 2 pi + ln det sigma + |L^-1 (x - mu)|^2) / 2. Throws ShapeMismatch for a wrong length.

    nabi
    use core::array::{Matrix, Vector};
    
    let mu: Vector<f64> = [0];
    let s: Matrix<f64> = [[1]];
    let d = try stats::MultivariateNormal::new(mu, s);
    let x: Vector<f64> = [0];
    assert((try d.logpdf(x) + 0.9189385332046728).abs() < 1e-15);
    
  • pub fn pdf(self, x: Vector<f64>) throws (StatsError) -> f64§

    Source

    The density at x.

  • pub fn mahalanobis(self, x: Vector<f64>) throws (StatsError) -> f64§

    Source

    The squared Mahalanobis distance (x - mu)^T sigma^-1 (x - mu).

    nabi
    use core::array::{Matrix, Vector};
    
    let mu: Vector<f64> = [0, 0];
    let s: Matrix<f64> = [[4, 0], [0, 1]];
    let d = try stats::MultivariateNormal::new(mu, s);
    let x: Vector<f64> = [2, 1];
    assert((try d.mahalanobis(x) - 2.0).abs() < 1e-14);
    
  • pub fn sample_rows<G: Rng>(self, ref g: G, n: usize) -> Matrix<f64>§

    Source

    n draws as the rows of an n x k matrix.

    nabi
    use core::array::{Matrix, Vector};
    use std::random::Xoshiro256PlusPlus;
    
    let mu: Vector<f64> = [1, 2];
    let s: Matrix<f64> = [[1, 0.5], [0.5, 1]];
    let d = try stats::MultivariateNormal::new(mu, s);
    let g = Xoshiro256PlusPlus::seed(3);
    let x = d.sample_rows(ref g, 5000);
    assert(x.shape() == [5000, 2] && (stats::mean(x[:, 1]) - 2.0).abs() < 0.1);
    
  • pub fn fit(x: Matrix<f64>) throws (StatsError) -> MultivariateNormal§

    Source

    The maximum-likelihood fit from the rows of x (one observation per row): the column means and the covariance with ddof = 0.

    nabi
    use core::array::Matrix;
    
    let x: Matrix<f64> = [[1, 2], [3, 3], [2, 7]];
    let d = try stats::MultivariateNormal::fit(x);
    assert(d.mean()[0] == 2.0 && d.mean()[1] == 4.0);
    
Trait implementations 1

NegativeBinomialSource

pub struct NegativeBinomial

The negative binomial distribution: the number of failures before the r-th success in trials of probability p (SciPy's nbinom; r > 0 need not be an integer). `P(X = k) = C(k + r - 1, k) p^r (1

  • p)^k, CDF I_p(r, k + 1)`; draws as Poisson(Gamma(r, (1 - p) / p)).
nabi
use stats::{Discrete, NegativeBinomial};

let d = try NegativeBinomial::new(3.0, 0.5);
assert((d.pmf(2) - 0.1875).abs() < 1e-16 && d.mean() == 3.0);
  • pub fn new(r: f64, p: f64) throws (StatsError) -> NegativeBinomial§

    Source

    NegativeBinomial(r, p), r > 0 finite, 0 < p <= 1.

  • pub fn successes(self) -> f64§

    Source

    The number of successes.

  • pub fn p(self) -> f64§

    Source

    The success probability.

Trait implementations 2

NormalSource

pub struct Normal

The normal (Gaussian) distribution with mean mu and standard deviation sigma > 0. CDF and quantile through ndtr / ndtri, so both tails keep full relative accuracy; draws by the ziggurat.

nabi
use stats::{Continuous, Normal};

let d = try Normal::new(100.0, 15.0);
assert((d.cdf(130.0) - 0.9772498680518208).abs() < 1e-15);
assert((d.ppf(0.5) - 100.0).abs() < 1e-12);
  • pub fn new(mu: f64, sigma: f64) throws (StatsError) -> Normal§

    Source

    N(mu, sigma^2); throws InvalidParameter unless mu is finite and sigma finite and positive.

  • pub fn standard() -> Normal§

    Source

    N(0, 1).

  • pub fn mu(self) -> f64§

    Source

    The mean parameter.

  • pub fn sigma(self) -> f64§

    Source

    The standard deviation parameter.

  • pub fn fit<X: Sample>(x: X) throws (StatsError) -> Normal§

    Source

    The maximum-likelihood fit: the mean and the population standard deviation (ddof = 0). Throws TooFew below 2 values, NotFinite for NaN or infinity, InvalidParameter for constant data.

    nabi
    let d = try stats::Normal::fit([1.0, 2.0, 3.0, 4.0]);
    assert(d.mu() == 2.5 && (d.sigma() - 1.25.sqrt()).abs() < 1e-15);
    
Trait implementations 2

PoissonSource

pub struct Poisson

The Poisson distribution with mean lambda >= 0. PMF lambda^k e^-lambda / k! through the incomplete gamma function's factor, CDF Q(k + 1, lambda); draws by search below 10 and PTRS above.

nabi
use stats::{Discrete, Poisson};

let d = try Poisson::new(4.0);
assert((d.pmf(2) - 8.0 * (-4.0).exp()).abs() < 1e-16);
assert(d.ppf(0.5) == 4);
  • pub fn new(lambda: f64) throws (StatsError) -> Poisson§

    Source

    Poisson(lambda), lambda finite and >= 0.

  • pub fn lambda(self) -> f64§

    Source

    The mean.

  • pub fn fit<X: Sample>(x: X) throws (StatsError) -> Poisson§

    Source

    The maximum-likelihood fit: the mean of the counts.

    nabi
    assert((try stats::Poisson::fit([1, 2, 6])).lambda() == 3.0);
    
Trait implementations 2

StudentTSource

pub struct StudentT

Student's t distribution with nu > 0 degrees of freedom (not necessarily an integer). The CDF is I_x(nu / 2, 1 / 2) with x = nu / (nu + t^2), both x and 1 - x formed directly so neither tail cancels; the quantile inverts it, with the closed forms for nu = 1 and 2.

nabi
use stats::{Continuous, StudentT};

let d = try StudentT::new(10.0);
// mpmath: 2.22813885198627475; SciPy 1.13 gives 2.2281388519649385.
// A few ulps either way: the platform's libm differs (Windows' UCRT).
assert((d.ppf(0.975) - 2.2281388519862747).abs() < 4e-15);
assert((d.cdf(-2.0) - 0.036694017385370196).abs() < 1e-16);
  • pub fn new(nu: f64) throws (StatsError) -> StudentT§

    Source

    Student's t with nu degrees of freedom (> 0; inf is not allowed: use Normal::standard()).

  • pub fn df(self) -> f64§

    Source

    The degrees of freedom.

Trait implementations 2

UniformSource

pub struct Uniform

The uniform distribution on [a, b], a < b.

nabi
use stats::{Continuous, Uniform};

let d = try Uniform::new(2.0, 6.0);
assert(d.cdf(3.0) == 0.25 && d.ppf(0.75) == 5.0 && d.var() == 16.0 / 12.0);
  • pub fn new(a: f64, b: f64) throws (StatsError) -> Uniform§

    Source

    The uniform distribution on [a, b]; both finite, a < b.

  • pub fn a(self) -> f64§

    Source

    The lower end.

  • pub fn b(self) -> f64§

    Source

    The upper end.

  • pub fn fit<X: Sample>(x: X) throws (StatsError) -> Uniform§

    Source

    The maximum-likelihood fit [min(x), max(x)].

    nabi
    let d = try stats::Uniform::fit([0.5, 0.2, 0.9]);
    assert(d.a() == 0.2 && d.b() == 0.9);
    
Trait implementations 2

WeibullSource

pub struct Weibull

The Weibull distribution with shape k > 0 and scale lambda > 0: P(X > x) = e^(-(x / lambda)^k) (SciPy's weibull_min).

nabi
use stats::{Continuous, Weibull};

let d = try Weibull::new(2.0, 1.0);
assert((d.sf(1.0) - (-1.0).exp()).abs() < 1e-16);
assert((d.mean() - 0.8862269254527579).abs() < 1e-15);
  • pub fn new(k: f64, lambda: f64) throws (StatsError) -> Weibull§

    Source

    Weibull(k, lambda); both finite and positive.

  • pub fn shape(self) -> f64§

    Source

    The shape.

  • pub fn scale(self) -> f64§

    Source

    The scale.

Trait implementations 2

IidSource

pub struct Iid<D>

n independent copies of d: a draw is d.samples(g, n).

nabi
use stats::{Distribution, Poisson};
use std::random::Xoshiro256PlusPlus;

let g = Xoshiro256PlusPlus::seed(1);
let ks = (try Poisson::new(3.0)).iid(5).sample(ref g);
assert(ks.len() == 5);
  • pub d: D§

    Source

    The distribution of each draw.

  • pub n: usize§

    Source

    The number of draws.

Trait implementations 1

Traits

DistributionSource

pub trait Distribution

Something to draw random values from. Value is f64 for the continuous distributions, i64 for the discrete ones and a vector for the multivariate ones. Draws depend only on the generator's state, so a seeded Xoshiro256PlusPlus repeats them on every target.

nabi
use stats::{Distribution, Normal};
use std::random::Xoshiro256PlusPlus;

let g = Xoshiro256PlusPlus::seed(7);
let d = try Normal::new(10.0, 2.0);
let x = d.sample(ref g);
let xs = d.samples(ref g, 1000);
assert(xs.len() == 1000 && (stats::mean(xs) - 10.0).abs() < 0.3);
  • type Value§

    Source

    The type of one draw.

  • fn sample<G: Rng>(self, ref g: G) -> Value§

    Source

    One draw, advancing g.

  • fn samples<G: Rng>(self, ref g: G, n: usize) -> Array<Value, 1>§

    Source

    n independent draws.

  • fn iid(self, n: usize) -> Iid<Self>§

    Source

    n independent copies as one distribution, whose draw is a vector of n (for g ~ d.iid(n)).

ContinuousSource

pub trait Continuous: Distribution<Value = f64>

A distribution on the real line with a density.

nabi
use stats::{Continuous, Normal};

let d = Normal::standard();
assert(d.cdf(0.0) == 0.5);
assert((d.ppf(d.cdf(1.3)) - 1.3).abs() < 1e-15);
let i = d.interval(95pct);
assert((i.hi - 1.959963984540054).abs() < 1e-15);
  • fn pdf(self, x: f64) -> f64§

    Source

    The density at x.

  • fn logpdf(self, x: f64) -> f64§

    Source

    ln pdf(x), without underflow far in the tails.

  • fn cdf(self, x: f64) -> f64§

    Source

    P(X <= x).

  • fn sf(self, x: f64) -> f64§

    Source

    The survival function P(X > x), accurate where it is small.

  • fn ppf(self, p: f64) -> f64§

    Source

    The quantile: the x with cdf(x) = p, 0 <= p <= 1 (NaN otherwise).

  • fn isf(self, q: f64) -> f64§

    Source

    The x with sf(x) = q, accurate for small q.

  • fn mean(self) -> f64§

    Source

    The mean (NaN when it does not exist, as for Cauchy).

  • fn var(self) -> f64§

    Source

    The variance (NaN or infinity when it does not exist).

  • fn std(self) -> f64§

    Source

    The standard deviation.

  • fn median(self) -> f64§

    Source

    The median, ppf(0.5).

  • fn interval(self, level: f64) -> Interval§

    Source

    The central interval holding probability level: [ppf((1 - level) / 2), isf((1 - level) / 2)].

DiscreteSource

pub trait Discrete: Distribution<Value = i64>

A distribution on the integers.

nabi
use stats::{Discrete, Binomial};

let d = try Binomial::new(10, 0.5);
assert((d.pmf(5) - 0.24609375).abs() < 1e-15);
assert(d.ppf(0.5) == 5);
  • fn pmf(self, k: i64) -> f64§

    Source

    P(X = k).

  • fn logpmf(self, k: i64) -> f64§

    Source

    ln pmf(k).

  • fn cdf(self, k: i64) -> f64§

    Source

    P(X <= k).

  • fn sf(self, k: i64) -> f64§

    Source

    P(X > k), accurate where it is small.

  • fn ppf(self, p: f64) -> i64§

    Source

    The smallest k with cdf(k) >= p, 0 <= p <= 1; i64::MIN for a p outside it.

  • fn mean(self) -> f64§

    Source

    The mean.

  • fn var(self) -> f64§

    Source

    The variance.

  • fn std(self) -> f64§

    Source

    The standard deviation.