Inverse-Gamma Distribution

Table of contents


Density Function

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 \geq 0 ]\]

where \(\Gamma(\cdot)\) denotes the Gamma function, \(\alpha\) is the shape parameter, and \(\beta\) is the rate parameter.

Methods for scalar input, as well as for vector/matrix input, are listed below.

Scalar Input

template<typename T1, typename T2, typename T3>
constexpr common_return_t<T1, T2, T3> dinvgamma(const T1 x, const T2 shape_par, const T3 rate_par, const bool log_form = false) noexcept

Density function of the Inverse-Gamma distribution.

Example:

stats::dinvgamma(1.5,2,1,false); 

Parameters
  • x – a real-valued input.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • log_form – return the log-density or the true form.

Returns

the density function evaluated at x.

Vector/Matrix Input

STL Containers

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>>
inline std::vector<rT> dinvgamma(const std::vector<eT> &x, const T1 shape_par, const T2 rate_par, const bool log_form = false)

Density function of the Inverse-Gamma distribution.

Example:

std::vector<double> x = {1.8, 0.7, 4.2};
stats::dinvgamma(x,3.0,2.0,false);

Parameters
  • x – a standard vector.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • log_form – return the log-density or the true form.

Returns

a vector of density function values corresponding to the elements of x.

Armadillo

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>>
inline ArmaMat<rT> dinvgamma(const ArmaMat<eT> &X, const T1 shape_par, const T2 rate_par, const bool log_form = false)

Density function of the Inverse-Gamma distribution.

Example:

arma::mat X = { {1.8, 0.7, 4.2},
                {0.3, 5.3, 3.7} };
stats::dinvgamma(X,3.0,2.0,false);

Parameters
  • X – a matrix of input values.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • log_form – return the log-density or the true form.

Returns

a matrix of density function values corresponding to the elements of X.

Blaze

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>, bool To = blaze::columnMajor>
inline BlazeMat<rT, To> dinvgamma(const BlazeMat<eT, To> &X, const T1 shape_par, const T2 rate_par, const bool log_form = false)

Density function of the Inverse-Gamma distribution.

Example:

stats::dinvgamma(X,3.0,2.0,false);

Parameters
  • X – a matrix of input values.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • log_form – return the log-density or the true form.

Returns

a matrix of density function values corresponding to the elements of X.

Eigen

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>, int iTr = Eigen::Dynamic, int iTc = Eigen::Dynamic>
inline EigenMat<rT, iTr, iTc> dinvgamma(const EigenMat<eT, iTr, iTc> &X, const T1 shape_par, const T2 rate_par, const bool log_form = false)

Density function of the Inverse-Gamma distribution.

Example:

stats::dinvgamma(X,3.0,2.0,false);

Parameters
  • X – a matrix of input values.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • log_form – return the log-density or the true form.

Returns

a matrix of density function values corresponding to the elements of X.


Cumulative Distribution Function

The cumulative distribution function of the inverse-Gamma distribution:

\[F(x; \alpha, \beta) = \int_0^x f(z; \alpha, \beta) dz = 1 - \frac{\gamma(1/x,\beta/x)}{\Gamma (\alpha)}\]

where \(\Gamma(\cdot)\) denotes the gamma function and \(\gamma(\cdot, \cdot)\) denotes the incomplete gamma function.

Methods for scalar input, as well as for vector/matrix input, are listed below.

Scalar Input

template<typename T1, typename T2, typename T3>
constexpr common_return_t<T1, T2, T3> pinvgamma(const T1 x, const T2 shape_par, const T3 rate_par, const bool log_form = false) noexcept

Distribution function of the Inverse-Gamma distribution.

Example:

stats::pinvgamma(1.5,2,1,false); 

Parameters
  • x – a real-valued input.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • log_form – return the log-probability or the true form.

Returns

the cumulative distribution function evaluated at x.

Vector/Matrix Input

STL Containers

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>>
inline std::vector<rT> pinvgamma(const std::vector<eT> &x, const T1 shape_par, const T2 rate_par, const bool log_form = false)

Distribution function of the Inverse-Gamma distribution.

Example:

std::vector<double> x = {1.8, 0.7, 4.2};
stats::pinvgamma(x,3.0,2.0,false);

