3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Noncentral Beta Distribution</title>
5 <link rel="stylesheet" href="../../../math.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../../index.html" title="Math Toolkit 2.11.0">
8 <link rel="up" href="../dists.html" title="Distributions">
9 <link rel="prev" href="negative_binomial_dist.html" title="Negative Binomial Distribution">
10 <link rel="next" href="nc_chi_squared_dist.html" title="Noncentral Chi-Squared Distribution">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="negative_binomial_dist.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="nc_chi_squared_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h4 class="title">
27 <a name="math_toolkit.dist_ref.dists.nc_beta_dist"></a><a class="link" href="nc_beta_dist.html" title="Noncentral Beta Distribution">Noncentral
29 </h4></div></div></div>
30 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">non_central_beta</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></pre>
31 <pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
33 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">RealType</span> <span class="special">=</span> <span class="keyword">double</span><span class="special">,</span>
34 <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> <span class="special">=</span> <a class="link" href="../../pol_ref/pol_ref_ref.html" title="Policy Class Reference">policies::policy<></a> <span class="special">></span>
35 <span class="keyword">class</span> <span class="identifier">non_central_beta_distribution</span><span class="special">;</span>
37 <span class="keyword">typedef</span> <span class="identifier">non_central_beta_distribution</span><span class="special"><></span> <span class="identifier">non_central_beta</span><span class="special">;</span>
39 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">RealType</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
40 <span class="keyword">class</span> <span class="identifier">non_central_beta_distribution</span>
41 <span class="special">{</span>
42 <span class="keyword">public</span><span class="special">:</span>
43 <span class="keyword">typedef</span> <span class="identifier">RealType</span> <span class="identifier">value_type</span><span class="special">;</span>
44 <span class="keyword">typedef</span> <span class="identifier">Policy</span> <span class="identifier">policy_type</span><span class="special">;</span>
46 <span class="comment">// Constructor:</span>
47 <span class="identifier">non_central_beta_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">);</span>
49 <span class="comment">// Accessor to shape parameters:</span>
50 <span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
51 <span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
53 <span class="comment">// Accessor to non-centrality parameter lambda:</span>
54 <span class="identifier">RealType</span> <span class="identifier">non_centrality</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
55 <span class="special">};</span>
57 <span class="special">}}</span> <span class="comment">// namespaces</span>
60 The noncentral beta distribution is a generalization of the <a class="link" href="beta_dist.html" title="Beta Distribution">Beta
64 It is defined as the ratio
66 <div class="blockquote"><blockquote class="blockquote"><p>
67 <span class="serif_italic">X = χ<sub>m</sub><sup>2</sup>(λ) / (χ<sub>m</sub><sup>2</sup>(λ) + χ<sub>n</sub><sup>2</sup>)</span>
68 </p></blockquote></div>
70 where <span class="serif_italic">χ<sub>m</sub><sup>2</sup>(λ)</span> is a noncentral <span class="serif_italic">χ<sup>2</sup></span> random variable with <span class="emphasis"><em>m</em></span>
71 degrees of freedom, and χ<sub>n</sub><sup>2</sup>
72 is a central <span class="serif_italic">χ<sup>2</sup> </span>
73 random variable with <span class="emphasis"><em>n</em></span> degrees of freedom.
76 This gives a PDF that can be expressed as a Poisson mixture of beta distribution
79 <div class="blockquote"><blockquote class="blockquote"><p>
80 <span class="inlinemediaobject"><img src="../../../../equations/nc_beta_ref1.svg"></span>
82 </p></blockquote></div>
84 where P(i;λ/2) is the discrete Poisson probablity at <span class="emphasis"><em>i</em></span>,
85 with mean λ/2, and I<sub>x</sub><sup>'</sup>(α, β) is the derivative of the incomplete beta function.
86 This leads to the usual form of the CDF as:
88 <div class="blockquote"><blockquote class="blockquote"><p>
89 <span class="inlinemediaobject"><img src="../../../../equations/nc_beta_ref2.svg"></span>
91 </p></blockquote></div>
93 The following graph illustrates how the distribution changes for different
96 <div class="blockquote"><blockquote class="blockquote"><p>
97 <span class="inlinemediaobject"><img src="../../../../graphs/nc_beta_pdf.svg" align="middle"></span>
99 </p></blockquote></div>
101 <a name="math_toolkit.dist_ref.dists.nc_beta_dist.h0"></a>
102 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_beta_dist.member_functions"></a></span><a class="link" href="nc_beta_dist.html#math_toolkit.dist_ref.dists.nc_beta_dist.member_functions">Member
105 <pre class="programlisting"><span class="identifier">non_central_beta_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">);</span>
108 Constructs a noncentral beta distribution with shape parameters <span class="emphasis"><em>a</em></span>
109 and <span class="emphasis"><em>b</em></span> and non-centrality parameter <span class="emphasis"><em>lambda</em></span>.
112 Requires a > 0, b > 0 and lambda >= 0, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
114 <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
117 Returns the parameter <span class="emphasis"><em>a</em></span> from which this object was
120 <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
123 Returns the parameter <span class="emphasis"><em>b</em></span> from which this object was
126 <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">non_centrality</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
129 Returns the parameter <span class="emphasis"><em>lambda</em></span> from which this object
133 <a name="math_toolkit.dist_ref.dists.nc_beta_dist.h1"></a>
134 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_beta_dist.non_member_accessors"></a></span><a class="link" href="nc_beta_dist.html#math_toolkit.dist_ref.dists.nc_beta_dist.non_member_accessors">Non-member
138 Most of the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member
139 accessor functions</a> are supported: <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative
140 Distribution Function</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability
141 Density Function</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a>,
142 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mean">mean</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.variance">variance</a>,
143 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
144 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.median">median</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mode">mode</a>,
145 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.hazard">Hazard Function</a>,
146 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.chf">Cumulative Hazard Function</a>,
147 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.range">range</a> and <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.support">support</a>.
150 Mean and variance are implemented using hypergeometric pfq functions and
151 relations given in <a href="http://reference.wolfram.com/mathematica/ref/NoncentralBetaDistribution.html" target="_top">Wolfram
152 Noncentral Beta Distribution</a>.
155 However, the following are not currently implemented: <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.skewness">skewness</a>,
156 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis">kurtosis</a> and
157 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess">kurtosis_excess</a>.
160 The domain of the random variable is [0, 1].
163 <a name="math_toolkit.dist_ref.dists.nc_beta_dist.h2"></a>
164 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_beta_dist.accuracy"></a></span><a class="link" href="nc_beta_dist.html#math_toolkit.dist_ref.dists.nc_beta_dist.accuracy">Accuracy</a>
167 The following table shows the peak errors (in units of <a href="http://en.wikipedia.org/wiki/Machine_epsilon" target="_top">epsilon</a>)
168 found on various platforms with various floating point types. The failures
169 in the comparison to the <a href="http://www.r-project.org/" target="_top">R Math
170 library</a>, seem to be mostly in the corner cases when the probablity
171 would be very small. Unless otherwise specified any floating-point type
172 that is narrower than the one shown will have <a class="link" href="../../relative_error.html#math_toolkit.relative_error.zero_error">effectively
176 <a name="math_toolkit.dist_ref.dists.nc_beta_dist.table_non_central_beta_CDF"></a><p class="title"><b>Table 5.4. Error rates for non central beta CDF</b></p>
177 <div class="table-contents"><table class="table" summary="Error rates for non central beta CDF">
190 GNU C++ version 7.1.0<br> linux<br> double
195 GNU C++ version 7.1.0<br> linux<br> long double
200 Sun compiler version 0x5150<br> Sun Solaris<br> long double
205 Microsoft Visual C++ version 14.1<br> Win32<br> double
213 Non Central Beta, medium parameters
218 <span class="blue">Max = 0.998ε (Mean = 0.0649ε)</span><br>
219 <br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span> <span class="red">Max
220 = 1.46e+26ε (Mean = 3.5e+24ε) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_non_central_beta_CDF_Rmath_3_2_3_Non_Central_Beta_medium_parameters">And
221 other failures.</a>)</span>
226 <span class="blue">Max = 824ε (Mean = 27.4ε)</span>
231 <span class="blue">Max = 832ε (Mean = 38.1ε)</span>
236 <span class="blue">Max = 242ε (Mean = 31ε)</span>
243 Non Central Beta, large parameters
248 <span class="blue">Max = 1.18ε (Mean = 0.175ε)</span><br>
249 <br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span> <span class="red">Max
250 = 1.01e+36ε (Mean = 1.19e+35ε) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_non_central_beta_CDF_Rmath_3_2_3_Non_Central_Beta_large_parameters">And
251 other failures.</a>)</span>
256 <span class="blue">Max = 2.5e+04ε (Mean = 3.78e+03ε)</span>
261 <span class="blue">Max = 2.57e+04ε (Mean = 4.45e+03ε)</span>
266 <span class="blue">Max = 3.66e+03ε (Mean = 500ε)</span>
273 <br class="table-break"><div class="table">
274 <a name="math_toolkit.dist_ref.dists.nc_beta_dist.table_non_central_beta_CDF_complement"></a><p class="title"><b>Table 5.5. Error rates for non central beta CDF complement</b></p>
275 <div class="table-contents"><table class="table" summary="Error rates for non central beta CDF complement">
288 GNU C++ version 7.1.0<br> linux<br> double
293 GNU C++ version 7.1.0<br> linux<br> long double
298 Sun compiler version 0x5150<br> Sun Solaris<br> long double
303 Microsoft Visual C++ version 14.1<br> Win32<br> double
311 Non Central Beta, medium parameters
316 <span class="blue">Max = 0.998ε (Mean = 0.0936ε)</span><br>
317 <br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span> <span class="red">Max
318 = 7.5e+97ε (Mean = 1.37e+96ε) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_non_central_beta_CDF_complement_Rmath_3_2_3_Non_Central_Beta_medium_parameters">And
319 other failures.</a>)</span>
324 <span class="blue">Max = 396ε (Mean = 50.7ε)</span>
329 <span class="blue">Max = 554ε (Mean = 57.2ε)</span>
334 <span class="blue">Max = 624ε (Mean = 62.7ε)</span>
341 Non Central Beta, large parameters
346 <span class="blue">Max = 0.986ε (Mean = 0.188ε)</span><br>
347 <br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span> <span class="red">Max
348 = +INFε (Mean = +INFε) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_non_central_beta_CDF_complement_Rmath_3_2_3_Non_Central_Beta_large_parameters">And
349 other failures.</a>)</span>
354 <span class="blue">Max = 6.83e+03ε (Mean = 993ε)</span>
359 <span class="blue">Max = 3.56e+03ε (Mean = 707ε)</span>
364 <span class="blue">Max = 1.25e+04ε (Mean = 1.49e+03ε)</span>
371 <br class="table-break"><p>
372 Error rates for the PDF, the complement of the CDF and for the quantile
373 functions are broadly similar.
376 <a name="math_toolkit.dist_ref.dists.nc_beta_dist.h3"></a>
377 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_beta_dist.tests"></a></span><a class="link" href="nc_beta_dist.html#math_toolkit.dist_ref.dists.nc_beta_dist.tests">Tests</a>
380 There are two sets of test data used to verify this implementation: firstly
381 we can compare with a few sample values generated by the <a href="http://www.r-project.org/" target="_top">R
382 library</a>. Secondly, we have tables of test data, computed with this
383 implementation and using interval arithmetic - this data should be accurate
384 to at least 50 decimal digits - and is the used for our accuracy tests.
387 <a name="math_toolkit.dist_ref.dists.nc_beta_dist.h4"></a>
388 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_beta_dist.implementation"></a></span><a class="link" href="nc_beta_dist.html#math_toolkit.dist_ref.dists.nc_beta_dist.implementation">Implementation</a>
391 The CDF and its complement are evaluated as follows:
394 First we determine which of the two values (the CDF or its complement)
395 is likely to be the smaller, the crossover point is taken to be the mean
396 of the distribution: for this we use the approximation due to: R. Chattamvelli
397 and R. Shanmugam, "Algorithm AS 310: Computing the Non-Central Beta
398 Distribution Function", Applied Statistics, Vol. 46, No. 1. (1997),
401 <div class="blockquote"><blockquote class="blockquote"><p>
402 <span class="inlinemediaobject"><img src="../../../../equations/nc_beta_ref3.svg"></span>
404 </p></blockquote></div>
406 Then either the CDF or its complement is computed using the relations:
408 <div class="blockquote"><blockquote class="blockquote"><p>
409 <span class="inlinemediaobject"><img src="../../../../equations/nc_beta_ref4.svg"></span>
411 </p></blockquote></div>
413 The summation is performed by starting at i = λ/2, and then recursing in
414 both directions, using the usual recurrence relations for the Poisson PDF
415 and incomplete beta functions. This is the "Method 2" described
419 Denise Benton and K. Krishnamoorthy, "Computing discrete mixtures
420 of continuous distributions: noncentral chisquare, noncentral t and the
421 distribution of the square of the sample multiple correlation coefficient",
422 Computational Statistics & Data Analysis 43 (2003) 249-267.
425 Specific applications of the above formulae to the noncentral beta distribution
429 Russell V. Lenth, "Algorithm AS 226: Computing Noncentral Beta Probabilities",
430 Applied Statistics, Vol. 36, No. 2. (1987), pp. 241-244.
433 H. Frick, "Algorithm AS R84: A Remark on Algorithm AS 226: Computing
434 Non-Central Beta Probabilities", Applied Statistics, Vol. 39, No.
435 2. (1990), pp. 311-312.
438 Ming Long Lam, "Remark AS R95: A Remark on Algorithm AS 226: Computing
439 Non-Central Beta Probabilities", Applied Statistics, Vol. 44, No.
440 4. (1995), pp. 551-552.
443 Harry O. Posten, "An Effective Algorithm for the Noncentral Beta Distribution
444 Function", The American Statistician, Vol. 47, No. 2. (May, 1993),
448 R. Chattamvelli, "A Note on the Noncentral Beta Distribution Function",
449 The American Statistician, Vol. 49, No. 2. (May, 1995), pp. 231-234.
452 Of these, the Posten reference provides the most complete overview, and
453 includes the modification starting iteration at λ/2.
456 The main difference between this implementation and the above references
457 is the direct computation of the complement when most efficient to do so,
458 and the accumulation of the sum to -1 rather than subtracting the result
459 from 1 at the end: this can substantially reduce the number of iterations
460 required when the result is near 1.
463 The PDF is computed using the methodology of Benton and Krishnamoorthy
466 <div class="blockquote"><blockquote class="blockquote"><p>
467 <span class="inlinemediaobject"><img src="../../../../equations/nc_beta_ref1.svg"></span>
469 </p></blockquote></div>
471 Quantiles are computed using a specially modified version of <a class="link" href="../../roots_noderiv/bracket_solve.html" title="Bracket and Solve Root">bracket
472 and solve</a>, starting the search for the root at the mean of the distribution.
473 (A Cornish-Fisher type expansion was also tried, but while this gets quite
474 close to the root in many cases, when it is wrong it tends to introduce
475 quite pathological behaviour: more investigation in this area is probably
479 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
480 <td align="left"></td>
481 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
482 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
483 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
484 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
485 Daryle Walker and Xiaogang Zhang<p>
486 Distributed under the Boost Software License, Version 1.0. (See accompanying
487 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
492 <div class="spirit-nav">
493 <a accesskey="p" href="negative_binomial_dist.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="nc_chi_squared_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>