Introduction

The density function of the inverse-Gamma distribution:

$$ f(x; \alpha, \beta) = \dfrac{\beta^{\alpha}}{\Gamma(\alpha)} x^{-\alpha-1} \exp\left(-\frac{\beta}{x}\right) \times \mathbf{1}[ x > 0 ] $$

Parameters:

  • shape_par is $\alpha$
  • scale_par is $\beta$

Density


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
return_t<Ta> dinvgamma(const Ta x, const Tb shape_par, const Tb scale_par, const bool log_form = false);

Computes the density function.


Examples:

// parameters
double shape = 5.0;
double scale = 4.0;

// standard input
double dens_val = stats::dinvgamma(0.5,shape,scale);
double log_dens_val = stats::dinvgamma(0.5,shape,scale,true);

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

arma::mat dens_vals_mat = stats::dinvgamma(X,shape,scale);
arma::mat log_dens_vals_mat = stats::dinvgamma(X,shape,scale,true);

Probability


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
return_t<Ta> pinvgamma(const Ta x, const Tb shape_par, const Tb scale_par, const bool log_form = false);

Computes the cumulative distribution function (CDF).


Examples:

// parameters
double shape = 5.0;
double scale = 4.0;

// standard input
double prob_val = stats::pinvgamma(0.5,shape,scale);
double log_prob_val = stats::pinvgamma(0.5,shape,scale,true);

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

arma::mat prob_vals_mat = stats::pinvgamma(X,shape,scale);
arma::mat log_prob_vals_mat = stats::pinvgamma(X,shape,scale,true);

Quantile


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
Ta qinvgamma(const Ta p, const Tb shape_par, const Tb scale_par);

Computes the quantile function.


Examples:

// parameters
double shape = 5.0;
double scale = 4.0;

// standard input
double quant_val = stats::qinvgamma(0.7,shape,scale);

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

arma::mat quant_vals_mat = stats::qinvgamma(X,shape,scale);

Random Sampling


Definition:

 
// random engine seeding
template<typename T>
statslib_inline
return_t<T> rinvgamma(const T shape_par, const T scale_par, rand_engine_t& engine);

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

// matrix output
template<typename mT, typename eT>
statslib_inline
mT rinvgamma(const uint_t n, const uint_t k, const eT shape_par, const eT scale_par);

Generates pseudo-random draws.


Examples:

// parameters
double shape = 5.0;
double scale = 4.0;

// standard input
double rand_val = stats::rinvgamma(shape,scale);

// Armadillo output: 10 x 1 matrix
arma::mat rand_mat = stats::rgamma<arma::mat>(10,1,shape,scale);