inverse_gaussian.qbk 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. [section:inverse_gaussian_dist Inverse Gaussian (or Inverse Normal) Distribution]
  2. ``#include <boost/math/distributions/inverse_gaussian.hpp>``
  3. namespace boost{ namespace math{
  4. template <class RealType = double,
  5. class ``__Policy`` = ``__policy_class`` >
  6. class inverse_gaussian_distribution
  7. {
  8. public:
  9. typedef RealType value_type;
  10. typedef Policy policy_type;
  11. inverse_gaussian_distribution(RealType mean = 1, RealType scale = 1);
  12. RealType mean()const; // mean default 1.
  13. RealType scale()const; // Optional scale, default 1 (unscaled).
  14. RealType shape()const; // Shape = scale/mean.
  15. };
  16. typedef inverse_gaussian_distribution<double> inverse_gaussian;
  17. }} // namespace boost // namespace math
  18. The Inverse Gaussian distribution distribution is a continuous probability distribution.
  19. The distribution is also called 'normal-inverse Gaussian distribution',
  20. and 'normal Inverse' distribution.
  21. It is also convenient to provide unity as default for both mean and scale.
  22. This is the Standard form for all distributions.
  23. The Inverse Gaussian distribution was first studied in relation to Brownian motion.
  24. In 1956 M.C.K. Tweedie used the name Inverse Gaussian because there is an inverse relationship
  25. between the time to cover a unit distance and distance covered in unit time.
  26. The inverse Gaussian is one of family of distributions that have been called the
  27. [@http://en.wikipedia.org/wiki/Tweedie_distributions Tweedie distributions].
  28. (So ['inverse] in the name may mislead: it does [*not] relate to the inverse of a distribution).
  29. The tails of the distribution decrease more slowly than the normal distribution.
  30. It is therefore suitable to model phenomena
  31. where numerically large values are more probable than is the case for the normal distribution.
  32. For stock market returns and prices, a key characteristic is that it models
  33. that extremely large variations from typical (crashes) can occur
  34. even when almost all (normal) variations are small.
  35. Examples are returns from financial assets and turbulent wind speeds.
  36. The normal-inverse Gaussian distributions form
  37. a subclass of the generalised hyperbolic distributions.
  38. See
  39. [@http://en.wikipedia.org/wiki/Normal-inverse_Gaussian_distribution distribution].
  40. [@http://mathworld.wolfram.com/InverseGaussianDistribution.html
  41. Weisstein, Eric W. "Inverse Gaussian Distribution." From MathWorld--A Wolfram Web Resource.]
  42. If you want a `double` precision inverse_gaussian distribution you can use
  43. ``boost::math::inverse_gaussian_distribution<>``
  44. or, more conveniently, you can write
  45. using boost::math::inverse_gaussian;
  46. inverse_gaussian my_ig(2, 3);
  47. For mean parameters [mu] and scale (also called precision) parameter [lambda],
  48. and random variate x,
  49. the inverse_gaussian distribution is defined by the probability density function (PDF):
  50. [expression f(x;[mu], [lambda]) = [sqrt]([lambda]/2[pi]x[super 3]) e[super -[lambda](x-[mu])[sup2]/2[mu][sup2]x] ]
  51. and Cumulative Density Function (CDF):
  52. [expression F(x;[mu], [lambda]) = [Phi]{[sqrt]([lambda]/x) (x/[mu]-1)} + e[super 2[mu]/[lambda]] [Phi]{-[sqrt]([lambda]/[mu]) (1+x/[mu])} ]
  53. where [Phi] is the standard normal distribution CDF.
  54. The following graphs illustrate how the PDF and CDF of the inverse_gaussian distribution
  55. varies for a few values of parameters [mu] and [lambda]:
  56. [graph inverse_gaussian_pdf] [/.png or .svg]
  57. [graph inverse_gaussian_cdf]
  58. Tweedie also provided 3 other parameterisations where ([mu] and [lambda])
  59. are replaced by their ratio [phi] = [lambda]/[mu] and by 1/[mu]:
  60. these forms may be more suitable for Bayesian applications.
  61. These can be found on Seshadri, page 2 and are also discussed by Chhikara and Folks on page 105.
  62. Another related parameterisation, the __wald_distrib (where mean [mu] is unity) is also provided.
  63. [h4 Member Functions]
  64. inverse_gaussian_distribution(RealType df = 1, RealType scale = 1); // optionally scaled.
  65. Constructs an inverse_gaussian distribution with [mu] mean,
  66. and scale [lambda], with both default values 1.
  67. Requires that both the mean [mu] parameter and scale [lambda] are greater than zero,
  68. otherwise calls __domain_error.
  69. RealType mean()const;
  70. Returns the mean [mu] parameter of this distribution.
  71. RealType scale()const;
  72. Returns the scale [lambda] parameter of this distribution.
  73. [h4 Non-member Accessors]
  74. All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions] that are generic to all
  75. distributions are supported: __usual_accessors.
  76. The domain of the random variate is \[0,+[infin]).
  77. [note Unlike some definitions, this implementation supports a random variate
  78. equal to zero as a special case, returning zero for both pdf and cdf.]
  79. [h4 Accuracy]
  80. The inverse_gaussian distribution is implemented in terms of the
  81. exponential function and standard normal distribution ['N]0,1 [Phi] :
  82. refer to the accuracy data for those functions for more information.
  83. But in general, gamma (and thus inverse gamma) results are often accurate to a few epsilon,
  84. >14 decimal digits accuracy for 64-bit double.
  85. [h4 Implementation]
  86. In the following table [mu] is the mean parameter and
  87. [lambda] is the scale parameter of the inverse_gaussian distribution,
  88. /x/ is the random variate, /p/ is the probability and /q = 1-p/ its complement.
  89. Parameters [mu] for shape and [lambda] for scale
  90. are used for the inverse gaussian function.
  91. [table
  92. [[Function] [Implementation Notes] ]
  93. [[pdf] [ [sqrt]([lambda]/ 2[pi]x[super 3]) e[super -[lambda](x - [mu])[sup2]/ 2[mu][sup2]x]]]
  94. [[cdf][ [Phi]{[sqrt]([lambda]/x) (x/[mu]-1)} + e[super 2[mu]/[lambda]] [Phi]{-[sqrt]([lambda]/[mu]) (1+x/[mu])} ]]
  95. [[cdf complement] [using complement of [Phi] above.] ]
  96. [[quantile][No closed form known. Estimated using a guess refined by Newton-Raphson iteration.]]
  97. [[quantile from the complement][No closed form known. Estimated using a guess refined by Newton-Raphson iteration.]]
  98. [[mode][[mu] {[sqrt](1+9[mu][sup2]/4[lambda][sup2])[sup2] - 3[mu]/2[lambda]} ]]
  99. [[median][No closed form analytic equation is known, but is evaluated as quantile(0.5)]]
  100. [[mean][[mu]] ]
  101. [[variance][[mu][cubed]/[lambda]] ]
  102. [[skewness][3 [sqrt] ([mu]/[lambda])] ]
  103. [[kurtosis_excess][15[mu]/[lambda]] ]
  104. [[kurtosis][12[mu]/[lambda]] ]
  105. ] [/table]
  106. [h4 References]
  107. #Wald, A. (1947). Sequential analysis. Wiley, NY.
  108. #The Inverse Gaussian distribution : theory, methodology, and applications, Raj S. Chhikara, J. Leroy Folks. ISBN 0824779975 (1989).
  109. #The Inverse Gaussian distribution : statistical theory and applications, Seshadri, V , ISBN - 0387986189 (pbk) (Dewey 519.2) (1998).
  110. #[@http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.wald.html Numpy and Scipy Documentation].
  111. #[@http://bm2.genes.nig.ac.jp/RGM2/R_current/library/statmod/man/invgauss.html R statmod invgauss functions].
  112. #[@http://cran.r-project.org/web/packages/SuppDists/index.html R SuppDists invGauss functions].
  113. (Note that these R implementations names differ in case).
  114. #[@http://www.statsci.org/s/invgauss.html StatSci.org invgauss help].
  115. #[@http://www.statsci.org/s/invgauss.statSci.org invgauss R source].
  116. #[@http://www.biostat.wustl.edu/archives/html/s-news/2001-12/msg00144.html pwald, qwald].
  117. #[@http://www.brighton-webs.co.uk/distributions/wald.asp Brighton Webs wald].
  118. [endsect] [/section:inverse_gaussian_dist Inverse Gaussiann Distribution]
  119. [/
  120. Copyright 2010 John Maddock and Paul A. Bristow.
  121. Distributed under the Boost Software License, Version 1.0.
  122. (See accompanying file LICENSE_1_0.txt or copy at
  123. http://www.boost.org/LICENSE_1_0.txt).
  124. ]