Parameters
  • x – a standard vector.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • log_form – return the log-probability or the true form.

Returns

a vector of CDF values corresponding to the elements of x.

Armadillo

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>>
inline ArmaMat<rT> pinvgamma(const ArmaMat<eT> &X, const T1 shape_par, const T2 rate_par, const bool log_form = false)

Distribution function of the Inverse-Gamma distribution.

Example:

arma::mat X = { {1.8, 0.7, 4.2},
                {0.3, 5.3, 3.7} };
stats::pinvgamma(X,3.0,2.0,false);

Parameters
  • X – a matrix of input values.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • log_form – return the log-probability or the true form.

Returns

a matrix of CDF values corresponding to the elements of X.

Blaze

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>, bool To = blaze::columnMajor>
inline BlazeMat<rT, To> pinvgamma(const BlazeMat<eT, To> &X, const T1 shape_par, const T2 rate_par, const bool log_form = false)

Distribution function of the Inverse-Gamma distribution.

Example:

stats::pinvgamma(X,3.0,2.0,false);

Parameters
  • X – a matrix of input values.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • log_form – return the log-probability or the true form.

Returns

a matrix of CDF values corresponding to the elements of X.

Eigen

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>, int iTr = Eigen::Dynamic, int iTc = Eigen::Dynamic>
inline EigenMat<rT, iTr, iTc> pinvgamma(const EigenMat<eT, iTr, iTc> &X, const T1 shape_par, const T2 rate_par, const bool log_form = false)

Distribution function of the Inverse-Gamma distribution.

Example:

stats::pinvgamma(X,3.0,2.0,false);

Parameters
  • X – a matrix of input values.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • log_form – return the log-probability or the true form.

Returns

a matrix of CDF values corresponding to the elements of X.


Quantile Function

The quantile function of the inverse-Gamma distribution:

\[q(p; \alpha, \beta) = \inf \left\{ x : p \leq 1 - \frac{\gamma(1/x,\beta/x)}{\Gamma (\alpha)} \right\}\]

where \(\Gamma(\cdot)\) denotes the gamma function and \(\gamma(\cdot, \cdot)\) denotes the incomplete gamma function.

Methods for scalar input, as well as for vector/matrix input, are listed below.

Scalar Input

template<typename T1, typename T2, typename T3>
constexpr common_return_t<T1, T2, T3> qinvgamma(const T1 p, const T2 shape_par, const T3 rate_par) noexcept

Quantile function of the Inverse-Gamma distribution.

Example:

stats::qinvgamma(0.5,2,1); 

Parameters
  • p – a real-valued input.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

Returns

the quantile function evaluated at p.

Vector/Matrix Input

STL Containers

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>>
inline std::vector<rT> qinvgamma(const std::vector<eT> &x, const T1 shape_par, const T2 rate_par)

Quantile function of the Inverse-Gamma distribution.

Example:

std::vector<double> x = {0.3, 0.5, 0.9};
stats::qinvgamma(x,3.0,2.0);

Parameters
  • x – a standard vector.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

Returns

a vector of quantile values corresponding to the elements of x.

Armadillo

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>>
inline ArmaMat<rT> qinvgamma(const ArmaMat<eT> &X, const T1 shape_par, const T2 rate_par)

Quantile function of the Inverse-Gamma distribution.

Example:

arma::mat X = { {0.2,  0.7,  0.1},
                {0.9,  0.3,  0.87} };
stats::qinvgamma(X,3.0,2.0);

Parameters
  • X – a matrix of input values.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

Returns

a matrix of quantile values corresponding to the elements of X.

Blaze

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>, bool To = blaze::columnMajor>
inline BlazeMat<rT, To> qinvgamma(const BlazeMat<eT, To> &X, const T1 shape_par, const T2 rate_par)

Quantile function of the Inverse-Gamma distribution.

Example:

stats::qinvgamma(X,3.0,2.0);

Parameters
  • X – a matrix of input values.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

Returns

a matrix of quantile values corresponding to the elements of X.

Eigen

