1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 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.12.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"> 11</head> 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> 20</tr></table> 21<hr> 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> 24</div> 25<div class="section"> 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> 32 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 21. 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> 40 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> 42 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> 46 47<span class="special">}}</span> <span class="comment">// namespaces</span> 48</pre> 49<p> 50 The inverse_gamma distribution is a continuous probability distribution 51 of the reciprocal of a variable distributed according to the gamma distribution. 52 </p> 53<p> 54 The inverse_gamma distribution is used in Bayesian statistics. 55 </p> 56<p> 57 See <a href="http://en.wikipedia.org/wiki/Inverse-gamma_distribution" target="_top">inverse 58 gamma distribution</a>. 59 </p> 60<p> 61 <a href="http://rss.acs.unt.edu/Rdoc/library/pscl/html/igamma.html" target="_top">R 62 inverse gamma distribution functions</a>. 63 </p> 64<p> 65 <a href="http://reference.wolfram.com/mathematica/ref/InverseGammaDistribution.html" target="_top">Wolfram 66 inverse gamma distribution</a>. 67 </p> 68<p> 69 See also <a class="link" href="gamma_dist.html" title="Gamma (and Erlang) Distribution">Gamma Distribution</a>. 70 </p> 71<div class="note"><table border="0" summary="Note"> 72<tr> 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> 75</tr> 76<tr><td align="left" valign="top"> 77<p> 78 In spite of potential confusion with the inverse gamma function, this 79 distribution <span class="bold"><strong>does</strong></span> provide the typedef: 80 </p> 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> 82<p> 83 If you want a <code class="computeroutput"><span class="keyword">double</span></code> precision 84 gamma distribution you can use 85 </p> 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> 87<p> 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> 90 </p> 91</td></tr> 92</table></div> 93<p> 94 For shape parameter α and scale parameter β, it is defined by the probability 95 density function (PDF): 96 </p> 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> 100<p> 101 and cumulative density function (CDF) 102 </p> 103<div class="blockquote"><blockquote class="blockquote"><p> 104 <span class="serif_italic">F(x;α, β) = Γ(α, β/x) / Γ(α)</span> 105 </p></blockquote></div> 106<p> 107 The following graphs illustrate how the PDF and CDF of the inverse gamma 108 distribution varies as the parameters vary: 109 </p> 110<div class="blockquote"><blockquote class="blockquote"><p> 111 <span class="inlinemediaobject"><img src="../../../../graphs/inverse_gamma_pdf.svg" align="middle"></span> 112 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> 116 117 </p></blockquote></div> 118<h5> 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 121 Functions</a> 122 </h5> 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> 124</pre> 125<p> 126 Constructs an inverse gamma distribution with shape α and scale β. 127 </p> 128<p> 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>. 131 </p> 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> 133</pre> 134<p> 135 Returns the α shape parameter of this inverse gamma distribution. 136 </p> 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> 138</pre> 139<p> 140 Returns the β scale parameter of this inverse gamma distribution. 141 </p> 142<h5> 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 145 Accessors</a> 146 </h5> 147<p> 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>. 158 </p> 159<p> 160 The domain of the random variate is [0,+∞]. 161 </p> 162<div class="note"><table border="0" summary="Note"> 163<tr> 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> 166</tr> 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. 170 </p></td></tr> 171</table></div> 172<h5> 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> 175 </h5> 176<p> 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. 185 </p> 186<h5> 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> 189 </h5> 190<p> 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>. 194 </p> 195<div class="informaltable"><table class="table"> 196<colgroup> 197<col> 198<col> 199</colgroup> 200<thead><tr> 201<th> 202 <p> 203 Function 204 </p> 205 </th> 206<th> 207 <p> 208 Implementation Notes 209 </p> 210 </th> 211</tr></thead> 212<tbody> 213<tr> 214<td> 215 <p> 216 pdf 217 </p> 218 </td> 219<td> 220 <p> 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 223 </p> 224 </td> 225</tr> 226<tr> 227<td> 228 <p> 229 cdf 230 </p> 231 </td> 232<td> 233 <p> 234 Using the relation: p = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a>(α, 235 β / x) 236 </p> 237 </td> 238</tr> 239<tr> 240<td> 241 <p> 242 cdf complement 243 </p> 244 </td> 245<td> 246 <p> 247 Using the relation: q = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>(α, 248 β / x) 249 </p> 250 </td> 251</tr> 252<tr> 253<td> 254 <p> 255 quantile 256 </p> 257 </td> 258<td> 259 <p> 260 Using the relation: x = β/ <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>(α, 261 p) 262 </p> 263 </td> 264</tr> 265<tr> 266<td> 267 <p> 268 quantile from the complement 269 </p> 270 </td> 271<td> 272 <p> 273 Using the relation: x = α/ <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a>(α, 274 q) 275 </p> 276 </td> 277</tr> 278<tr> 279<td> 280 <p> 281 mode 282 </p> 283 </td> 284<td> 285 <p> 286 β / (α + 1) 287 </p> 288 </td> 289</tr> 290<tr> 291<td> 292 <p> 293 median 294 </p> 295 </td> 296<td> 297 <p> 298 no analytic equation is known, but is evaluated as quantile(0.5) 299 </p> 300 </td> 301</tr> 302<tr> 303<td> 304 <p> 305 mean 306 </p> 307 </td> 308<td> 309 <p> 310 β / (α - 1) for α > 1, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a> 311 </p> 312 </td> 313</tr> 314<tr> 315<td> 316 <p> 317 variance 318 </p> 319 </td> 320<td> 321 <p> 322 (β * β) / ((α - 1) * (α - 1) * (α - 2)) for α >2, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a> 323 </p> 324 </td> 325</tr> 326<tr> 327<td> 328 <p> 329 skewness 330 </p> 331 </td> 332<td> 333 <p> 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> 335 </p> 336 </td> 337</tr> 338<tr> 339<td> 340 <p> 341 kurtosis_excess 342 </p> 343 </td> 344<td> 345 <p> 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> 347 </p> 348 </td> 349</tr> 350</tbody> 351</table></div> 352</div> 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>) 362 </p> 363</div></td> 364</tr></table> 365<hr> 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> 368</div> 369</body> 370</html> 371