3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Noncentral T 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="nc_f_dist.html" title="Noncentral F Distribution">
10 <link rel="next" href="normal_dist.html" title="Normal (Gaussian) 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="nc_f_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="normal_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_t_dist"></a><a class="link" href="nc_t_dist.html" title="Noncentral T Distribution">Noncentral T
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_t</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_t_distribution</span><span class="special">;</span>
37 <span class="keyword">typedef</span> <span class="identifier">non_central_t_distribution</span><span class="special"><></span> <span class="identifier">non_central_t</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_t_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_t_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">delta</span><span class="special">);</span>
49 <span class="comment">// Accessor to degrees_of_freedom parameter v:</span>
50 <span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
52 <span class="comment">// Accessor to non-centrality parameter delta:</span>
53 <span class="identifier">RealType</span> <span class="identifier">non_centrality</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
54 <span class="special">};</span>
56 <span class="special">}}</span> <span class="comment">// namespaces</span>
59 The noncentral T distribution is a generalization of the <a class="link" href="students_t_dist.html" title="Students t Distribution">Students
60 t Distribution</a>. Let X have a normal distribution with mean δ and variance
61 1, and let <span class="emphasis"><em>ν S<sup>2</sup></em></span> have a chi-squared distribution with
62 degrees of freedom ν. Assume that X and S<sup>2</sup> are independent. The distribution
63 of <span class="serif_italic">t<sub>ν</sub>(δ)=X/S</span> is called a noncentral
64 t distribution with degrees of freedom ν and noncentrality parameter δ.
67 This gives the following PDF:
69 <div class="blockquote"><blockquote class="blockquote"><p>
70 <span class="inlinemediaobject"><img src="../../../../equations/nc_t_ref1.svg"></span>
72 </p></blockquote></div>
74 where <span class="serif_italic"><sub>1</sub>F<sub>1</sub>(a;b;x)</span> is a confluent hypergeometric
78 The following graph illustrates how the distribution changes for different
79 values of ν and δ:
81 <div class="blockquote"><blockquote class="blockquote"><p>
82 <span class="inlinemediaobject"><img src="../../../../graphs/nc_t_pdf.svg" align="middle"></span>
84 </p></blockquote></div>
85 <div class="blockquote"><blockquote class="blockquote"><p>
86 <span class="inlinemediaobject"><img src="../../../../graphs/nc_t_cdf.svg" align="middle"></span>
88 </p></blockquote></div>
90 <a name="math_toolkit.dist_ref.dists.nc_t_dist.h0"></a>
91 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_t_dist.member_functions"></a></span><a class="link" href="nc_t_dist.html#math_toolkit.dist_ref.dists.nc_t_dist.member_functions">Member
94 <pre class="programlisting"><span class="identifier">non_central_t_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">delta</span><span class="special">);</span>
97 Constructs a non-central t distribution with degrees of freedom parameter
98 <span class="emphasis"><em>v</em></span> and non-centrality parameter <span class="emphasis"><em>delta</em></span>.
101 Requires <span class="emphasis"><em>v</em></span> > 0 (including positive infinity) and
102 finite <span class="emphasis"><em>delta</em></span>, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
104 <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
107 Returns the parameter <span class="emphasis"><em>v</em></span> from which this object was
110 <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>
113 Returns the non-centrality parameter <span class="emphasis"><em>delta</em></span> from which
114 this object was constructed.
117 <a name="math_toolkit.dist_ref.dists.nc_t_dist.h1"></a>
118 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_t_dist.non_member_accessors"></a></span><a class="link" href="nc_t_dist.html#math_toolkit.dist_ref.dists.nc_t_dist.non_member_accessors">Non-member
122 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
123 functions</a> that are generic to all distributions are supported:
124 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
125 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
126 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.hazard">Hazard Function</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.chf">Cumulative Hazard Function</a>,
127 <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.median">median</a>,
128 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mode">mode</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.variance">variance</a>,
129 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
130 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.skewness">skewness</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis">kurtosis</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess">kurtosis_excess</a>,
131 <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>.
134 The domain of the random variable is [-∞, +∞].
137 <a name="math_toolkit.dist_ref.dists.nc_t_dist.h2"></a>
138 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_t_dist.accuracy"></a></span><a class="link" href="nc_t_dist.html#math_toolkit.dist_ref.dists.nc_t_dist.accuracy">Accuracy</a>
141 The following table shows the peak errors (in units of <a href="http://en.wikipedia.org/wiki/Machine_epsilon" target="_top">epsilon</a>)
142 found on various platforms with various floating-point types. Unless otherwise
143 specified, any floating-point type that is narrower than the one shown
144 will have <a class="link" href="../../relative_error.html#math_toolkit.relative_error.zero_error">effectively
148 <a name="math_toolkit.dist_ref.dists.nc_t_dist.table_non_central_t_CDF"></a><p class="title"><b>Table 5.8. Error rates for non central t CDF</b></p>
149 <div class="table-contents"><table class="table" summary="Error rates for non central t CDF">
162 GNU C++ version 7.1.0<br> linux<br> double
167 GNU C++ version 7.1.0<br> linux<br> long double
172 Sun compiler version 0x5150<br> Sun Solaris<br> long double
177 Microsoft Visual C++ version 14.1<br> Win32<br> double
190 <span class="blue">Max = 0.796ε (Mean = 0.0691ε)</span><br>
191 <br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span> <span class="red">Max
192 = 5.28e+15ε (Mean = 8.49e+14ε) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_non_central_t_CDF_Rmath_3_2_3_Non_Central_T">And
193 other failures.</a>)</span>
198 <span class="blue">Max = 139ε (Mean = 31ε)</span>
203 <span class="blue">Max = 145ε (Mean = 30.9ε)</span>
208 <span class="blue">Max = 135ε (Mean = 32.1ε)</span>
215 Non Central T (small non-centrality)
220 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>Rmath
221 3.2.3:</em></span> Max = 2.09e+03ε (Mean = 244ε))
226 <span class="blue">Max = 3.86ε (Mean = 1.4ε)</span>
231 <span class="blue">Max = 9.15ε (Mean = 2.13ε)</span>
236 <span class="blue">Max = 6.17ε (Mean = 1.45ε)</span>
243 Non Central T (large parameters)
248 <span class="blue">Max = 257ε (Mean = 72.1ε)</span><br> <br>
249 (<span class="emphasis"><em>Rmath 3.2.3:</em></span> Max = 2.46ε (Mean = 0.657ε))
254 <span class="blue">Max = 5.26e+05ε (Mean = 1.48e+05ε)</span>
259 <span class="blue">Max = 5.24e+05ε (Mean = 1.47e+05ε)</span>
264 <span class="blue">Max = 286ε (Mean = 62.8ε)</span>
271 <br class="table-break"><div class="table">
272 <a name="math_toolkit.dist_ref.dists.nc_t_dist.table_non_central_t_CDF_complement"></a><p class="title"><b>Table 5.9. Error rates for non central t CDF complement</b></p>
273 <div class="table-contents"><table class="table" summary="Error rates for non central t CDF complement">
286 GNU C++ version 7.1.0<br> linux<br> double
291 GNU C++ version 7.1.0<br> linux<br> long double
296 Sun compiler version 0x5150<br> Sun Solaris<br> long double
301 Microsoft Visual C++ version 14.1<br> Win32<br> double
314 <span class="blue">Max = 0.707ε (Mean = 0.0497ε)</span><br>
315 <br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span> <span class="red">Max
316 = 6.19e+15ε (Mean = 6.72e+14ε) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_non_central_t_CDF_complement_Rmath_3_2_3_Non_Central_T">And
317 other failures.</a>)</span>
322 <span class="blue">Max = 201ε (Mean = 31.7ε)</span>
327 <span class="blue">Max = 340ε (Mean = 43.2ε)</span>
332 <span class="blue">Max = 154ε (Mean = 32.1ε)</span>
339 Non Central T (small non-centrality)
344 <span class="blue">Max = 0ε (Mean = 0ε)</span><br> <br> (<span class="emphasis"><em>Rmath
345 3.2.3:</em></span> Max = 1.87e+03ε (Mean = 263ε))
350 <span class="blue">Max = 10.5ε (Mean = 2.13ε)</span>
355 <span class="blue">Max = 10.5ε (Mean = 2.39ε)</span>
360 <span class="blue">Max = 4.6ε (Mean = 1.63ε)</span>
367 Non Central T (large parameters)
372 <span class="blue">Max = 478ε (Mean = 96.3ε)</span><br> <br>
373 (<span class="emphasis"><em>Rmath 3.2.3:</em></span> Max = 2.24ε (Mean = 0.945ε))
378 <span class="blue">Max = 9.79e+05ε (Mean = 1.97e+05ε)</span>
383 <span class="blue">Max = 9.79e+05ε (Mean = 1.97e+05ε)</span>
388 <span class="blue">Max = 227ε (Mean = 50.4ε)</span>
395 <br class="table-break"><div class="caution"><table border="0" summary="Caution">
397 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../doc/src/images/caution.png"></td>
398 <th align="left">Caution</th>
400 <tr><td align="left" valign="top"><p>
401 The complexity of the current algorithm is dependent upon δ<sup>2</sup>: consequently
402 the time taken to evaluate the CDF increases rapidly for δ > 500, likewise
403 the accuracy decreases rapidly for very large δ.
407 Accuracy for the quantile and PDF functions should be broadly similar.
408 The <span class="emphasis"><em>mode</em></span> is determined numerically and cannot in principal
409 be more accurate than the square root of floating-point type FPT epsilon,
410 accessed using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tools</span><span class="special">::</span><span class="identifier">epsilon</span><span class="special"><</span><span class="identifier">FPT</span><span class="special">>()</span></code>.
411 For 64-bit <code class="computeroutput"><span class="keyword">double</span></code>, epsilon
412 is about 1e-16, so the fractional accuracy is limited to 1e-8.
415 <a name="math_toolkit.dist_ref.dists.nc_t_dist.h3"></a>
416 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_t_dist.tests"></a></span><a class="link" href="nc_t_dist.html#math_toolkit.dist_ref.dists.nc_t_dist.tests">Tests</a>
419 There are two sets of tests of this distribution:
422 Basic sanity checks compare this implementation to the test values given
423 in "Computing discrete mixtures of continuous distributions: noncentral
424 chisquare, noncentral t and the distribution of the square of the sample
425 multiple correlation coefficient." Denise Benton, K. Krishnamoorthy,
426 Computational Statistics & Data Analysis 43 (2003) 249-267.
429 Accuracy checks use test data computed with this implementation and arbitary
430 precision interval arithmetic: this test data is believed to be accurate
431 to at least 50 decimal places.
434 The cases of large (or infinite) ν and/or large δ has received special treatment
435 to avoid catastrophic loss of accuracy. New tests have been added to confirm
436 the improvement achieved.
439 From Boost 1.52, degrees of freedom ν can be +∞
440 when the normal distribution
442 (equivalent to the central Student's t distribution) is used
443 in place for accuracy and speed.
446 <a name="math_toolkit.dist_ref.dists.nc_t_dist.h4"></a>
447 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_t_dist.implementation"></a></span><a class="link" href="nc_t_dist.html#math_toolkit.dist_ref.dists.nc_t_dist.implementation">Implementation</a>
450 The CDF is computed using a modification of the method described in "Computing
451 discrete mixtures of continuous distributions: noncentral chisquare, noncentral
452 t and the distribution of the square of the sample multiple correlation
453 coefficient." Denise Benton, K. Krishnamoorthy, Computational Statistics
454 & Data Analysis 43 (2003) 249-267.
457 This uses the following formula for the CDF:
459 <div class="blockquote"><blockquote class="blockquote"><p>
460 <span class="inlinemediaobject"><img src="../../../../equations/nc_t_ref2.svg"></span>
462 </p></blockquote></div>
464 Where I<sub>x</sub>(a,b) is the incomplete beta function, and Φ(x) is the normal CDF
468 Iteration starts at the largest of the Poisson weighting terms (at i =
469 δ<sup>2</sup> / 2) and then proceeds in both directions as per Benton and Krishnamoorthy's
473 Alternatively, by considering what happens when t = ∞, we have x = 1, and
474 therefore I<sub>x</sub>(a,b) = 1 and:
476 <div class="blockquote"><blockquote class="blockquote"><p>
477 <span class="inlinemediaobject"><img src="../../../../equations/nc_t_ref3.svg"></span>
479 </p></blockquote></div>
481 From this we can easily show that:
483 <div class="blockquote"><blockquote class="blockquote"><p>
484 <span class="inlinemediaobject"><img src="../../../../equations/nc_t_ref4.svg"></span>
486 </p></blockquote></div>
488 and therefore we have a means to compute either the probability or its
489 complement directly without the risk of cancellation error. The crossover
490 criterion for choosing whether to calculate the CDF or its complement is
491 the same as for the <a class="link" href="nc_beta_dist.html" title="Noncentral Beta Distribution">Noncentral
492 Beta Distribution</a>.
495 The PDF can be computed by a very similar method using:
497 <div class="blockquote"><blockquote class="blockquote"><p>
498 <span class="inlinemediaobject"><img src="../../../../equations/nc_t_ref5.svg"></span>
500 </p></blockquote></div>
502 Where I<sub>x</sub><sup>'</sup>(a,b) is the derivative of the incomplete beta function.
505 For both the PDF and CDF we switch to approximating the distribution by
506 a Student's t distribution centred on δ when ν is very large. The crossover
507 location appears to be when δ/(4ν) < ε, this location was estimated by
508 inspection of equation 2.6 in "A Comparison of Approximations To Percentiles
509 of the Noncentral t-Distribution". H. Sahai and M. M. Ojeda, Revista
510 Investigacion Operacional Vol 21, No 2, 2000, page 123.
513 Equation 2.6 is a Fisher-Cornish expansion by Eeden and Johnson. The second
514 term includes the ratio δ/(4ν), so when this term become negligible, this
515 and following terms can be ignored, leaving just Student's t distribution
519 This was also confirmed by experimental testing.
524 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
525 <li class="listitem">
526 "Some Approximations to the Percentage Points of the Noncentral
527 t-Distribution". C. van Eeden. International Statistical Review,
530 <li class="listitem">
531 "Continuous Univariate Distributions". N.L. Johnson, S. Kotz
532 and N. Balkrishnan. 1995. John Wiley and Sons New York.
536 The quantile is calculated via the usual <a class="link" href="../../roots_noderiv.html" title="Root Finding Without Derivatives">root-finding
537 without derivatives</a> method with the initial guess taken as the quantile
538 of a normal approximation to the noncentral T.
541 There is no closed form for the mode, so this is computed via functional
542 maximisation of the PDF.
545 The remaining functions (mean, variance etc) are implemented using the
546 formulas given in Weisstein, Eric W. "Noncentral Student's t-Distribution."
547 From MathWorld--A Wolfram Web Resource. <a href="http://mathworld.wolfram.com/NoncentralStudentst-Distribution.html" target="_top">http://mathworld.wolfram.com/NoncentralStudentst-Distribution.html</a>
548 and in the <a href="http://reference.wolfram.com/mathematica/ref/NoncentralStudentTDistribution.html" target="_top">Mathematica
552 Some analytic properties of noncentral distributions (particularly unimodality,
553 and monotonicity of their modes) are surveyed and summarized by:
556 Andrea van Aubel & Wolfgang Gawronski, Applied Mathematics and Computation,
560 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
561 <td align="left"></td>
562 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
563 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
564 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
565 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
566 Daryle Walker and Xiaogang Zhang<p>
567 Distributed under the Boost Software License, Version 1.0. (See accompanying
568 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>)
573 <div class="spirit-nav">
574 <a accesskey="p" href="nc_f_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="normal_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>