inverse_gamma.qbk 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. [section:inverse_gamma_dist Inverse Gamma Distribution]
  2. ``#include <boost/math/distributions/inverse_gamma.hpp>``
  3. namespace boost{ namespace math{
  4. template <class RealType = double,
  5. class ``__Policy`` = ``__policy_class`` >
  6. class inverse_gamma_distribution
  7. {
  8. public:
  9. typedef RealType value_type;
  10. typedef Policy policy_type;
  11. inverse_gamma_distribution(RealType shape, RealType scale = 1)
  12. RealType shape()const;
  13. RealType scale()const;
  14. };
  15. }} // namespaces
  16. The inverse_gamma distribution is a continuous probability distribution
  17. of the reciprocal of a variable distributed according to the gamma distribution.
  18. The inverse_gamma distribution is used in Bayesian statistics.
  19. See [@http://en.wikipedia.org/wiki/Inverse-gamma_distribution inverse gamma distribution].
  20. [@http://rss.acs.unt.edu/Rdoc/library/pscl/html/igamma.html R inverse gamma distribution functions].
  21. [@http://reference.wolfram.com/mathematica/ref/InverseGammaDistribution.html Wolfram inverse gamma distribution].
  22. See also __gamma_distrib.
  23. [note
  24. In spite of potential confusion with the inverse gamma function, this
  25. distribution *does* provide the typedef:
  26. ``typedef inverse_gamma_distribution<double> gamma;``
  27. If you want a `double` precision gamma distribution you can use
  28. ``boost::math::inverse_gamma_distribution<>``
  29. or you can write `inverse_gamma my_ig(2, 3);`]
  30. For shape parameter [alpha] and scale parameter [beta], it is defined
  31. by the probability density function (PDF):
  32. [expression f(x;[alpha], [beta]) = [beta][super [alpha]] * (1/x) [super [alpha]+1] exp(-[beta]/x) / [Gamma]([alpha])]
  33. and cumulative density function (CDF)
  34. [expression F(x;[alpha], [beta]) = [Gamma]([alpha], [beta]/x) / [Gamma]([alpha])]
  35. The following graphs illustrate how the PDF and CDF of the inverse gamma distribution
  36. varies as the parameters vary:
  37. [graph inverse_gamma_pdf] [/png or svg]
  38. [graph inverse_gamma_cdf]
  39. [h4 Member Functions]
  40. inverse_gamma_distribution(RealType shape = 1, RealType scale = 1);
  41. Constructs an inverse gamma distribution with shape [alpha] and scale [beta].
  42. Requires that the shape and scale parameters are greater than zero, otherwise calls
  43. __domain_error.
  44. RealType shape()const;
  45. Returns the [alpha] shape parameter of this inverse gamma distribution.
  46. RealType scale()const;
  47. Returns the [beta] scale parameter of this inverse gamma distribution.
  48. [h4 Non-member Accessors]
  49. All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions] that are generic to all
  50. distributions are supported: __usual_accessors.
  51. The domain of the random variate is \[0,+[infin]\].
  52. [note Unlike some definitions, this implementation supports a random variate
  53. equal to zero as a special case, returning zero for pdf and cdf.]
  54. [h4 Accuracy]
  55. The inverse gamma distribution is implemented in terms of the
  56. incomplete gamma functions __gamma_p and __gamma_q and their
  57. inverses __gamma_p_inv and __gamma_q_inv: refer to the accuracy
  58. data for those functions for more information.
  59. But in general, inverse_gamma results are accurate to a few epsilon,
  60. >14 decimal digits accuracy for 64-bit double.
  61. [h4 Implementation]
  62. In the following table [alpha] is the shape parameter of the distribution,
  63. [alpha] is its scale parameter, /x/ is the random variate, /p/ is the probability
  64. and /q = 1-p/.
  65. [table
  66. [[Function][Implementation Notes]]
  67. [[pdf][Using the relation: pdf = __gamma_p_derivative([alpha], [beta]/ x, [beta]) / x * x ]]
  68. [[cdf][Using the relation: p = __gamma_q([alpha], [beta] / x) ]]
  69. [[cdf complement][Using the relation: q = __gamma_p([alpha], [beta] / x) ]]
  70. [[quantile][Using the relation: x = [beta]/ __gamma_q_inv([alpha], p) ]]
  71. [[quantile from the complement][Using the relation: x = [alpha]/ __gamma_p_inv([alpha], q) ]]
  72. [[mode][[beta] / ([alpha] + 1) ]]
  73. [[median][no analytic equation is known, but is evaluated as quantile(0.5)]]
  74. [[mean][[beta] / ([alpha] - 1) for [alpha] > 1, else a __domain_error]]
  75. [[variance][([beta] * [beta]) / (([alpha] - 1) * ([alpha] - 1) * ([alpha] - 2)) for [alpha] >2, else a __domain_error]]
  76. [[skewness][4 * sqrt ([alpha] -2) / ([alpha] -3) for [alpha] >3, else a __domain_error]]
  77. [[kurtosis_excess][(30 * [alpha] - 66) / (([alpha]-3)*([alpha] - 4)) for [alpha] >4, else a __domain_error]]
  78. ] [/table]
  79. [endsect] [/section:inverse_gamma_dist Inverse Gamma Distribution]
  80. [/
  81. Copyright 2010 John Maddock and Paul A. Bristow.
  82. Distributed under the Boost Software License, Version 1.0.
  83. (See accompanying file LICENSE_1_0.txt or copy at
  84. http://www.boost.org/LICENSE_1_0.txt).
  85. ]