fisher.qbk 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. [section:f_dist F Distribution]
  2. ``#include <boost/math/distributions/fisher_f.hpp>``
  3. namespace boost{ namespace math{
  4. template <class RealType = double,
  5. class ``__Policy`` = ``__policy_class`` >
  6. class fisher_f_distribution;
  7. typedef fisher_f_distribution<> fisher_f;
  8. template <class RealType, class ``__Policy``>
  9. class fisher_f_distribution
  10. {
  11. public:
  12. typedef RealType value_type;
  13. // Construct:
  14. fisher_f_distribution(const RealType& i, const RealType& j);
  15. // Accessors:
  16. RealType degrees_of_freedom1()const;
  17. RealType degrees_of_freedom2()const;
  18. };
  19. }} //namespaces
  20. The F distribution is a continuous distribution that arises when testing
  21. whether two samples have the same variance. If [chi][super 2][sub m] and
  22. [chi][super 2][sub n] are independent variates each distributed as
  23. Chi-Squared with /m/ and /n/ degrees of freedom, then the test statistic:
  24. [expression F[sub n,m] = ([chi][super 2][sub n] / n) / ([chi][super 2][sub m] / m)]
  25. Is distributed over the range \[0, [infin]\] with an F distribution, and
  26. has the PDF:
  27. [equation fisher_pdf]
  28. The following graph illustrates how the PDF varies depending on the
  29. two degrees of freedom parameters.
  30. [graph fisher_f_pdf]
  31. [h4 Member Functions]
  32. fisher_f_distribution(const RealType& df1, const RealType& df2);
  33. Constructs an F-distribution with numerator degrees of freedom /df1/
  34. and denominator degrees of freedom /df2/.
  35. Requires that /df1/ and /df2/ are both greater than zero, otherwise __domain_error
  36. is called.
  37. RealType degrees_of_freedom1()const;
  38. Returns the numerator degrees of freedom parameter of the distribution.
  39. RealType degrees_of_freedom2()const;
  40. Returns the denominator degrees of freedom parameter of the distribution.
  41. [h4 Non-member Accessors]
  42. All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
  43. that are generic to all distributions are supported: __usual_accessors.
  44. The domain of the random variable is \[0, +[infin]\].
  45. [h4 Examples]
  46. Various [link math_toolkit.stat_tut.weg.f_eg worked examples] are
  47. available illustrating the use of the F Distribution.
  48. [h4 Accuracy]
  49. The normal distribution is implemented in terms of the
  50. [link math_toolkit.sf_beta.ibeta_function incomplete beta function]
  51. and its [link math_toolkit.sf_beta.ibeta_inv_function inverses],
  52. refer to those functions for accuracy data.
  53. [h4 Implementation]
  54. In the following table /v1/ and /v2/ are the first and second
  55. degrees of freedom parameters of the distribution,
  56. /x/ is the random variate, /p/ is the probability, and /q = 1-p/.
  57. [table
  58. [[Function][Implementation Notes]]
  59. [[pdf][The usual form of the PDF is given by:
  60. [equation fisher_pdf]
  61. However, that form is hard to evaluate directly without incurring problems with
  62. either accuracy or numeric overflow.
  63. Direct differentiation of the CDF expressed in terms of the incomplete beta function
  64. led to the following two formulas:
  65. [expression f[sub v1,v2](x) = y * __ibeta_derivative(v2 \/ 2, v1 \/ 2, v2 \/ (v2 + v1 * x))]
  66. with y = (v2 * v1) \/ ((v2 + v1 * x) * (v2 + v1 * x))
  67. and
  68. [expression f[sub v1,v2](x) = y * __ibeta_derivative(v1 \/ 2, v2 \/ 2, v1 * x \/ (v2 + v1 * x))]
  69. with y = (z * v1 - x * v1 * v1) \/ z[super 2]
  70. and z = v2 + v1 * x
  71. The first of these is used for v1 * x > v2, otherwise the second is used.
  72. The aim is to keep the /x/ argument to __ibeta_derivative away from 1 to avoid
  73. rounding error. ]]
  74. [[cdf][Using the relations:
  75. [expression p = __ibeta(v1 \/ 2, v2 \/ 2, v1 * x \/ (v2 + v1 * x))]
  76. and
  77. [expression :p = __ibetac(v2 \/ 2, v1 \/ 2, v2 \/ (v2 + v1 * x))]
  78. The first is used for v1 * x > v2, otherwise the second is used.
  79. The aim is to keep the /x/ argument to __ibeta well away from 1 to
  80. avoid rounding error. ]]
  81. [[cdf complement][Using the relations:
  82. [expression p = __ibetac(v1 \/ 2, v2 \/ 2, v1 * x \/ (v2 + v1 * x))]
  83. and
  84. [expression p = __ibeta(v2 \/ 2, v1 \/ 2, v2 \/ (v2 + v1 * x))]
  85. The first is used for v1 * x < v2, otherwise the second is used.
  86. The aim is to keep the /x/ argument to __ibeta well away from 1 to
  87. avoid rounding error. ]]
  88. [[quantile][Using the relation:
  89. [expression x = v2 * a \/ (v1 * b)]
  90. where:
  91. [expression a = __ibeta_inv(v1 \/ 2, v2 \/ 2, p)]
  92. and
  93. [expression b = 1 - a]
  94. Quantities /a/ and /b/ are both computed by __ibeta_inv without the
  95. subtraction implied above.]]
  96. [[quantile
  97. from the complement][Using the relation:
  98. [expression x = v2 * a \/ (v1 * b)]
  99. where
  100. [expression a = __ibetac_inv(v1 \/ 2, v2 \/ 2, p)]
  101. and
  102. [expression b = 1 - a]
  103. Quantities /a/ and /b/ are both computed by __ibetac_inv without the
  104. subtraction implied above.]]
  105. [[mean][v2 \/ (v2 - 2)]]
  106. [[variance][2 * v2[super 2 ] * (v1 + v2 - 2) \/ (v1 * (v2 - 2) * (v2 - 2) * (v2 - 4))]]
  107. [[mode][v2 * (v1 - 2) \/ (v1 * (v2 + 2))]]
  108. [[skewness][2 * (v2 + 2 * v1 - 2) * sqrt((2 * v2 - 8) \/ (v1 * (v2 + v1 - 2))) \/ (v2 - 6)]]
  109. [[kurtosis and kurtosis excess]
  110. [Refer to, [@http://mathworld.wolfram.com/F-Distribution.html
  111. Weisstein, Eric W. "F-Distribution." From MathWorld--A Wolfram Web Resource.] ]]
  112. ]
  113. [endsect] [/section:f_dist F distribution]
  114. [/ fisher.qbk
  115. Copyright 2006 John Maddock and Paul A. Bristow.
  116. Distributed under the Boost Software License, Version 1.0.
  117. (See accompanying file LICENSE_1_0.txt or copy at
  118. http://www.boost.org/LICENSE_1_0.txt).
  119. ]