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]
fn new(location: f64, scale: f64, freedom: f64) -> Result<StudentsT>
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());
fn location(&self) -> f64
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);
fn scale(&self) -> f64
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);
fn freedom(&self) -> f64
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]
impl Copy for StudentsT
[src]
impl Clone for StudentsT
[src]
fn clone(&self) -> StudentsT
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl PartialEq for StudentsT
[src]
fn eq(&self, __arg_0: &StudentsT) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &StudentsT) -> bool
This method tests for !=
.
impl Sample<f64> for StudentsT
[src]
fn sample<R: Rng>(&mut self, r: &mut R) -> f64
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]
fn ind_sample<R: Rng>(&self, r: &mut R) -> f64
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]
fn sample<R: Rng>(&self, r: &mut R) -> f64
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]
fn cdf(&self, x: f64) -> f64
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]
fn min(&self) -> f64
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]
fn max(&self) -> f64
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]
impl Variance<f64> for StudentsT
[src]
fn variance(&self) -> f64
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
fn std_dev(&self) -> f64
impl Entropy<f64> for StudentsT
[src]
impl Skewness<f64> for StudentsT
[src]
impl Median<f64> for StudentsT
[src]
impl Mode<f64> for StudentsT
[src]
impl Continuous<f64, f64> for StudentsT
[src]
fn pdf(&self, x: f64) -> f64
Calculates the probability density function for the student's t-distribution
at x
Formula
Γ((v + 1) / 2) / (sqrt(vπ) * Γ(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
fn ln_pdf(&self, x: f64) -> f64
Calculates the log probability density function for the student's t-distribution
at x
Formula
ln(Γ((v + 1) / 2) / (sqrt(vπ) * Γ(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