3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Inverse Gamma Distribution</title>
5 <link rel="stylesheet" href="../../../math.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../../index.html" title="Math Toolkit 2.11.0">
8 <link rel="up" href="../dists.html" title="Distributions">
9 <link rel="prev" href="inverse_chi_squared_dist.html" title="Inverse Chi Squared Distribution">
10 <link rel="next" href="inverse_gaussian_dist.html" title="Inverse Gaussian (or Inverse Normal) Distribution">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="inverse_chi_squared_dist.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="inverse_gaussian_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h4 class="title">
27 <a name="math_toolkit.dist_ref.dists.inverse_gamma_dist"></a><a class="link" href="inverse_gamma_dist.html" title="Inverse Gamma Distribution">Inverse
28 Gamma Distribution</a>
29 </h4></div></div></div>
30 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">inverse_gamma</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></pre>
31 <pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
33 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">RealType</span> <span class="special">=</span> <span class="keyword">double</span><span class="special">,</span>
34 <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> <span class="special">=</span> <a class="link" href="../../pol_ref/pol_ref_ref.html" title="Policy Class Reference">policies::policy<></a> <span class="special">></span>
35 <span class="keyword">class</span> <span class="identifier">inverse_gamma_distribution</span>
36 <span class="special">{</span>
37 <span class="keyword">public</span><span class="special">:</span>
38 <span class="keyword">typedef</span> <span class="identifier">RealType</span> <span class="identifier">value_type</span><span class="special">;</span>
39 <span class="keyword">typedef</span> <span class="identifier">Policy</span> <span class="identifier">policy_type</span><span class="special">;</span>
41 <span class="identifier">inverse_gamma_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">)</span>
43 <span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
44 <span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
45 <span class="special">};</span>
47 <span class="special">}}</span> <span class="comment">// namespaces</span>
50 The inverse_gamma distribution is a continuous probability distribution
51 of the reciprocal of a variable distributed according to the gamma distribution.
54 The inverse_gamma distribution is used in Bayesian statistics.
57 See <a href="http://en.wikipedia.org/wiki/Inverse-gamma_distribution" target="_top">inverse
58 gamma distribution</a>.
61 <a href="http://rss.acs.unt.edu/Rdoc/library/pscl/html/igamma.html" target="_top">R
62 inverse gamma distribution functions</a>.
65 <a href="http://reference.wolfram.com/mathematica/ref/InverseGammaDistribution.html" target="_top">Wolfram
66 inverse gamma distribution</a>.
69 See also <a class="link" href="gamma_dist.html" title="Gamma (and Erlang) Distribution">Gamma Distribution</a>.
71 <div class="note"><table border="0" summary="Note">
73 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
74 <th align="left">Note</th>
76 <tr><td align="left" valign="top">
78 In spite of potential confusion with the inverse gamma function, this
79 distribution <span class="bold"><strong>does</strong></span> provide the typedef:
81 <pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">inverse_gamma_distribution</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">gamma</span><span class="special">;</span></pre>
83 If you want a <code class="computeroutput"><span class="keyword">double</span></code> precision
84 gamma distribution you can use
86 <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">inverse_gamma_distribution</span><span class="special"><></span></pre>
88 or you can write <code class="computeroutput"><span class="identifier">inverse_gamma</span>
89 <span class="identifier">my_ig</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">);</span></code>
94 For shape parameter α and scale parameter β, it is defined by the probability
95 density function (PDF):
97 <div class="blockquote"><blockquote class="blockquote"><p>
98 <span class="serif_italic">f(x;α, β) = β<sup>α</sup> * (1/x) <sup>α+1</sup> exp(-β/x) / Γ(α)</span>
99 </p></blockquote></div>
101 and cumulative density function (CDF)
103 <div class="blockquote"><blockquote class="blockquote"><p>
104 <span class="serif_italic">F(x;α, β) = Γ(α, β/x) / Γ(α)</span>
105 </p></blockquote></div>
107 The following graphs illustrate how the PDF and CDF of the inverse gamma
108 distribution varies as the parameters vary:
110 <div class="blockquote"><blockquote class="blockquote"><p>
111 <span class="inlinemediaobject"><img src="../../../../graphs/inverse_gamma_pdf.svg" align="middle"></span>
113 </p></blockquote></div>
114 <div class="blockquote"><blockquote class="blockquote"><p>
115 <span class="inlinemediaobject"><img src="../../../../graphs/inverse_gamma_cdf.svg" align="middle"></span>
117 </p></blockquote></div>
119 <a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.h0"></a>
120 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.member_functions"></a></span><a class="link" href="inverse_gamma_dist.html#math_toolkit.dist_ref.dists.inverse_gamma_dist.member_functions">Member
123 <pre class="programlisting"><span class="identifier">inverse_gamma_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">shape</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
126 Constructs an inverse gamma distribution with shape α and scale β.
129 Requires that the shape and scale parameters are greater than zero, otherwise
130 calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
132 <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
135 Returns the α shape parameter of this inverse gamma distribution.
137 <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
140 Returns the β scale parameter of this inverse gamma distribution.
143 <a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.h1"></a>
144 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.non_member_accessors"></a></span><a class="link" href="inverse_gamma_dist.html#math_toolkit.dist_ref.dists.inverse_gamma_dist.non_member_accessors">Non-member
148 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
149 functions</a> that are generic to all distributions are supported:
150 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
151 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
152 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.hazard">Hazard Function</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.chf">Cumulative Hazard Function</a>,
153 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mean">mean</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.median">median</a>,
154 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mode">mode</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.variance">variance</a>,
155 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
156 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.skewness">skewness</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis">kurtosis</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess">kurtosis_excess</a>,
157 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.range">range</a> and <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.support">support</a>.
160 The domain of the random variate is [0,+∞].
162 <div class="note"><table border="0" summary="Note">
164 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
165 <th align="left">Note</th>
167 <tr><td align="left" valign="top"><p>
168 Unlike some definitions, this implementation supports a random variate
169 equal to zero as a special case, returning zero for pdf and cdf.
173 <a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.h2"></a>
174 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.accuracy"></a></span><a class="link" href="inverse_gamma_dist.html#math_toolkit.dist_ref.dists.inverse_gamma_dist.accuracy">Accuracy</a>
177 The inverse gamma distribution is implemented in terms of the incomplete
178 gamma functions <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>
179 and <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a> and their
180 inverses <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a>
181 and <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>:
182 refer to the accuracy data for those functions for more information. But
183 in general, inverse_gamma results are accurate to a few epsilon, >14
184 decimal digits accuracy for 64-bit double.
187 <a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.h3"></a>
188 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gamma_dist.implementation"></a></span><a class="link" href="inverse_gamma_dist.html#math_toolkit.dist_ref.dists.inverse_gamma_dist.implementation">Implementation</a>
191 In the following table α is the shape parameter of the distribution, α is its
192 scale parameter, <span class="emphasis"><em>x</em></span> is the random variate, <span class="emphasis"><em>p</em></span>
193 is the probability and <span class="emphasis"><em>q = 1-p</em></span>.
195 <div class="informaltable"><table class="table">
221 Using the relation: pdf = <a class="link" href="../../sf_gamma/gamma_derivatives.html" title="Derivative of the Incomplete Gamma Function">gamma_p_derivative</a>(α,
222 β/ x, β) / x * x
234 Using the relation: p = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a>(α,
247 Using the relation: q = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>(α,
260 Using the relation: x = β/ <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>(α,
268 quantile from the complement
273 Using the relation: x = α/ <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a>(α,
286 β / (α + 1)
298 no analytic equation is known, but is evaluated as quantile(0.5)
310 β / (α - 1) for α > 1, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
322 (β * β) / ((α - 1) * (α - 1) * (α - 2)) for α >2, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
334 4 * sqrt (α -2) / (α -3) for α >3, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
346 (30 * α - 66) / ((α-3)*(α - 4)) for α >4, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
353 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
354 <td align="left"></td>
355 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
356 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
357 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
358 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
359 Daryle Walker and Xiaogang Zhang<p>
360 Distributed under the Boost Software License, Version 1.0. (See accompanying
361 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
366 <div class="spirit-nav">
367 <a accesskey="p" href="inverse_chi_squared_dist.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="inverse_gaussian_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>