1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Inverse Gaussian (or Inverse Normal) 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_gamma_dist.html" title="Inverse Gamma Distribution"> 10<link rel="next" href="laplace_dist.html" title="Laplace 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_gamma_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="laplace_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_gaussian_dist"></a><a class="link" href="inverse_gaussian_dist.html" title="Inverse Gaussian (or Inverse Normal) Distribution">Inverse 28 Gaussian (or Inverse Normal) 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_gaussian</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_gaussian_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_gaussian_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">mean</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> 42 43 <span class="identifier">RealType</span> <span class="identifier">mean</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// mean default 1.</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> <span class="comment">// Optional scale, default 1 (unscaled).</span> 45 <span class="identifier">RealType</span> <span class="identifier">shape</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// Shape = scale/mean.</span> 46<span class="special">};</span> 47<span class="keyword">typedef</span> <span class="identifier">inverse_gaussian_distribution</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">inverse_gaussian</span><span class="special">;</span> 48 49<span class="special">}}</span> <span class="comment">// namespace boost // namespace math</span> 50</pre> 51<p> 52 The Inverse Gaussian distribution distribution is a continuous probability 53 distribution. 54 </p> 55<p> 56 The distribution is also called 'normal-inverse Gaussian distribution', 57 and 'normal Inverse' distribution. 58 </p> 59<p> 60 It is also convenient to provide unity as default for both mean and scale. 61 This is the Standard form for all distributions. The Inverse Gaussian distribution 62 was first studied in relation to Brownian motion. In 1956 M.C.K. Tweedie 63 used the name Inverse Gaussian because there is an inverse relationship 64 between the time to cover a unit distance and distance covered in unit 65 time. The inverse Gaussian is one of family of distributions that have 66 been called the <a href="http://en.wikipedia.org/wiki/Tweedie_distributions" target="_top">Tweedie 67 distributions</a>. 68 </p> 69<p> 70 (So <span class="emphasis"><em>inverse</em></span> in the name may mislead: it does <span class="bold"><strong>not</strong></span> relate to the inverse of a distribution). 71 </p> 72<p> 73 The tails of the distribution decrease more slowly than the normal distribution. 74 It is therefore suitable to model phenomena where numerically large values 75 are more probable than is the case for the normal distribution. For stock 76 market returns and prices, a key characteristic is that it models that 77 extremely large variations from typical (crashes) can occur even when almost 78 all (normal) variations are small. 79 </p> 80<p> 81 Examples are returns from financial assets and turbulent wind speeds. 82 </p> 83<p> 84 The normal-inverse Gaussian distributions form a subclass of the generalised 85 hyperbolic distributions. 86 </p> 87<p> 88 See <a href="http://en.wikipedia.org/wiki/Normal-inverse_Gaussian_distribution" target="_top">distribution</a>. 89 <a href="http://mathworld.wolfram.com/InverseGaussianDistribution.html" target="_top">Weisstein, 90 Eric W. "Inverse Gaussian Distribution." From MathWorld--A Wolfram 91 Web Resource.</a> 92 </p> 93<p> 94 If you want a <code class="computeroutput"><span class="keyword">double</span></code> precision 95 inverse_gaussian distribution you can use 96 </p> 97<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_gaussian_distribution</span><span class="special"><></span></pre> 98<p> 99 or, more conveniently, you can write 100 </p> 101<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">inverse_gaussian</span><span class="special">;</span> 102<span class="identifier">inverse_gaussian</span> <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> 103</pre> 104<p> 105 For mean parameters μ and scale (also called precision) parameter λ, and random 106 variate x, the inverse_gaussian distribution is defined by the probability 107 density function (PDF): 108 </p> 109<div class="blockquote"><blockquote class="blockquote"><p> 110 <span class="serif_italic">f(x;μ, λ) = √(λ/2πx<sup>3</sup>) e<sup>-λ(x-μ)²/2μ²x</sup> </span> 111 </p></blockquote></div> 112<p> 113 and Cumulative Density Function (CDF): 114 </p> 115<div class="blockquote"><blockquote class="blockquote"><p> 116 <span class="serif_italic">F(x;μ, λ) = Φ{√(λ<span class="emphasis"><em>x) (x</em></span>μ-1)} 117 + e<sup>2μ/λ</sup> Φ{-√(λ/μ) (1+x/μ)} </span> 118 </p></blockquote></div> 119<p> 120 where Φ is the standard normal distribution CDF. 121 </p> 122<p> 123 The following graphs illustrate how the PDF and CDF of the inverse_gaussian 124 distribution varies for a few values of parameters μ and λ: 125 </p> 126<div class="blockquote"><blockquote class="blockquote"><p> 127 <span class="inlinemediaobject"><img src="../../../../graphs/inverse_gaussian_pdf.svg" align="middle"></span> 128 129 </p></blockquote></div> 130<div class="blockquote"><blockquote class="blockquote"><p> 131 <span class="inlinemediaobject"><img src="../../../../graphs/inverse_gaussian_cdf.svg" align="middle"></span> 132 133 </p></blockquote></div> 134<p> 135 Tweedie also provided 3 other parameterisations where (μ and λ) are replaced 136 by their ratio φ = λ/μ and by 1/μ: these forms may be more suitable for Bayesian 137 applications. These can be found on Seshadri, page 2 and are also discussed 138 by Chhikara and Folks on page 105. Another related parameterisation, the 139 __wald_distrib (where mean μ is unity) is also provided. 140 </p> 141<h5> 142<a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.h0"></a> 143 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.member_functions"></a></span><a class="link" href="inverse_gaussian_dist.html#math_toolkit.dist_ref.dists.inverse_gaussian_dist.member_functions">Member 144 Functions</a> 145 </h5> 146<pre class="programlisting"><span class="identifier">inverse_gaussian_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">df</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> <span class="comment">// optionally scaled.</span> 147</pre> 148<p> 149 Constructs an inverse_gaussian distribution with μ mean, and scale λ, with 150 both default values 1. 151 </p> 152<p> 153 Requires that both the mean μ parameter and scale λ are greater than zero, 154 otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>. 155 </p> 156<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">mean</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> 157</pre> 158<p> 159 Returns the mean μ parameter of this distribution. 160 </p> 161<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> 162</pre> 163<p> 164 Returns the scale λ parameter of this distribution. 165 </p> 166<h5> 167<a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.h1"></a> 168 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.non_member_accessors"></a></span><a class="link" href="inverse_gaussian_dist.html#math_toolkit.dist_ref.dists.inverse_gaussian_dist.non_member_accessors">Non-member 169 Accessors</a> 170 </h5> 171<p> 172 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor 173 functions</a> that are generic to all distributions are supported: 174 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>, 175 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>, 176 <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>, 177 <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>, 178 <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>, 179 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>, 180 <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>, 181 <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>. 182 </p> 183<p> 184 The domain of the random variate is [0,+∞). 185 </p> 186<div class="note"><table border="0" summary="Note"> 187<tr> 188<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td> 189<th align="left">Note</th> 190</tr> 191<tr><td align="left" valign="top"><p> 192 Unlike some definitions, this implementation supports a random variate 193 equal to zero as a special case, returning zero for both pdf and cdf. 194 </p></td></tr> 195</table></div> 196<h5> 197<a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.h2"></a> 198 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.accuracy"></a></span><a class="link" href="inverse_gaussian_dist.html#math_toolkit.dist_ref.dists.inverse_gaussian_dist.accuracy">Accuracy</a> 199 </h5> 200<p> 201 The inverse_gaussian distribution is implemented in terms of the exponential 202 function and standard normal distribution <span class="emphasis"><em>N</em></span>0,1 Φ : refer 203 to the accuracy data for those functions for more information. But in general, 204 gamma (and thus inverse gamma) results are often accurate to a few epsilon, 205 >14 decimal digits accuracy for 64-bit double. 206 </p> 207<h5> 208<a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.h3"></a> 209 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.implementation"></a></span><a class="link" href="inverse_gaussian_dist.html#math_toolkit.dist_ref.dists.inverse_gaussian_dist.implementation">Implementation</a> 210 </h5> 211<p> 212 In the following table μ is the mean parameter and λ is the scale parameter 213 of the inverse_gaussian distribution, <span class="emphasis"><em>x</em></span> is the random 214 variate, <span class="emphasis"><em>p</em></span> is the probability and <span class="emphasis"><em>q = 1-p</em></span> 215 its complement. Parameters μ for shape and λ for scale are used for the inverse 216 gaussian function. 217 </p> 218<div class="informaltable"><table class="table"> 219<colgroup> 220<col> 221<col> 222</colgroup> 223<thead><tr> 224<th> 225 <p> 226 Function 227 </p> 228 </th> 229<th> 230 <p> 231 Implementation Notes 232 </p> 233 </th> 234</tr></thead> 235<tbody> 236<tr> 237<td> 238 <p> 239 pdf 240 </p> 241 </td> 242<td> 243 <p> 244 √(λ/ 2πx<sup>3</sup>) e<sup>-λ(x - μ)²/ 2μ²x</sup> 245 </p> 246 </td> 247</tr> 248<tr> 249<td> 250 <p> 251 cdf 252 </p> 253 </td> 254<td> 255 <p> 256 Φ{√(λ<span class="emphasis"><em>x) (x</em></span>μ-1)} + e<sup>2μ/λ</sup> Φ{-√(λ/μ) (1+x/μ)} 257 </p> 258 </td> 259</tr> 260<tr> 261<td> 262 <p> 263 cdf complement 264 </p> 265 </td> 266<td> 267 <p> 268 using complement of Φ above. 269 </p> 270 </td> 271</tr> 272<tr> 273<td> 274 <p> 275 quantile 276 </p> 277 </td> 278<td> 279 <p> 280 No closed form known. Estimated using a guess refined by Newton-Raphson 281 iteration. 282 </p> 283 </td> 284</tr> 285<tr> 286<td> 287 <p> 288 quantile from the complement 289 </p> 290 </td> 291<td> 292 <p> 293 No closed form known. Estimated using a guess refined by Newton-Raphson 294 iteration. 295 </p> 296 </td> 297</tr> 298<tr> 299<td> 300 <p> 301 mode 302 </p> 303 </td> 304<td> 305 <p> 306 μ {√(1+9μ²/4λ²)² - 3μ/2λ} 307 </p> 308 </td> 309</tr> 310<tr> 311<td> 312 <p> 313 median 314 </p> 315 </td> 316<td> 317 <p> 318 No closed form analytic equation is known, but is evaluated as 319 quantile(0.5) 320 </p> 321 </td> 322</tr> 323<tr> 324<td> 325 <p> 326 mean 327 </p> 328 </td> 329<td> 330 <p> 331 μ 332 </p> 333 </td> 334</tr> 335<tr> 336<td> 337 <p> 338 variance 339 </p> 340 </td> 341<td> 342 <p> 343 μ³/λ 344 </p> 345 </td> 346</tr> 347<tr> 348<td> 349 <p> 350 skewness 351 </p> 352 </td> 353<td> 354 <p> 355 3 √ (μ/λ) 356 </p> 357 </td> 358</tr> 359<tr> 360<td> 361 <p> 362 kurtosis_excess 363 </p> 364 </td> 365<td> 366 <p> 367 15μ/λ 368 </p> 369 </td> 370</tr> 371<tr> 372<td> 373 <p> 374 kurtosis 375 </p> 376 </td> 377<td> 378 <p> 379 12μ/λ 380 </p> 381 </td> 382</tr> 383</tbody> 384</table></div> 385<h5> 386<a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.h4"></a> 387 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_gaussian_dist.references"></a></span><a class="link" href="inverse_gaussian_dist.html#math_toolkit.dist_ref.dists.inverse_gaussian_dist.references">References</a> 388 </h5> 389<div class="orderedlist"><ol class="orderedlist" type="1"> 390<li class="listitem"> 391 Wald, A. (1947). Sequential analysis. Wiley, NY. 392 </li> 393<li class="listitem"> 394 The Inverse Gaussian distribution : theory, methodology, and applications, 395 Raj S. Chhikara, J. Leroy Folks. ISBN 0824779975 (1989). 396 </li> 397<li class="listitem"> 398 The Inverse Gaussian distribution : statistical theory and applications, 399 Seshadri, V , ISBN - 0387986189 (pbk) (Dewey 519.2) (1998). 400 </li> 401<li class="listitem"> 402 <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.wald.html" target="_top">Numpy 403 and Scipy Documentation</a>. 404 </li> 405<li class="listitem"> 406 <a href="http://bm2.genes.nig.ac.jp/RGM2/R_current/library/statmod/man/invgauss.html" target="_top">R 407 statmod invgauss functions</a>. 408 </li> 409<li class="listitem"> 410 <a href="http://cran.r-project.org/web/packages/SuppDists/index.html" target="_top">R 411 SuppDists invGauss functions</a>. (Note that these R implementations 412 names differ in case). 413 </li> 414<li class="listitem"> 415 <a href="http://www.statsci.org/s/invgauss.html" target="_top">StatSci.org invgauss 416 help</a>. 417 </li> 418<li class="listitem"> 419 <a href="http://www.statsci.org/s/invgauss.statSci.org" target="_top">invgauss 420 R source</a>. 421 </li> 422<li class="listitem"> 423 <a href="http://www.biostat.wustl.edu/archives/html/s-news/2001-12/msg00144.html" target="_top">pwald, 424 qwald</a>. 425 </li> 426<li class="listitem"> 427 <a href="http://www.brighton-webs.co.uk/distributions/wald.asp" target="_top">Brighton 428 Webs wald</a>. 429 </li> 430</ol></div> 431</div> 432<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 433<td align="left"></td> 434<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 435 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 436 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 437 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 438 Daryle Walker and Xiaogang Zhang<p> 439 Distributed under the Boost Software License, Version 1.0. (See accompanying 440 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>) 441 </p> 442</div></td> 443</tr></table> 444<hr> 445<div class="spirit-nav"> 446<a accesskey="p" href="inverse_gamma_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="laplace_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 447</div> 448</body> 449</html> 450