template<typename eT, typename T1, typename T2, typename rT = common_return_t<eT, T1, T2>, int iTr = Eigen::Dynamic, int iTc = Eigen::Dynamic>
inline EigenMat<rT, iTr, iTc> qinvgamma(const EigenMat<eT, iTr, iTc> &X, const T1 shape_par, const T2 rate_par)

Quantile function of the Inverse-Gamma distribution.

Example:

stats::qinvgamma(X,3.0,2.0);

Parameters
  • X – a matrix of input values.

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

Returns

a matrix of quantile values corresponding to the elements of X.


Random Sampling

Random sampling for the inverse-Gamma distribution is achieved by simulating \(X \sim G(\alpha, 1/\beta)\), then returning

\[Z = \frac{1}{X} \sim \text{IG}(\alpha,\beta)\]

Scalar Output

  1. Random number engines

template<typename T1, typename T2>
inline common_return_t<T1, T2> rinvgamma(const T1 shape_par, const T2 rate_par, rand_engine_t &engine)

Random sampling function for the Inverse-Gamma distribution.

Example:

stats::rand_engine_t engine(1776);
stats::rinvgamma(3.0,2.0,engine);

Parameters
  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • engine – a random engine, passed by reference.

Returns

a pseudo-random draw from the Inverse-Gamma distribution.

  1. Seed values

template<typename T1, typename T2>
inline common_return_t<T1, T2> rinvgamma(const T1 shape_par, const T2 rate_par, const ullint_t seed_val = std::random_device{}())

Random sampling function for the Inverse-Gamma distribution.

Example:

stats::rinvgamma(3.0,2.0,1776);

Parameters
  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • seed_val – initialize the random engine with a non-negative integral-valued seed.

Returns

a pseudo-random draw from the Inverse-Gamma distribution.

Vector/Matrix Output

  1. Random number engines

template<typename mT, typename T1, typename T2>
inline mT rinvgamma(const ullint_t n, const ullint_t k, const T1 shape_par, const T2 rate_par, rand_engine_t &engine)

Random matrix sampling function for the Inverse-Gamma distribution.

Example:

stats::rand_engine_t engine(1776);
// std::vector
stats::rinvgamma<std::vector<double>>(5,4,3.0,2.0,engine);
// Armadillo matrix
stats::rinvgamma<arma::mat>(5,4,3.0,2.0,engine);
// Blaze dynamic matrix
stats::rinvgamma<blaze::DynamicMatrix<double,blaze::columnMajor>>(5,4,3.0,2.0,engine);
// Eigen dynamic matrix
stats::rinvgamma<Eigen::MatrixXd>(5,4,3.0,2.0,engine);

Note

This function requires template instantiation; acceptable output types include: std::vector, with element type float, double, etc., as well as Armadillo, Blaze, and Eigen dense matrices.

Parameters
  • n – the number of output rows

  • k – the number of output columns

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • engine – a random engine, passed by reference.

Returns

a matrix of pseudo-random draws from the Inverse-Gamma distribution.

  1. Seed values

template<typename mT, typename T1, typename T2>
inline mT rinvgamma(const ullint_t n, const ullint_t k, const T1 shape_par, const T2 rate_par, const ullint_t seed_val = std::random_device{}())

Random matrix sampling function for the Inverse-Gamma distribution.

Example:

// std::vector
stats::rinvgamma<std::vector<double>>(5,4,3.0,2.0);
// Armadillo matrix
stats::rinvgamma<arma::mat>(5,4,3.0,2.0);
// Blaze dynamic matrix
stats::rinvgamma<blaze::DynamicMatrix<double,blaze::columnMajor>>(5,4,3.0,2.0);
// Eigen dynamic matrix
stats::rinvgamma<Eigen::MatrixXd>(5,4,3.0,2.0);

Note

This function requires template instantiation; acceptable output types include: std::vector, with element type float, double, etc., as well as Armadillo, Blaze, and Eigen dense matrices.

Parameters
  • n – the number of output rows

  • k – the number of output columns

  • shape_par – the shape parameter, a real-valued input.

  • rate_par – the rate parameter, a real-valued input.

  • seed_val – initialize the random engine with a non-negative integral-valued seed.

Returns

a matrix of pseudo-random draws from the Inverse-Gamma distribution.