skew_normal.qbk 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. [section:skew_normal_dist Skew Normal Distribution]
  2. ``#include <boost/math/distributions/skew_normal.hpp>``
  3. namespace boost{ namespace math{
  4. template <class RealType = double,
  5. class ``__Policy`` = ``__policy_class`` >
  6. class skew_normal_distribution;
  7. typedef skew_normal_distribution<> normal;
  8. template <class RealType, class ``__Policy``>
  9. class skew_normal_distribution
  10. {
  11. public:
  12. typedef RealType value_type;
  13. typedef Policy policy_type;
  14. // Constructor:
  15. skew_normal_distribution(RealType location = 0, RealType scale = 1, RealType shape = 0);
  16. // Accessors:
  17. RealType location()const; // mean if normal.
  18. RealType scale()const; // width, standard deviation if normal.
  19. RealType shape()const; // The distribution is right skewed if shape > 0 and is left skewed if shape < 0.
  20. // The distribution is normal if shape is zero.
  21. };
  22. }} // namespaces
  23. The skew normal distribution is a variant of the most well known
  24. Gaussian statistical distribution.
  25. The skew normal distribution with shape zero resembles the
  26. [@http://en.wikipedia.org/wiki/Normal_distribution Normal Distribution],
  27. hence the latter can be regarded as a special case of the more generic skew normal distribution.
  28. If the standard (mean = 0, scale = 1) normal distribution probability density function is
  29. [equation normal01_pdf]
  30. and the cumulative distribution function
  31. [equation normal01_cdf]
  32. then the [@http://en.wikipedia.org/wiki/Probability_density_function PDF]
  33. of the [@http://en.wikipedia.org/wiki/Skew_normal_distribution skew normal distribution]
  34. with shape parameter [alpha], defined by O'Hagan and Leonhard (1976) is
  35. [equation skew_normal_pdf0]
  36. Given [@http://en.wikipedia.org/wiki/Location_parameter location] [xi],
  37. [@http://en.wikipedia.org/wiki/Scale_parameter scale] [omega],
  38. and [@http://en.wikipedia.org/wiki/Shape_parameter shape] [alpha],
  39. it can be
  40. [@http://en.wikipedia.org/wiki/Skew_normal_distribution transformed],
  41. to the form:
  42. [equation skew_normal_pdf]
  43. and [@http://en.wikipedia.org/wiki/Cumulative_distribution_function CDF]:
  44. [equation skew_normal_cdf]
  45. where ['T(h,a)] is Owen's T function, and ['[Phi](x)] is the normal distribution.
  46. The variation the PDF and CDF with its parameters is illustrated
  47. in the following graphs:
  48. [graph skew_normal_pdf]
  49. [graph skew_normal_cdf]
  50. [h4 Member Functions]
  51. skew_normal_distribution(RealType location = 0, RealType scale = 1, RealType shape = 0);
  52. Constructs a skew_normal distribution with location [xi],
  53. scale [omega] and shape [alpha].
  54. Requires scale > 0, otherwise __domain_error is called.
  55. RealType location()const;
  56. returns the location [xi] of this distribution,
  57. RealType scale()const;
  58. returns the scale [omega] of this distribution,
  59. RealType shape()const;
  60. returns the shape [alpha] of this distribution.
  61. (Location and scale function match other similar distributions,
  62. allowing the functions `find_location` and `find_scale` to be used generically).
  63. [note While the shape parameter may be chosen arbitrarily (finite),
  64. the resulting [*skewness] of the distribution is in fact limited to about (-1, 1);
  65. strictly, the interval is (-0.9952717, 0.9952717).
  66. A parameter [delta] is related to the shape [alpha] by
  67. [delta] = [alpha] / (1 + [alpha][pow2]),
  68. and used in the expression for skewness
  69. [equation skew_normal_skewness]
  70. ] [/note]
  71. [h4 References]
  72. * [@http://azzalini.stat.unipd.it/SN/ Skew-Normal Probability Distribution] for many links and bibliography.
  73. * [@http://azzalini.stat.unipd.it/SN/Intro/intro.html A very brief introduction to the skew-normal distribution]
  74. by Adelchi Azzalini (2005-11-2).
  75. * See a [@http://www.tri.org.au/azzalini.html skew-normal function animation].
  76. [h4 Non-member Accessors]
  77. All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
  78. that are generic to all distributions are supported: __usual_accessors.
  79. The domain of the random variable is ['-[max_value], +[min_value]].
  80. Infinite values are not supported.
  81. There are no [@http://en.wikipedia.org/wiki/Closed-form_expression closed-form expression]
  82. known for the mode and median, but these are computed for the
  83. * mode - by finding the maximum of the PDF.
  84. * median - by computing `quantile(1/2)`.
  85. The maximum of the PDF is sought through searching the root of f'(x)=0.
  86. Both involve iterative methods that will have lower accuracy than other estimates.
  87. [h4 Testing]
  88. __R using library(sn) described at
  89. [@http://azzalini.stat.unipd.it/SN/ Skew-Normal Probability Distribution],
  90. and at [@http://cran.r-project.org/web/packages/sn/sn.pd R skew-normal(sn) package].
  91. Package sn provides functions related to the skew-normal (SN)
  92. and the skew-t (ST) probability distributions,
  93. both for the univariate and for the the multivariate case,
  94. including regression models.
  95. __Mathematica was also used to generate some more accurate spot test data.
  96. [h4 Accuracy]
  97. The skew_normal distribution with shape = zero is implemented as a special case,
  98. equivalent to the normal distribution in terms of the
  99. [link math_toolkit.sf_erf.error_function error function],
  100. and therefore should have excellent accuracy.
  101. The PDF and mean, variance, skewness and kurtosis are also accurately evaluated using
  102. [@http://en.wikipedia.org/wiki/Analytical_expression analytical expressions].
  103. The CDF requires [@http://en.wikipedia.org/wiki/Owen%27s_T_function Owen's T function]
  104. that is evaluated using a Boost C++ __owens_t implementation of the algorithms of
  105. M. Patefield and D. Tandy, Journal of Statistical Software, 5(5), 1-25 (2000);
  106. the complicated accuracy of this function is discussed in detail at __owens_t.
  107. The median and mode are calculated by iterative root finding, and both will be less accurate.
  108. [h4 Implementation]
  109. In the following table, [xi] is the location of the distribution,
  110. and [omega] is its scale, and [alpha] is its shape.
  111. [table
  112. [[Function][Implementation Notes]]
  113. [[pdf][Using:[equation skew_normal_pdf] ]]
  114. [[cdf][Using: [equation skew_normal_cdf][br]
  115. where ['T(h,a)] is Owen's T function, and ['[Phi](x)] is the normal distribution. ]]
  116. [[cdf complement][Using: complement of normal distribution + 2 * Owens_t]]
  117. [[quantile][Maximum of the pdf is sought through searching the root of f'(x)=0]]
  118. [[quantile from the complement][-quantile(SN(-location [xi], scale [omega], -shape[alpha]), p)]]
  119. [[location][location [xi]]]
  120. [[scale][scale [omega]]]
  121. [[shape][shape [alpha]]]
  122. [[median][quantile(1/2)]]
  123. [[mean][[equation skew_normal_mean]]]
  124. [[mode][Maximum of the pdf is sought through searching the root of f'(x)=0]]
  125. [[variance][[equation skew_normal_variance] ]]
  126. [[skewness][[equation skew_normal_skewness] ]]
  127. [[kurtosis][kurtosis excess-3]]
  128. [[kurtosis excess] [ [equation skew_normal_kurt_ex] ]]
  129. ] [/table]
  130. [endsect] [/section:skew_normal_dist skew_Normal]
  131. [/ skew_normal.qbk
  132. Copyright 2012 Bejamin Sobotta, John Maddock and Paul A. Bristow.
  133. Distributed under the Boost Software License, Version 1.0.
  134. (See accompanying file LICENSE_1_0.txt or copy at
  135. http://www.boost.org/LICENSE_1_0.txt).
  136. ]