Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.
PrevUpHomeNext

Inverse Gamma Distribution

#include <boost/math/distributions/inverse_gamma.hpp>
namespace boost{ namespace math{

template <class RealType = double,
          class Policy   = policies::policy<> >
class inverse_gamma_distribution
{
public:
   typedef RealType value_type;
   typedef Policy   policy_type;

   inverse_gamma_distribution(RealType shape, RealType scale = 1)

   RealType shape()const;
   RealType scale()const;
};

}} // namespaces

The inverse_gamma distribution is a continuous probability distribution of the reciprocal of a variable distributed according to the gamma distribution.

The inverse_gamma distribution is used in Bayesian statistics.

See inverse gamma distribution.

R inverse gamma distribution functions.

Wolfram inverse gamma distribution.

See also Gamma Distribution.

[Note] Note

In spite of potential confusion with the inverse gamma function, this distribution does provide the typedef:

typedef inverse_gamma_distribution<double> gamma;

If you want a double precision gamma distribution you can use

boost::math::inverse_gamma_distribution<>

or you can write inverse_gamma my_ig(2, 3);

For shape parameter α and scale parameter β, it is defined by the probability density function (PDF):

   f(x;α, β) = βα * (1/x) α+1 exp(-β/x) / Γ(α)

and cumulative density function (CDF)

   F(x;α, β) = Γ(α, β/x) / Γ(α)

The following graphs illustrate how the PDF and CDF of the inverse gamma distribution varies as the parameters vary:

Member Functions
inverse_gamma_distribution(RealType shape = 1, RealType scale = 1);

Constructs an inverse gamma distribution with shape α and scale β.

Requires that the shape and scale parameters are greater than zero, otherwise calls domain_error.

RealType shape()const;

Returns the α shape parameter of this inverse gamma distribution.

RealType scale()const;

Returns the β scale parameter of this inverse gamma distribution.

Non-member Accessors

All the usual non-member accessor functions that are generic to all distributions are supported: Cumulative Distribution Function, Probability Density Function, Quantile, Hazard Function, Cumulative Hazard Function, mean, median, mode, variance, standard deviation, skewness, kurtosis, kurtosis_excess, range and support.

The domain of the random variate is [0,+∞].

[Note] Note

Unlike some definitions, this implementation supports a random variate equal to zero as a special case, returning zero for pdf and cdf.

Accuracy

The inverse gamma distribution is implemented in terms of the incomplete gamma functions gamma_p and gamma_q and their inverses gamma_p_inv and gamma_q_inv: refer to the accuracy data for those functions for more information. But in general, inverse_gamma results are accurate to a few epsilon, >14 decimal digits accuracy for 64-bit double.

Implementation

In the following table α is the shape parameter of the distribution, α   is its scale parameter, x is the random variate, p is the probability and q = 1-p.

Function

Implementation Notes

pdf

Using the relation: pdf = gamma_p_derivative(α, β/ x, β) / x * x

cdf

Using the relation: p = gamma_q(α, β / x)

cdf complement

Using the relation: q = gamma_p(α, β / x)

quantile

Using the relation: x = β  / gamma_q_inv(α, p)

quantile from the complement

Using the relation: x = α  / gamma_p_inv(α, q)

mode

β / (α + 1)

median

no analytic equation is known, but is evaluated as quantile(0.5)

mean

β / (α - 1) for α > 1, else a domain_error

variance

(β * β) / ((α - 1) * (α - 1) * (α - 2)) for α >2, else a domain_error

skewness

4 * sqrt (α -2) / (α -3) for α >3, else a domain_error

kurtosis_excess

(30 * α - 66) / ((α-3)*(α - 4)) for α >4, else a domain_error


PrevUpHomeNext