Struct statrs::distribution::StudentsT [] [src]

pub struct StudentsT { /* fields omitted */ }

Implements the Student's T distribution

Examples

use statrs::distribution::{StudentsT, Continuous};
use statrs::statistics::Mean;
use statrs::prec;

let n = StudentsT::new(0.0, 1.0, 2.0).unwrap();
assert_eq!(n.mean(), 0.0);
assert!(prec::almost_eq(n.pdf(0.0), 0.353553390593274, 1e-15));

Methods

impl StudentsT
[src]

Constructs a new student's t-distribution with location location, scale scale, and freedom freedom.

Errors

Returns an error if any of location, scale, or freedom are NaN. Returns an error if scale <= 0.0 or freedom <= 0.0

Examples

use statrs::distribution::StudentsT;

let mut result = StudentsT::new(0.0, 1.0, 2.0);
assert!(result.is_ok());

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

Returns the location of the student's t-distribution

Examples

use statrs::distribution::StudentsT;

let n = StudentsT::new(0.0, 1.0, 2.0).unwrap();
assert_eq!(n.location(), 0.0);

Returns the scale of the student's t-distribution

Examples

use statrs::distribution::StudentsT;

let n = StudentsT::new(0.0, 1.0, 2.0).unwrap();
assert_eq!(n.scale(), 1.0);

Returns the freedom of the student's t-distribution

Examples

use statrs::distribution::StudentsT;

let n = StudentsT::new(0.0, 1.0, 2.0).unwrap();
assert_eq!(n.freedom(), 2.0);

Trait Implementations

impl Debug for StudentsT
[src]

Formats the value using the given formatter.

impl Copy for StudentsT
[src]

impl Clone for StudentsT
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for StudentsT
[src]

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

This method tests for !=.

impl Sample<f64> for StudentsT
[src]

Generate a random sample from a student's t-distribution distribution using r as the source of randomness. Refer here for implementation details

impl IndependentSample<f64> for StudentsT
[src]

Generate a random independent sample from a student's t-distribution distribution using r as the source of randomness. Refer here for implementation details

impl Distribution<f64> for StudentsT
[src]

Generate a random sample from a student's t-distribution using r as the source of randomness. The implementation is based on method 2, section 5 in chapter 9 of L. Devroye's "Non-Uniform Random Variate Generation"

Examples

use rand::StdRng;
use statrs::distribution::{StudentsT, Distribution};

let mut r = rand::StdRng::new().unwrap();
let n = StudentsT::new(0.0, 1.0, 2.0).unwrap();
print!("{}", n.sample::<StdRng>(&mut r));

impl Univariate<f64, f64> for StudentsT
[src]

Calculates the cumulative distribution function for the student's t-distribution at x

Formula

if x < μ {
    (1 / 2) * I(t, v / 2, 1 / 2)
} else {
    1 - (1 / 2) * I(t, v / 2, 1 / 2)
}

where t = v / (v + k^2), k = (x - μ) / σ, μ is the location, σ is the scale, v is the freedom, and I is the regularized incomplete beta function

impl Min<f64> for StudentsT
[src]

Returns the minimum value in the domain of the student's t-distribution representable by a double precision float

Formula

-INF

impl Max<f64> for StudentsT
[src]

Returns the maximum value in the domain of the student's t-distribution representable by a double precision float

Formula

INF

impl Mean<f64> for StudentsT
[src]

Returns the mean of the student's t-distribution

Panics

If freedom <= 1.0

Formula

μ

where μ is the location

impl Variance<f64> for StudentsT
[src]

Returns the variance of the student's t-distribution

Panics

If freedom <= 1.0

Formula

if v == INF {
    σ^2
} else if freedom > 2.0 {
    v * σ^2 / (v - 2)
} else {
    INF
}

where σ is the scale and v is the freedom

Returns the standard deviation of the student's t-distribution

Panics

If freedom <= 1.0

Formula

let variance = if v == INF {
    σ^2
} else if freedom > 2.0 {
    v * σ^2 / (v - 2)
} else {
    INF
}
sqrt(variance)

where σ is the scale and v is the freedom

impl Entropy<f64> for StudentsT
[src]

Returns the entropy for the student's t-distribution

Panics

If location != 0.0 && scale != 1.0

Formula

(v + 1) / 2 * (ψ((v + 1) / 2) - ψ(v / 2)) + ln(sqrt(v) * B(v / 2, 1 / 2))

where v is the freedom, ψ is the digamma function, and B is the beta function

impl Skewness<f64> for StudentsT
[src]

Returns the skewness of the student's t-distribution

Panics

If x <= 3.0

Formula

0

impl Median<f64> for StudentsT
[src]

Returns the median of the student's t-distribution

Formula

μ

where μ is the location

impl Mode<f64> for StudentsT
[src]

Returns the mode of the student's t-distribution

Formula

μ

where μ is the location

impl Continuous<f64, f64> for StudentsT
[src]

Calculates the probability density function for the student's t-distribution at x

Formula

Γ((v + 1) / 2) / (sqrt() * Γ(v / 2) * σ) * (1 + k^2 / v)^(-1 / 2 * (v + 1))

where k = (x - μ) / σ, μ is the location, σ is the scale, v is the freedom, and Γ is the gamma function

Calculates the log probability density function for the student's t-distribution at x

Formula

ln(Γ((v + 1) / 2) / (sqrt() * Γ(v / 2) * σ) * (1 + k^2 / v)^(-1 / 2 * (v + 1)))

where k = (x - μ) / σ, μ is the location, σ is the scale, v is the freedom, and Γ is the gamma function