File: inverse_gaussian.qbk

package info (click to toggle)
boost1.74 1.74.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 464,084 kB
  • sloc: cpp: 3,338,324; xml: 131,293; python: 33,088; ansic: 14,336; asm: 4,034; sh: 3,351; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (171 lines) | stat: -rw-r--r-- 7,598 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
[section:inverse_gaussian_dist Inverse Gaussian (or Inverse Normal) Distribution]

``#include <boost/math/distributions/inverse_gaussian.hpp>``

   namespace boost{ namespace math{ 
      
   template <class RealType = double, 
             class ``__Policy``   = ``__policy_class`` >
   class inverse_gaussian_distribution
   {
   public:
      typedef RealType value_type;
      typedef Policy   policy_type;

      inverse_gaussian_distribution(RealType mean = 1, RealType scale = 1);

      RealType mean()const; // mean default 1.
      RealType scale()const; // Optional scale, default 1 (unscaled).
      RealType shape()const; // Shape = scale/mean.
   };
   typedef inverse_gaussian_distribution<double> inverse_gaussian;

   }} // namespace boost // namespace math
   
The Inverse Gaussian distribution distribution is a continuous probability distribution.

The distribution is also called 'normal-inverse Gaussian distribution',
and 'normal Inverse' distribution.

It is also convenient to provide unity as default for both mean and scale.
This is the Standard form for all distributions.
The Inverse Gaussian distribution was first studied in relation to Brownian motion.
In 1956 M.C.K. Tweedie used the name Inverse Gaussian because there is an inverse relationship
between the time to cover a unit distance and distance covered in unit time.
The inverse Gaussian is one of family of distributions that have been called the
[@http://en.wikipedia.org/wiki/Tweedie_distributions Tweedie distributions].

(So ['inverse] in the name may mislead: it does [*not] relate to the inverse of a distribution).

The tails of the distribution decrease more slowly than the normal distribution.
It is therefore suitable to model phenomena
where numerically large values are more probable than is the case for the normal distribution.
For stock market returns and prices, a key characteristic is that it models 
that extremely large variations from typical (crashes) can occur
even when almost all (normal) variations are small.

Examples are returns from financial assets and turbulent wind speeds. 

The normal-inverse Gaussian distributions form
a subclass of the generalised hyperbolic distributions.

See 
[@http://en.wikipedia.org/wiki/Normal-inverse_Gaussian_distribution distribution].
[@http://mathworld.wolfram.com/InverseGaussianDistribution.html 
  Weisstein, Eric W. "Inverse Gaussian Distribution." From MathWorld--A Wolfram Web Resource.]
  
If you want a `double` precision inverse_gaussian distribution you can use 

``boost::math::inverse_gaussian_distribution<>``

or, more conveniently, you can write

  using boost::math::inverse_gaussian;
  inverse_gaussian my_ig(2, 3);

For mean parameters [mu] and scale (also called precision) parameter [lambda],
and random variate x,
the inverse_gaussian distribution is defined by the probability density function (PDF):

[expression f(x;[mu], [lambda]) = [sqrt]([lambda]/2[pi]x[super 3]) e[super -[lambda](x-[mu])[sup2]/2[mu][sup2]x] ]

and Cumulative Density Function (CDF):

[expression  F(x;[mu], [lambda]) = [Phi]{[sqrt]([lambda]/x) (x/[mu]-1)} + e[super 2[mu]/[lambda]] [Phi]{-[sqrt]([lambda]/[mu]) (1+x/[mu])} ]

where [Phi] is the standard normal distribution CDF.

The following graphs illustrate how the PDF and CDF of the inverse_gaussian distribution
varies for a few values of parameters [mu] and [lambda]:

[graph inverse_gaussian_pdf]  [/.png or .svg]

[graph inverse_gaussian_cdf]

Tweedie also provided 3 other parameterisations where ([mu] and [lambda])
are replaced by their ratio [phi] = [lambda]/[mu] and by 1/[mu]:
these forms may be more suitable for Bayesian applications. 
These can be found on Seshadri, page 2 and are also discussed by Chhikara and Folks on page 105.
Another related parameterisation, the __wald_distrib (where mean [mu] is unity) is also provided.

[h4 Member Functions]

   inverse_gaussian_distribution(RealType df = 1, RealType scale = 1); // optionally scaled.

Constructs an inverse_gaussian distribution with [mu] mean,
and scale [lambda], with both default values 1.

Requires that both the mean [mu] parameter and scale [lambda] are greater than zero,
otherwise calls __domain_error.

   RealType mean()const; 
   
Returns the mean [mu] parameter of this distribution.

   RealType scale()const; 
   
Returns the scale [lambda] parameter of this distribution.

[h4 Non-member Accessors]

All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions] that are generic to all
distributions are supported: __usual_accessors.

The domain of the random variate is \[0,+[infin]).
[note Unlike some definitions, this implementation supports a random variate 
equal to zero as a special case, returning zero for both pdf and cdf.]

[h4 Accuracy]

The inverse_gaussian distribution is implemented in terms of the 
exponential function and standard normal distribution ['N]0,1 [Phi] :
refer to the accuracy data for those functions for more information.
But in general, gamma (and thus inverse gamma) results are often accurate to a few epsilon,
>14 decimal digits accuracy for 64-bit double.

[h4 Implementation]

In the following table [mu] is the mean parameter and 
[lambda] is the scale parameter of the inverse_gaussian distribution,
/x/ is the random variate, /p/ is the probability and /q = 1-p/ its complement.
Parameters [mu] for shape and [lambda] for scale
are used for the inverse gaussian function.

[table
[[Function] [Implementation Notes] ]
[[pdf] [ [sqrt]([lambda]/ 2[pi]x[super 3]) e[super -[lambda](x - [mu])[sup2]/ 2[mu][sup2]x]]]
[[cdf][ [Phi]{[sqrt]([lambda]/x) (x/[mu]-1)} + e[super 2[mu]/[lambda]] [Phi]{-[sqrt]([lambda]/[mu]) (1+x/[mu])} ]]
[[cdf complement] [using complement of [Phi] above.] ]
[[quantile][No closed form known. Estimated using a guess refined by Newton-Raphson iteration.]]
[[quantile from the complement][No closed form known. Estimated using a guess refined by Newton-Raphson iteration.]]
[[mode][[mu] {[sqrt](1+9[mu][sup2]/4[lambda][sup2])[sup2] - 3[mu]/2[lambda]} ]]
[[median][No closed form analytic equation is known, but is evaluated as quantile(0.5)]]
[[mean][[mu]] ]
[[variance][[mu][cubed]/[lambda]] ]
[[skewness][3 [sqrt] ([mu]/[lambda])] ]
[[kurtosis_excess][15[mu]/[lambda]] ]
[[kurtosis][12[mu]/[lambda]] ]
] [/table]

[h4 References]

#Wald, A. (1947). Sequential analysis. Wiley, NY.
#The Inverse Gaussian distribution : theory, methodology, and applications, Raj S. Chhikara, J. Leroy Folks. ISBN 0824779975 (1989).
#The Inverse Gaussian distribution : statistical theory and applications, Seshadri, V , ISBN - 0387986189 (pbk) (Dewey 519.2) (1998).
#[@http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.wald.html Numpy and Scipy Documentation].
#[@http://bm2.genes.nig.ac.jp/RGM2/R_current/library/statmod/man/invgauss.html  R statmod invgauss functions].
#[@http://cran.r-project.org/web/packages/SuppDists/index.html R SuppDists invGauss functions].
(Note that these R implementations names differ in case).
#[@http://www.statsci.org/s/invgauss.html StatSci.org invgauss help].
#[@http://www.statsci.org/s/invgauss.statSci.org invgauss R source].
#[@http://www.biostat.wustl.edu/archives/html/s-news/2001-12/msg00144.html pwald, qwald].
#[@http://www.brighton-webs.co.uk/distributions/wald.asp Brighton Webs wald].

[endsect] [/section:inverse_gaussian_dist Inverse Gaussian Distribution]

[/ 
  Copyright 2010 John Maddock and Paul A. Bristow.
  Distributed under the Boost Software License, Version 1.0.
  (See accompanying file LICENSE_1_0.txt or copy at
  http://www.boost.org/LICENSE_1_0.txt).
]