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