Introduction

The density function of Student's $t$ distribution:

$$ f(x; \nu) = \dfrac{\Gamma \left( \frac{\nu + 1}{2} \right)}{ \sqrt{\nu \pi} \Gamma \left( \frac{\nu}{2} \right)} \left( 1 + \frac{t^2}{\nu} \right)^{- \frac{\nu+1}{2}} $$

Parameters:

  • dof_par is $\nu$. Note: this need not be an integer.

Density


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
return_t<Ta> dt(const Ta x, const Tb dof_par, const bool log_form = false);

Computes the density function.


Examples:

// parameters
double dof = 14.0;

// standard input
double dens_val = stats::dt(0.5,dof);
double log_dens_val = stats::dt(0.5,dof,true);

// Armadillo input
arma::mat X(10,1);
X.fill(0.5);

arma::mat dens_vals_mat = stats::dt(X,dof);
arma::mat log_dens_vals_mat = stats::dt(X,dof,true);

Probability


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
return_t<Ta> pt(const Ta x, const Tb dof_par, const bool log_form = false);

Computes the cumulative distribution function (CDF).


Examples:

// parameters
double dof = 14.0;

// standard input
double prob_val = stats::pt(0.5,dof);
double log_prob_val = stats::pt(0.5,dof,true);

// Armadillo input
arma::mat X(10,1);
X.fill(0.5);

arma::mat prob_vals_mat = stats::pt(X,dof);
arma::mat log_prob_vals_mat = stats::pt(X,dof,true);

Quantile


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
Ta qt(const Ta p, const Tb dof_par);

Computes the quantile function.


Examples:

// parameters
double dof = 14.0;

// standard input
double quant_val = stats::qt(0.7,dof);

// Armadillo input
arma::mat X(10,1);
X.fill(0.7);

arma::mat quant_vals_mat = stats::qt(X,dof);

Random Sampling


Definition:

 
// random engine seeding
template<typename T>
statslib_inline
return_t<T> rt(const T dof_par, rand_engine_t& engine);

// seeding values
template<typename T>
statslib_inline
return_t<T> rt(const T dof_par, uint_t seed_val = std::random_device{}());

// matrix output
template<typename mT, typename eT>
statslib_inline
mT rt(const uint_t n, const uint_t k, const eT dof_par);

Generates pseudo-random draws.


Examples:

// parameters
double dof = 14.0;

// standard input
double rand_val = stats::rt(dof);

// Armadillo output: 10 x 1 matrix
arma::mat rand_mat = stats::rt<arma::mat>(10,1,dof);