students_t.qbk 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. [section:students_t_dist Students t Distribution]
  2. ``#include <boost/math/distributions/students_t.hpp>``
  3. namespace boost{ namespace math{
  4. template <class RealType = double,
  5. class ``__Policy`` = ``__policy_class`` >
  6. class students_t_distribution;
  7. typedef students_t_distribution<> students_t;
  8. template <class RealType, class ``__Policy``>
  9. class students_t_distribution
  10. {
  11. typedef RealType value_type;
  12. typedef Policy policy_type;
  13. // Constructor:
  14. students_t_distribution(const RealType& v);
  15. // Accessor:
  16. RealType degrees_of_freedom()const;
  17. // degrees of freedom estimation:
  18. static RealType find_degrees_of_freedom(
  19. RealType difference_from_mean,
  20. RealType alpha,
  21. RealType beta,
  22. RealType sd,
  23. RealType hint = 100);
  24. };
  25. }} // namespaces
  26. Student's t-distribution is a statistical distribution published by William Gosset in 1908.
  27. His employer, Guinness Breweries, required him to publish under a
  28. pseudonym (possibly to hide that they were using statistics to improve beer quality),
  29. so he chose "Student".
  30. Given N independent measurements, let
  31. [equation students_t_dist]
  32. where /M/ is the population mean, [mu] is the sample mean, and /s/ is the sample variance.
  33. [@https://en.wikipedia.org/wiki/Student%27s_t-distribution Student's t-distribution]
  34. is defined as the distribution of the random
  35. variable t which is - very loosely - the "best" that we can do while not
  36. knowing the true standard deviation of the sample. It has the PDF:
  37. [equation students_t_ref1]
  38. The Student's t-distribution takes a single parameter: the number of
  39. degrees of freedom of the sample. When the degrees of freedom is
  40. /one/ then this distribution is the same as the Cauchy-distribution.
  41. As the number of degrees of freedom tends towards infinity, then this
  42. distribution approaches the normal-distribution. The following graph
  43. illustrates how the PDF varies with the degrees of freedom [nu]:
  44. [graph students_t_pdf]
  45. [h4 Member Functions]
  46. students_t_distribution(const RealType& v);
  47. Constructs a Student's t-distribution with /v/ degrees of freedom.
  48. Requires /v/ > 0, including infinity (if RealType permits),
  49. otherwise calls __domain_error. Note that
  50. non-integral degrees of freedom are supported,
  51. and are meaningful under certain circumstances.
  52. RealType degrees_of_freedom()const;
  53. returns the number of degrees of freedom of this distribution.
  54. static RealType find_degrees_of_freedom(
  55. RealType difference_from_mean,
  56. RealType alpha,
  57. RealType beta,
  58. RealType sd,
  59. RealType hint = 100);
  60. returns the number of degrees of freedom required to observe a significant
  61. result in the Student's t test when the mean differs from the "true"
  62. mean by /difference_from_mean/.
  63. [variablelist
  64. [[difference_from_mean][The difference between the true mean and the sample mean
  65. that we wish to show is significant.]]
  66. [[alpha][The maximum acceptable probability of rejecting the null hypothesis
  67. when it is in fact true.]]
  68. [[beta][The maximum acceptable probability of failing to reject the null hypothesis
  69. when it is in fact false.]]
  70. [[sd][The sample standard deviation.]]
  71. [[hint][A hint for the location to start looking for the result, a good choice for this
  72. would be the sample size of a previous borderline Student's t test.]]
  73. ]
  74. [note
  75. Remember that for a two-sided test, you must divide alpha by two
  76. before calling this function.]
  77. For more information on this function see the
  78. [@http://www.itl.nist.gov/div898/handbook/prc/section2/prc222.htm
  79. NIST Engineering Statistics Handbook].
  80. [h4 Non-member Accessors]
  81. All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions] that are generic to all
  82. distributions are supported: __usual_accessors.
  83. The domain of the random variable is \[-[infin], +[infin]\].
  84. [h4 Examples]
  85. Various [link math_toolkit.stat_tut.weg.st_eg worked examples] are available illustrating the use of the Student's t
  86. distribution.
  87. [h4 Accuracy]
  88. The normal distribution is implemented in terms of the
  89. [link math_toolkit.sf_beta.ibeta_function incomplete beta function]
  90. and [link math_toolkit.sf_beta.ibeta_inv_function its inverses],
  91. refer to accuracy data on those functions for more information.
  92. [h4 Implementation]
  93. In the following table /v/ is the degrees of freedom of the distribution,
  94. /t/ is the random variate, /p/ is the probability and /q = 1-p/.
  95. [table
  96. [[Function][Implementation Notes]]
  97. [[pdf][Using the relation: [role serif_italic pdf = (v \/ (v + t[super 2]))[super (1+v)\/2 ] / (sqrt(v) * __beta(v\/2, 0.5))] ]]
  98. [[cdf][Using the relations:
  99. [role serif_italic p = 1 - z /iff t > 0/]
  100. [role serif_italic p = z /otherwise/]
  101. where z is given by:
  102. __ibeta(v \/ 2, 0.5, v \/ (v + t[super 2])) \/ 2 ['iff v < 2t[super 2]]
  103. __ibetac(0.5, v \/ 2, t[super 2 ] / (v + t[super 2]) \/ 2 /otherwise/]]
  104. [[cdf complement][Using the relation: q = cdf(-t) ]]
  105. [[quantile][Using the relation: [role serif_italic t = sign(p - 0.5) * sqrt(v * y \/ x)]
  106. where:
  107. [role serif_italic x = __ibeta_inv(v \/ 2, 0.5, 2 * min(p, q)) ]
  108. [role serif_italic y = 1 - x]
  109. The quantities /x/ and /y/ are both returned by __ibeta_inv
  110. without the subtraction implied above.]]
  111. [[quantile from the complement][Using the relation: t = -quantile(q)]]
  112. [[mode][0]]
  113. [[mean][0]]
  114. [[variance][if (v > 2) v \/ (v - 2) else NaN]]
  115. [[skewness][if (v > 3) 0 else NaN ]]
  116. [[kurtosis][if (v > 4) 3 * (v - 2) \/ (v - 4) else NaN]]
  117. [[kurtosis excess][if (v > 4) 6 \/ (df - 4) else NaN]]
  118. ]
  119. If the moment index /k/ is less than /v/, then the moment is undefined.
  120. Evaluating the moment will throw a __domain_error unless ignored by a policy,
  121. when it will return `std::numeric_limits<>::quiet_NaN();`
  122. [h5:implementation Implementation]
  123. (By popular demand, we now support infinite argument and random deviate.
  124. But we have not implemented the return of infinity
  125. as suggested by [@http://en.wikipedia.org/wiki/Student%27s_t-distribution Wikipedia Student's t],
  126. instead throwing a domain error or return NaN.
  127. See also [@https://svn.boost.org/trac/boost/ticket/7177].)
  128. [endsect] [/section:students_t_dist Students t]
  129. [/ students_t.qbk
  130. Copyright 2006, 2012, 2017 John Maddock and Paul A. Bristow.
  131. Distributed under the Boost Software License, Version 1.0.
  132. (See accompanying file LICENSE_1_0.txt or copy at
  133. http://www.boost.org/LICENSE_1_0.txt).
  134. ]