1[section:nc_beta_dist Noncentral Beta Distribution] 2 3``#include <boost/math/distributions/non_central_beta.hpp>`` 4 5 namespace boost{ namespace math{ 6 7 template <class RealType = double, 8 class ``__Policy`` = ``__policy_class`` > 9 class non_central_beta_distribution; 10 11 typedef non_central_beta_distribution<> non_central_beta; 12 13 template <class RealType, class ``__Policy``> 14 class non_central_beta_distribution 15 { 16 public: 17 typedef RealType value_type; 18 typedef Policy policy_type; 19 20 // Constructor: 21 non_central_beta_distribution(RealType alpha, RealType beta, RealType lambda); 22 23 // Accessor to shape parameters: 24 RealType alpha()const; 25 RealType beta()const; 26 27 // Accessor to non-centrality parameter lambda: 28 RealType non_centrality()const; 29 }; 30 31 }} // namespaces 32 33The noncentral beta distribution is a generalization of the __beta_distrib. 34 35It is defined as the ratio 36[expression X = [chi][sub m][super 2]([lambda]) \/ ([chi][sub m][super 2]([lambda]) 37+ [chi][sub n][super 2])] 38where [role serif_italic [chi][sub m][super 2]([lambda])] 39is a noncentral [role serif_italic [chi][super 2]] 40random variable with /m/ degrees of freedom, and [chi][sub n][super 2] 41is a central [role serif_italic [chi][super 2] ] random variable with /n/ degrees of freedom. 42 43This gives a PDF that can be expressed as a Poisson mixture 44of beta distribution PDFs: 45 46[equation nc_beta_ref1] 47 48where P(i;[lambda]\/2) is the discrete Poisson probability at /i/, with mean 49[lambda]\/2, and I[sub x][super ']([alpha], [beta]) is the derivative of 50the incomplete beta function. This leads to the usual form of the CDF 51as: 52 53[equation nc_beta_ref2] 54 55The following graph illustrates how the distribution changes 56for different values of [lambda]: 57 58[graph nc_beta_pdf] 59 60[h4 Member Functions] 61 62 non_central_beta_distribution(RealType a, RealType b, RealType lambda); 63 64Constructs a noncentral beta distribution with shape parameters /a/ and /b/ 65and non-centrality parameter /lambda/. 66 67Requires a > 0, b > 0 and lambda >= 0, otherwise calls __domain_error. 68 69 RealType alpha()const; 70 71Returns the parameter /a/ from which this object was constructed. 72 73 RealType beta()const; 74 75Returns the parameter /b/ from which this object was constructed. 76 77 RealType non_centrality()const; 78 79Returns the parameter /lambda/ from which this object was constructed. 80 81[h4 Non-member Accessors] 82 83Most of the [link math_toolkit.dist_ref.nmp usual non-member accessor functions] 84are supported: __cdf, __pdf, __quantile, __mean, __variance, __sd, 85__median, __mode, __hazard, __chf, __range and __support. 86 87Mean and variance are implemented using hypergeometric pfq functions and relations given in 88[@http://reference.wolfram.com/mathematica/ref/NoncentralBetaDistribution.html Wolfram Noncentral Beta Distribution]. 89 90However, the following are not currently implemented: 91 __skewness, __kurtosis and __kurtosis_excess. 92 93The domain of the random variable is \[0, 1\]. 94 95[h4 Accuracy] 96 97The following table shows the peak errors 98(in units of [@http://en.wikipedia.org/wiki/Machine_epsilon epsilon]) 99found on various platforms with various floating point types. 100The failures in the comparison to the [@http://www.r-project.org/ R Math library], 101seem to be mostly in the corner cases when the probability would be very small. 102Unless otherwise specified any floating-point type that is narrower 103than the one shown will have __zero_error. 104 105[table_non_central_beta_CDF] 106 107[table_non_central_beta_CDF_complement] 108 109Error rates for the PDF, the complement of the CDF and for the quantile 110functions are broadly similar. 111 112[h4 Tests] 113 114There are two sets of test data used to verify this implementation: 115firstly we can compare with a few sample values generated by the 116[@http://www.r-project.org/ R library]. 117Secondly, we have tables of test data, computed with this 118implementation and using interval arithmetic - this data should 119be accurate to at least 50 decimal digits - and is the used for 120our accuracy tests. 121 122[h4 Implementation] 123 124The CDF and its complement are evaluated as follows: 125 126First we determine which of the two values (the CDF or its 127complement) is likely to be the smaller, the crossover point 128is taken to be the mean of the distribution: for this we use the 129approximation due to: R. Chattamvelli and R. Shanmugam, 130"Algorithm AS 310: Computing the Non-Central Beta Distribution Function", 131Applied Statistics, Vol. 46, No. 1. (1997), pp. 146-156. 132 133[equation nc_beta_ref3] 134 135Then either the CDF or its complement is computed using the 136relations: 137 138[equation nc_beta_ref4] 139 140The summation is performed by starting at i = [lambda]/2, and then recursing 141in both directions, using the usual recurrence relations for the Poisson 142PDF and incomplete beta functions. This is the "Method 2" described 143by: 144 145Denise Benton and K. Krishnamoorthy, 146"Computing discrete mixtures of continuous 147distributions: noncentral chisquare, noncentral t 148and the distribution of the square of the sample 149multiple correlation coefficient", 150Computational Statistics & Data Analysis 43 (2003) 249-267. 151 152Specific applications of the above formulae to the noncentral 153beta distribution can be found in: 154 155Russell V. Lenth, 156"Algorithm AS 226: Computing Noncentral Beta Probabilities", 157Applied Statistics, Vol. 36, No. 2. (1987), pp. 241-244. 158 159H. Frick, 160"Algorithm AS R84: A Remark on Algorithm AS 226: Computing Non-Central Beta 161Probabilities", Applied Statistics, Vol. 39, No. 2. (1990), pp. 311-312. 162 163Ming Long Lam, 164"Remark AS R95: A Remark on Algorithm AS 226: Computing Non-Central Beta 165Probabilities", Applied Statistics, Vol. 44, No. 4. (1995), pp. 551-552. 166 167Harry O. Posten, 168"An Effective Algorithm for the Noncentral Beta Distribution Function", 169The American Statistician, Vol. 47, No. 2. (May, 1993), pp. 129-131. 170 171R. Chattamvelli, 172"A Note on the Noncentral Beta Distribution Function", 173The American Statistician, Vol. 49, No. 2. (May, 1995), pp. 231-234. 174 175Of these, the Posten reference provides the most complete overview, 176and includes the modification starting iteration at [lambda]/2. 177 178The main difference between this implementation and the above 179references is the direct computation of the complement when most 180efficient to do so, and the accumulation of the sum to -1 rather 181than subtracting the result from 1 at the end: this can substantially 182reduce the number of iterations required when the result is near 1. 183 184The PDF is computed using the methodology of Benton and Krishnamoorthy 185and the relation: 186 187[equation nc_beta_ref1] 188 189Quantiles are computed using a specially modified version of 190__bracket_solve, 191starting the search for the root at the mean of the distribution. 192(A Cornish-Fisher type expansion was also tried, but while this gets 193quite close to the root in many cases, when it is wrong it tends to 194introduce quite pathological behaviour: more investigation in this 195area is probably warranted). 196 197[endsect] [/section:nc_beta_dist] 198 199[/ nc_beta.qbk 200 Copyright 2008 John Maddock and Paul A. Bristow. 201 Distributed under the Boost Software License, Version 1.0. 202 (See accompanying file LICENSE_1_0.txt or copy at 203 http://www.boost.org/LICENSE_1_0.txt). 204] 205 206