nc_t.qbk 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. [section:nc_t_dist Noncentral T Distribution]
  2. ``#include <boost/math/distributions/non_central_t.hpp>``
  3. namespace boost{ namespace math{
  4. template <class RealType = double,
  5. class ``__Policy`` = ``__policy_class`` >
  6. class non_central_t_distribution;
  7. typedef non_central_t_distribution<> non_central_t;
  8. template <class RealType, class ``__Policy``>
  9. class non_central_t_distribution
  10. {
  11. public:
  12. typedef RealType value_type;
  13. typedef Policy policy_type;
  14. // Constructor:
  15. non_central_t_distribution(RealType v, RealType delta);
  16. // Accessor to degrees_of_freedom parameter v:
  17. RealType degrees_of_freedom()const;
  18. // Accessor to non-centrality parameter delta:
  19. RealType non_centrality()const;
  20. };
  21. }} // namespaces
  22. The noncentral T distribution is a generalization of the __students_t_distrib.
  23. Let X have a normal distribution with mean [delta] and variance 1, and let
  24. ['[nu] S[super 2]] have
  25. a chi-squared distribution with degrees of freedom [nu]. Assume that
  26. X and S[super 2] are independent.
  27. The distribution of [role serif_italic t[sub [nu]]([delta])=X/S] is called a
  28. noncentral t distribution with degrees of freedom [nu] and noncentrality parameter [delta].
  29. This gives the following PDF:
  30. [equation nc_t_ref1]
  31. where [role serif_italic [sub 1]F[sub 1](a;b;x)] is a confluent hypergeometric function.
  32. The following graph illustrates how the distribution changes
  33. for different values of [nu] and [delta]:
  34. [graph nc_t_pdf]
  35. [graph nc_t_cdf]
  36. [h4 Member Functions]
  37. non_central_t_distribution(RealType v, RealType delta);
  38. Constructs a non-central t distribution with degrees of freedom
  39. parameter /v/ and non-centrality parameter /delta/.
  40. Requires /v/ > 0 (including positive infinity) and finite /delta/, otherwise calls __domain_error.
  41. RealType degrees_of_freedom()const;
  42. Returns the parameter /v/ from which this object was constructed.
  43. RealType non_centrality()const;
  44. Returns the non-centrality parameter /delta/ from which this object was constructed.
  45. [h4 Non-member Accessors]
  46. All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
  47. that are generic to all distributions are supported: __usual_accessors.
  48. The domain of the random variable is \[-[infin], +[infin]\].
  49. [h4 Accuracy]
  50. The following table shows the peak errors
  51. (in units of [@http://en.wikipedia.org/wiki/Machine_epsilon epsilon])
  52. found on various platforms with various floating-point types.
  53. Unless otherwise specified, any floating-point type that is narrower
  54. than the one shown will have __zero_error.
  55. [table_non_central_t_CDF]
  56. [table_non_central_t_CDF_complement]
  57. [caution The complexity of the current algorithm is dependent upon
  58. [delta][super 2]: consequently the time taken to evaluate the CDF
  59. increases rapidly for [delta] > 500, likewise the accuracy decreases
  60. rapidly for very large [delta].]
  61. Accuracy for the quantile and PDF functions should be broadly similar.
  62. The /mode/ is determined numerically and cannot
  63. in principal be more accurate than the square root of
  64. floating-point type FPT epsilon, accessed using `boost::math::tools::epsilon<FPT>()`.
  65. For 64-bit `double`, epsilon is about 1e-16, so the fractional accuracy is limited to 1e-8.
  66. [h4 Tests]
  67. There are two sets of tests of this distribution:
  68. Basic sanity checks compare this implementation to the test values given in
  69. "Computing discrete mixtures of continuous
  70. distributions: noncentral chisquare, noncentral t
  71. and the distribution of the square of the sample
  72. multiple correlation coefficient."
  73. Denise Benton, K. Krishnamoorthy,
  74. Computational Statistics & Data Analysis 43 (2003) 249-267.
  75. Accuracy checks use test data computed with this
  76. implementation and arbitary precision interval arithmetic:
  77. this test data is believed to be accurate to at least 50
  78. decimal places.
  79. The cases of large (or infinite) [nu] and/or large [delta] has received special
  80. treatment to avoid catastrophic loss of accuracy.
  81. New tests have been added to confirm the improvement achieved.
  82. From Boost 1.52, degrees of freedom [nu] can be +[infin]
  83. when the normal distribution located at [delta]
  84. (equivalent to the central Student's t distribution)
  85. is used in place for accuracy and speed.
  86. [h4 Implementation]
  87. The CDF is computed using a modification of the method
  88. described in
  89. "Computing discrete mixtures of continuous
  90. distributions: noncentral chisquare, noncentral t
  91. and the distribution of the square of the sample
  92. multiple correlation coefficient."
  93. Denise Benton, K. Krishnamoorthy,
  94. Computational Statistics & Data Analysis 43 (2003) 249-267.
  95. This uses the following formula for the CDF:
  96. [equation nc_t_ref2]
  97. Where I[sub x](a,b) is the incomplete beta function, and
  98. [Phi](x) is the normal CDF at x.
  99. Iteration starts at the largest of the Poisson weighting terms
  100. (at i = [delta][super 2] / 2) and then proceeds in both directions
  101. as per Benton and Krishnamoorthy's paper.
  102. Alternatively, by considering what happens when t = [infin], we have
  103. x = 1, and therefore I[sub x](a,b) = 1 and:
  104. [equation nc_t_ref3]
  105. From this we can easily show that:
  106. [equation nc_t_ref4]
  107. and therefore we have a means to compute either the probability or its
  108. complement directly without the risk of cancellation error. The
  109. crossover criterion for choosing whether to calculate the CDF or
  110. its complement is the same as for the
  111. __non_central_beta_distrib.
  112. The PDF can be computed by a very similar method using:
  113. [equation nc_t_ref5]
  114. Where I[sub x][super '](a,b) is the derivative of the incomplete beta function.
  115. For both the PDF and CDF we switch to approximating the distribution by a
  116. Student's t distribution centred on [delta] when [nu] is very large.
  117. The crossover location appears to be when [delta]/(4[nu]) < [epsilon],
  118. this location was estimated by inspection of equation 2.6 in
  119. "A Comparison of Approximations To Percentiles of the
  120. Noncentral t-Distribution". H. Sahai and M. M. Ojeda,
  121. Revista Investigacion Operacional Vol 21, No 2, 2000, page 123.
  122. Equation 2.6 is a Fisher-Cornish expansion by Eeden and Johnson.
  123. The second term includes the ratio [delta]/(4[nu]),
  124. so when this term become negligible, this and following terms can be ignored,
  125. leaving just Student's t distribution centred on [delta].
  126. This was also confirmed by experimental testing.
  127. See also
  128. * "Some Approximations to the Percentage Points of the Noncentral
  129. t-Distribution". C. van Eeden. International Statistical Review, 29, 4-31.
  130. * "Continuous Univariate Distributions". N.L. Johnson, S. Kotz and
  131. N. Balkrishnan. 1995. John Wiley and Sons New York.
  132. The quantile is calculated via the usual
  133. __root_finding_without_derivatives method
  134. with the initial guess taken as the quantile of a normal approximation
  135. to the noncentral T.
  136. There is no closed form for the mode, so this is computed via
  137. functional maximisation of the PDF.
  138. The remaining functions (mean, variance etc) are implemented
  139. using the formulas given in
  140. Weisstein, Eric W. "Noncentral Student's t-Distribution."
  141. From MathWorld--A Wolfram Web Resource.
  142. [@http://mathworld.wolfram.com/NoncentralStudentst-Distribution.html
  143. http://mathworld.wolfram.com/NoncentralStudentst-Distribution.html]
  144. and in the
  145. [@http://reference.wolfram.com/mathematica/ref/NoncentralStudentTDistribution.html
  146. Mathematica documentation].
  147. Some analytic properties of noncentral distributions
  148. (particularly unimodality, and monotonicity of their modes)
  149. are surveyed and summarized by:
  150. Andrea van Aubel & Wolfgang Gawronski, Applied Mathematics and Computation, 141 (2003) 3-12.
  151. [endsect] [/section:nc_t_dist]
  152. [/ nc_t.qbk
  153. Copyright 2008, 2012 John Maddock and Paul A. Bristow.
  154. Distributed under the Boost Software License, Version 1.0.
  155. (See accompanying file LICENSE_1_0.txt or copy at
  156. http://www.boost.org/LICENSE_1_0.txt).
  157. ]