3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Noncentral Chi-Squared 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_beta_dist.html" title="Noncentral Beta Distribution">
10 <link rel="next" href="nc_f_dist.html" title="Noncentral F 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_beta_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_f_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_chi_squared_dist"></a><a class="link" href="nc_chi_squared_dist.html" title="Noncentral Chi-Squared Distribution">Noncentral
28 Chi-Squared Distribution</a>
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_chi_squared</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_chi_squared_distribution</span><span class="special">;</span>
37 <span class="keyword">typedef</span> <span class="identifier">non_central_chi_squared_distribution</span><span class="special"><></span> <span class="identifier">non_central_chi_squared</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_chi_squared_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_chi_squared_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">lambda</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 lambda:</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>
55 <span class="comment">// Parameter finders:</span>
56 <span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
57 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">A</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">C</span><span class="special">></span>
58 <span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">complemented3_type</span><span class="special"><</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">,</span><span class="identifier">C</span><span class="special">>&</span> <span class="identifier">c</span><span class="special">);</span>
60 <span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_non_centrality</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">x</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
61 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">A</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">C</span><span class="special">></span>
62 <span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_non_centrality</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">complemented3_type</span><span class="special"><</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">,</span><span class="identifier">C</span><span class="special">>&</span> <span class="identifier">c</span><span class="special">);</span>
63 <span class="special">};</span>
65 <span class="special">}}</span> <span class="comment">// namespaces</span>
68 The noncentral chi-squared distribution is a generalization of the <a class="link" href="chi_squared_dist.html" title="Chi Squared Distribution">Chi Squared Distribution</a>.
69 If <span class="emphasis"><em>X<sub>i</sub></em></span> are /ν/ independent, normally distributed random
70 variables with means /μ<sub>i</sub>/ and variances <span class="emphasis"><em>σ<sub>i</sub><sup>2</sup></em></span>, then the
73 <div class="blockquote"><blockquote class="blockquote"><p>
74 <span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref1.svg"></span>
76 </p></blockquote></div>
78 is distributed according to the noncentral chi-squared distribution.
81 The noncentral chi-squared distribution has two parameters: /ν/ which specifies
82 the number of degrees of freedom (i.e. the number of <span class="emphasis"><em>X<sub>i</sub>)</em></span>,
83 and λ which is related to the mean of the random variables <span class="emphasis"><em>X<sub>i</sub></em></span>
86 <div class="blockquote"><blockquote class="blockquote"><p>
87 <span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref2.svg"></span>
89 </p></blockquote></div>
91 (Note that some references define λ as one half of the above sum).
94 This leads to a PDF of:
96 <div class="blockquote"><blockquote class="blockquote"><p>
97 <span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref3.svg"></span>
99 </p></blockquote></div>
101 where <span class="emphasis"><em>f(x;k)</em></span> is the central chi-squared distribution
102 PDF, and <span class="emphasis"><em>I<sub>v</sub>(x)</em></span> is a modified Bessel function of the
106 The following graph illustrates how the distribution changes for different
109 <div class="blockquote"><blockquote class="blockquote"><p>
110 <span class="inlinemediaobject"><img src="../../../../graphs/nccs_pdf.svg" align="middle"></span>
112 </p></blockquote></div>
114 <a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h0"></a>
115 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.member_functions"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_dist.member_functions">Member
118 <pre class="programlisting"><span class="identifier">non_central_chi_squared_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">lambda</span><span class="special">);</span>
121 Constructs a Chi-Squared distribution with <span class="emphasis"><em>v</em></span> degrees
122 of freedom and non-centrality parameter <span class="emphasis"><em>lambda</em></span>.
125 Requires v > 0 and lambda >= 0, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
127 <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>
130 Returns the parameter <span class="emphasis"><em>v</em></span> from which this object was
133 <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>
136 Returns the parameter <span class="emphasis"><em>lambda</em></span> from which this object
139 <pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
142 This function returns the number of degrees of freedom <span class="emphasis"><em>v</em></span>
143 such that: <code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">non_central_chi_squared</span><span class="special"><</span><span class="identifier">RealType</span><span class="special">,</span> <span class="identifier">Policy</span><span class="special">>(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">),</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">p</span></code>
145 <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">A</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">C</span><span class="special">></span>
146 <span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">complemented3_type</span><span class="special"><</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">,</span><span class="identifier">C</span><span class="special">>&</span> <span class="identifier">c</span><span class="special">);</span>
149 When called with argument <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">lambda</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span>
150 <span class="identifier">q</span><span class="special">)</span></code>
151 this function returns the number of degrees of freedom <span class="emphasis"><em>v</em></span>
155 <code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">non_central_chi_squared</span><span class="special"><</span><span class="identifier">RealType</span><span class="special">,</span> <span class="identifier">Policy</span><span class="special">>(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">),</span> <span class="identifier">x</span><span class="special">))</span> <span class="special">==</span> <span class="identifier">q</span></code>.
157 <pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_non_centrality</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">x</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span>
160 This function returns the non centrality parameter <span class="emphasis"><em>lambda</em></span>
164 <code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">non_central_chi_squared</span><span class="special"><</span><span class="identifier">RealType</span><span class="special">,</span> <span class="identifier">Policy</span><span class="special">>(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">),</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">p</span></code>
166 <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">A</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">B</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">C</span><span class="special">></span>
167 <span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_non_centrality</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">complemented3_type</span><span class="special"><</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">,</span><span class="identifier">C</span><span class="special">>&</span> <span class="identifier">c</span><span class="special">);</span>
170 When called with argument <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span>
171 <span class="identifier">x</span><span class="special">,</span>
172 <span class="identifier">q</span><span class="special">)</span></code>
173 this function returns the non centrality parameter <span class="emphasis"><em>lambda</em></span>
177 <code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">non_central_chi_squared</span><span class="special"><</span><span class="identifier">RealType</span><span class="special">,</span> <span class="identifier">Policy</span><span class="special">>(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">lambda</span><span class="special">),</span> <span class="identifier">x</span><span class="special">))</span> <span class="special">==</span> <span class="identifier">q</span></code>.
180 <a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h1"></a>
181 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.non_member_accessors"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_dist.non_member_accessors">Non-member
185 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
186 functions</a> that are generic to all distributions are supported:
187 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
188 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
189 <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>,
190 <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>,
191 <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>,
192 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
193 <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>,
194 <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>.
197 The domain of the random variable is [0, +∞].
200 <a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h2"></a>
201 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.examples"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_dist.examples">Examples</a>
204 There is a <a class="link" href="../../stat_tut/weg/nccs_eg.html" title="Non Central Chi Squared Example">worked example</a>
205 for the noncentral chi-squared distribution.
208 <a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h3"></a>
209 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.accuracy"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_dist.accuracy">Accuracy</a>
212 The following table shows the peak errors (in units of <a href="http://en.wikipedia.org/wiki/Machine_epsilon" target="_top">epsilon</a>)
213 found on various platforms with various floating point types. The failures
214 in the comparison to the <a href="http://www.r-project.org/" target="_top">R Math
215 library</a>, seem to be mostly in the corner cases when the probablity
216 would be very small. Unless otherwise specified any floating-point type
217 that is narrower than the one shown will have <a class="link" href="../../relative_error.html#math_toolkit.relative_error.zero_error">effectively
221 <a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.table_non_central_chi_squared_CDF"></a><p class="title"><b>Table 5.6. Error rates for non central chi squared CDF</b></p>
222 <div class="table-contents"><table class="table" summary="Error rates for non central chi squared CDF">
235 GNU C++ version 7.1.0<br> linux<br> double
240 GNU C++ version 7.1.0<br> linux<br> long double
245 Sun compiler version 0x5150<br> Sun Solaris<br> long double
250 Microsoft Visual C++ version 14.1<br> Win32<br> double
258 Non Central Chi Squared, medium parameters
263 <span class="blue">Max = 0.99ε (Mean = 0.0544ε)</span><br>
264 <br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span> Max = 727ε (Mean = 121ε))
269 <span class="blue">Max = 46.5ε (Mean = 10.3ε)</span>
274 <span class="blue">Max = 115ε (Mean = 13.9ε)</span>
279 <span class="blue">Max = 48.9ε (Mean = 10ε)</span>
286 Non Central Chi Squared, large parameters
291 <span class="blue">Max = 1.07ε (Mean = 0.102ε)</span><br>
292 <br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span> <span class="red">Max
293 = 3.27e+08ε (Mean = 2.23e+07ε))</span>
298 <span class="blue">Max = 3.07e+03ε (Mean = 336ε)</span>
303 <span class="blue">Max = 6.17e+03ε (Mean = 677ε)</span>
308 <span class="blue">Max = 9.79e+03ε (Mean = 723ε)</span>
315 <br class="table-break"><div class="table">
316 <a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.table_non_central_chi_squared_CDF_complement"></a><p class="title"><b>Table 5.7. Error rates for non central chi squared CDF complement</b></p>
317 <div class="table-contents"><table class="table" summary="Error rates for non central chi squared CDF complement">
330 GNU C++ version 7.1.0<br> linux<br> double
335 GNU C++ version 7.1.0<br> linux<br> long double
340 Sun compiler version 0x5150<br> Sun Solaris<br> long double
345 Microsoft Visual C++ version 14.1<br> Win32<br> double
353 Non Central Chi Squared, medium parameters
358 <span class="blue">Max = 0.96ε (Mean = 0.0635ε)</span><br>
359 <br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span> <span class="red">Max
360 = +INFε (Mean = +INFε) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_non_central_chi_squared_CDF_complement_Rmath_3_2_3_Non_Central_Chi_Squared_medium_parameters">And
361 other failures.</a>)</span>
366 <span class="blue">Max = 107ε (Mean = 17.2ε)</span>
371 <span class="blue">Max = 171ε (Mean = 22.8ε)</span>
376 <span class="blue">Max = 98.6ε (Mean = 15.8ε)</span>
383 Non Central Chi Squared, large parameters
388 <span class="blue">Max = 2.11ε (Mean = 0.278ε)</span><br>
389 <br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span> <span class="red">Max
390 = +INFε (Mean = +INFε) <a class="link" href="../../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_non_central_chi_squared_CDF_complement_Rmath_3_2_3_Non_Central_Chi_Squared_large_parameters">And
391 other failures.</a>)</span>
396 <span class="blue">Max = 5.02e+03ε (Mean = 630ε)</span>
401 <span class="blue">Max = 5.1e+03ε (Mean = 577ε)</span>
406 <span class="blue">Max = 5.43e+03ε (Mean = 705ε)</span>
413 <br class="table-break"><p>
414 Error rates for the quantile functions are broadly similar. Special mention
415 should go to the <code class="computeroutput"><span class="identifier">mode</span></code> function:
416 there is no closed form for this function, so it is evaluated numerically
417 by finding the maxima of the PDF: in principal this can not produce an
418 accuracy greater than the square root of the machine epsilon.
421 <a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h4"></a>
422 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.tests"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_dist.tests">Tests</a>
425 There are two sets of test data used to verify this implementation: firstly
426 we can compare with published data, for example with Table 6 of "Self-Validating
427 Computations of Probabilities for Selected Central and Noncentral Univariate
428 Probability Functions", Morgan C. Wang and William J. Kennedy, Journal
429 of the American Statistical Association, Vol. 89, No. 427. (Sep., 1994),
430 pp. 878-887. Secondly, we have tables of test data, computed with this
431 implementation and using interval arithmetic - this data should be accurate
432 to at least 50 decimal digits - and is the used for our accuracy tests.
435 <a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.h5"></a>
436 <span class="phrase"><a name="math_toolkit.dist_ref.dists.nc_chi_squared_dist.implementation"></a></span><a class="link" href="nc_chi_squared_dist.html#math_toolkit.dist_ref.dists.nc_chi_squared_dist.implementation">Implementation</a>
439 The CDF and its complement are evaluated as follows:
442 First we determine which of the two values (the CDF or its complement)
443 is likely to be the smaller: for this we can use the relation due to Temme
444 (see "Asymptotic and Numerical Aspects of the Noncentral Chi-Square
445 Distribution", N. M. Temme, Computers Math. Applic. Vol 25, No. 5,
449 F(ν,λ;ν+λ) ≈ 0.5
452 and so compute the CDF when the random variable is less than ν+λ, and its
453 complement when the random variable is greater than ν+λ. If necessary the
454 computed result is then subtracted from 1 to give the desired result (the
455 CDF or its complement).
458 For small values of the non centrality parameter, the CDF is computed using
459 the method of Ding (see "Algorithm AS 275: Computing the Non-Central
460 #2 Distribution Function", Cherng G. Ding, Applied Statistics, Vol.
461 41, No. 2. (1992), pp. 478-482). This uses the following series representation:
463 <div class="blockquote"><blockquote class="blockquote"><p>
464 <span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref4.svg"></span>
466 </p></blockquote></div>
468 which requires just one call to <a class="link" href="../../sf_gamma/gamma_derivatives.html" title="Derivative of the Incomplete Gamma Function">gamma_p_derivative</a>
469 with the subsequent terms being computed by recursion as shown above.
472 For larger values of the non-centrality parameter, Ding's method can take
473 an unreasonable number of terms before convergence is achieved. Furthermore,
474 the largest term is not the first term, so in extreme cases the first term
475 may be zero, leading to a zero result, even though the true value may be
479 Therefore, when the non-centrality parameter is greater than 200, the method
480 due to Krishnamoorthy (see "Computing discrete mixtures of continuous
481 distributions: noncentral chisquare, noncentral t and the distribution
482 of the square of the sample multiple correlation coefficient", Denise
483 Benton and K. Krishnamoorthy, Computational Statistics & Data Analysis,
484 43, (2003), 249-267) is used.
487 This method uses the well known sum:
489 <div class="blockquote"><blockquote class="blockquote"><p>
490 <span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref5.svg"></span>
492 </p></blockquote></div>
494 Where <span class="emphasis"><em>P<sub>a</sub>(x)</em></span> is the incomplete gamma function.
497 The method starts at the λth term, which is where the Poisson weighting
498 function achieves its maximum value, although this is not necessarily the
499 largest overall term. Subsequent terms are calculated via the normal recurrence
500 relations for the incomplete gamma function, and iteration proceeds both
501 forwards and backwards until sufficient precision has been achieved. It
502 should be noted that recurrence in the forwards direction of P<sub>a</sub>(x) is numerically
503 unstable. However, since we always start <span class="emphasis"><em>after</em></span> the
504 largest term in the series, numeric instability is introduced more slowly
505 than the series converges.
508 Computation of the complement of the CDF uses an extension of Krishnamoorthy's
511 <div class="blockquote"><blockquote class="blockquote"><p>
512 <span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref6.svg"></span>
514 </p></blockquote></div>
516 we can again start at the λ'th term and proceed in both directions from
517 there until the required precision is achieved. This time it is backwards
518 recursion on the incomplete gamma function Q<sub>a</sub>(x) which is unstable. However,
519 as long as we start well <span class="emphasis"><em>before</em></span> the largest term,
520 this is not an issue in practice.
523 The PDF is computed directly using the relation:
525 <div class="blockquote"><blockquote class="blockquote"><p>
526 <span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref3.svg"></span>
528 </p></blockquote></div>
530 Where <span class="emphasis"><em>f(x; v)</em></span> is the PDF of the central <a class="link" href="chi_squared_dist.html" title="Chi Squared Distribution">Chi
531 Squared Distribution</a> and <span class="emphasis"><em>I<sub>v</sub>(x)</em></span> is a modified
532 Bessel function, see <a class="link" href="../../bessel/mbessel.html" title="Modified Bessel Functions of the First and Second Kinds">cyl_bessel_i</a>.
533 For small values of the non-centrality parameter the relation in terms
534 of <a class="link" href="../../bessel/mbessel.html" title="Modified Bessel Functions of the First and Second Kinds">cyl_bessel_i</a> is used.
535 However, this method fails for large values of the non-centrality parameter,
536 so in that case the infinite sum is evaluated using the method of Benton
537 and Krishnamoorthy, and the usual recurrence relations for successive terms.
540 The quantile functions are computed by numeric inversion of the CDF. An
541 improve starting quess is from Thomas Luu, <a href="http://discovery.ucl.ac.uk/1482128/%2c" target="_top">Fast
542 and accurate parallel computation of quantile functions for random number
543 generation, Doctorial Thesis, 2016</a>.
546 There is no <a href="http://en.wikipedia.org/wiki/Closed_form" target="_top">closed
547 form</a> for the mode of the noncentral chi-squared distribution: it
548 is computed numerically by finding the maximum of the PDF. Likewise, the
549 median is computed numerically via the quantile.
552 The remaining non-member functions use the following formulas:
554 <div class="blockquote"><blockquote class="blockquote"><p>
555 <span class="inlinemediaobject"><img src="../../../../equations/nc_chi_squ_ref7.svg"></span>
557 </p></blockquote></div>
559 Some analytic properties of noncentral distributions (particularly unimodality,
560 and monotonicity of their modes) are surveyed and summarized by:
563 Andrea van Aubel & Wolfgang Gawronski, Applied Mathematics and Computation,
567 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
568 <td align="left"></td>
569 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
570 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
571 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
572 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
573 Daryle Walker and Xiaogang Zhang<p>
574 Distributed under the Boost Software License, Version 1.0. (See accompanying
575 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>)
580 <div class="spirit-nav">
581 <a accesskey="p" href="nc_beta_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_f_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>