3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Inverse 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="hypergeometric_dist.html" title="Hypergeometric Distribution">
10 <link rel="next" href="inverse_gamma_dist.html" title="Inverse Gamma 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="hypergeometric_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="inverse_gamma_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.inverse_chi_squared_dist"></a><a class="link" href="inverse_chi_squared_dist.html" title="Inverse Chi Squared Distribution">Inverse
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">inverse_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">inverse_chi_squared_distribution</span>
36 <span class="special">{</span>
37 <span class="keyword">public</span><span class="special">:</span>
38 <span class="keyword">typedef</span> <span class="identifier">RealType</span> <span class="identifier">value_type</span><span class="special">;</span>
39 <span class="keyword">typedef</span> <span class="identifier">Policy</span> <span class="identifier">policy_type</span><span class="special">;</span>
41 <span class="identifier">inverse_chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">df</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// Not explicitly scaled, default 1/df.</span>
42 <span class="identifier">inverse_chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">df</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span> <span class="special">=</span> <span class="number">1</span><span class="special">/</span><span class="identifier">df</span><span class="special">);</span> <span class="comment">// Scaled.</span>
44 <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> <span class="comment">// Default 1.</span>
45 <span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> <span class="comment">// Optional scale [xi] (variance), default 1/degrees_of_freedom.</span>
46 <span class="special">};</span>
48 <span class="special">}}</span> <span class="comment">// namespace boost // namespace math</span>
51 The inverse chi squared distribution is a continuous probability distribution
52 of the <span class="bold"><strong>reciprocal</strong></span> of a variable distributed
53 according to the chi squared distribution.
56 The sources below give confusingly different formulae using different symbols
57 for the distribution pdf, but they are all the same, or related by a change
58 of variable, or choice of scale.
61 Two constructors are available to implement both the scaled and (implicitly)
65 The main version has an explicit scale parameter which implements the
66 <a href="http://en.wikipedia.org/wiki/Scaled-inverse-chi-square_distribution" target="_top">scaled
67 inverse chi_squared distribution</a>.
70 A second version has an implicit scale = 1/degrees of freedom and gives
71 the 1st definition in the <a href="http://en.wikipedia.org/wiki/Inverse-chi-square_distribution" target="_top">Wikipedia
72 inverse chi_squared distribution</a>. The 2nd Wikipedia inverse chi_squared
73 distribution definition can be implemented by explicitly specifying a scale
77 Both definitions are also available in <a href="http://www.wolfram.com/products/mathematica/index.html" target="_top">Wolfram
78 Mathematica</a> and in <a href="http://www.r-project.org/" target="_top">The R
79 Project for Statistical Computing</a> (geoR) with default scale = 1/degrees
85 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
87 Inverse chi_squared distribution <a href="http://en.wikipedia.org/wiki/Inverse-chi-square_distribution" target="_top">http://en.wikipedia.org/wiki/Inverse-chi-square_distribution</a>
90 Scaled inverse chi_squared distribution<a href="http://en.wikipedia.org/wiki/Scaled-inverse-chi-square_distribution" target="_top">http://en.wikipedia.org/wiki/Scaled-inverse-chi-square_distribution</a>
93 R inverse chi_squared distribution functions <a href="http://hosho.ees.hokudai.ac.jp/~kubo/Rdoc/library/geoR/html/InvChisquare.html" target="_top">R
97 Inverse chi_squared distribution functions <a href="http://mathworld.wolfram.com/InverseChi-SquaredDistribution.html" target="_top">Weisstein,
98 Eric W. "Inverse Chi-Squared Distribution." From MathWorld--A
99 Wolfram Web Resource.</a>
101 <li class="listitem">
102 Inverse chi_squared distribution reference <a href="http://reference.wolfram.com/mathematica/ref/InverseChiSquareDistribution.html" target="_top">Weisstein,
103 Eric W. "Inverse Chi-Squared Distribution reference." From
104 Wolfram Mathematica.</a>
108 The inverse_chi_squared distribution is used in <a href="http://en.wikipedia.org/wiki/Bayesian_statistics" target="_top">Bayesian
109 statistics</a>: the scaled inverse chi-square is conjugate prior for
110 the normal distribution with known mean, model parameter σ² (variance).
113 See <a href="http://en.wikipedia.org/wiki/Conjugate_prior" target="_top">conjugate
114 priors including a table of distributions and their priors.</a>
117 See also <a class="link" href="inverse_gamma_dist.html" title="Inverse Gamma Distribution">Inverse
118 Gamma Distribution</a> and <a class="link" href="chi_squared_dist.html" title="Chi Squared Distribution">Chi
119 Squared Distribution</a>.
122 The inverse_chi_squared distribution is a special case of a inverse_gamma
123 distribution with ν (degrees_of_freedom) shape (α) and scale (β) where
125 <div class="blockquote"><blockquote class="blockquote"><p>
126 <span class="serif_italic">α= ν /2 and β = ½</span>
127 </p></blockquote></div>
128 <div class="note"><table border="0" summary="Note">
130 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
131 <th align="left">Note</th>
133 <tr><td align="left" valign="top">
135 This distribution <span class="bold"><strong>does</strong></span> provide the typedef:
137 <pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">inverse_chi_squared_distribution</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">inverse_chi_squared</span><span class="special">;</span></pre>
139 If you want a <code class="computeroutput"><span class="keyword">double</span></code> precision
140 inverse_chi_squared distribution you can use
142 <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">inverse_chi_squared_distribution</span><span class="special"><></span></pre>
144 or you can write <code class="computeroutput"><span class="identifier">inverse_chi_squared</span>
145 <span class="identifier">my_invchisqr</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">);</span></code>
150 For degrees of freedom parameter ν, the (<span class="bold"><strong>unscaled</strong></span>)
151 inverse chi_squared distribution is defined by the probability density
154 <div class="blockquote"><blockquote class="blockquote"><p>
155 <span class="serif_italic">f(x;ν) = 2<sup>-ν/2</sup> x<sup>-ν/2-1</sup> e<sup>-1/2x</sup> / Γ(ν/2)</span>
156 </p></blockquote></div>
158 and Cumulative Density Function (CDF)
160 <div class="blockquote"><blockquote class="blockquote"><p>
161 <span class="serif_italic">F(x;ν) = Γ(ν/2, 1/2x) / Γ(ν/2)</span>
162 </p></blockquote></div>
164 For degrees of freedom parameter ν and scale parameter ξ, the <span class="bold"><strong>scaled</strong></span>
165 inverse chi_squared distribution is defined by the probability density
168 <div class="blockquote"><blockquote class="blockquote"><p>
169 <span class="serif_italic">f(x;ν, ξ) = (ξν/2)<sup>ν/2</sup> e<sup>-νξ/2x</sup> x<sup>-1-ν/2</sup> / Γ(ν/2)</span>
170 </p></blockquote></div>
172 and Cumulative Density Function (CDF)
174 <div class="blockquote"><blockquote class="blockquote"><p>
175 <span class="serif_italic">F(x;ν, ξ) = Γ(ν/2, νξ/2x) / Γ(ν/2)</span>
176 </p></blockquote></div>
178 The following graphs illustrate how the PDF and CDF of the inverse chi_squared
179 distribution varies for a few values of parameters ν and ξ:
181 <div class="blockquote"><blockquote class="blockquote"><p>
182 <span class="inlinemediaobject"><img src="../../../../graphs/inverse_chi_squared_pdf.svg" align="middle"></span>
184 </p></blockquote></div>
185 <div class="blockquote"><blockquote class="blockquote"><p>
186 <span class="inlinemediaobject"><img src="../../../../graphs/inverse_chi_squared_cdf.svg" align="middle"></span>
188 </p></blockquote></div>
190 <a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h0"></a>
191 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.member_functions"></a></span><a class="link" href="inverse_chi_squared_dist.html#math_toolkit.dist_ref.dists.inverse_chi_squared_dist.member_functions">Member
194 <pre class="programlisting"><span class="identifier">inverse_chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">df</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// Implicitly scaled 1/df.</span>
195 <span class="identifier">inverse_chi_squared_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">df</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">);</span> <span class="comment">// Explicitly scaled.</span>
198 Constructs an inverse chi_squared distribution with ν degrees of freedom
199 <span class="emphasis"><em>df</em></span>, and scale <span class="emphasis"><em>scale</em></span> with default
203 Requires that the degrees of freedom ν parameter is greater than zero, otherwise
204 calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
206 <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>
209 Returns the degrees_of_freedom ν parameter of this distribution.
211 <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">scale</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
214 Returns the scale ξ parameter of this distribution.
217 <a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h1"></a>
218 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.non_member_accessors"></a></span><a class="link" href="inverse_chi_squared_dist.html#math_toolkit.dist_ref.dists.inverse_chi_squared_dist.non_member_accessors">Non-member
222 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
223 functions</a> that are generic to all distributions are supported:
224 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
225 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
226 <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>,
227 <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>,
228 <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>,
229 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
230 <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>,
231 <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>.
234 The domain of the random variate is [0,+∞].
236 <div class="note"><table border="0" summary="Note">
238 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
239 <th align="left">Note</th>
241 <tr><td align="left" valign="top"><p>
242 Unlike some definitions, this implementation supports a random variate
243 equal to zero as a special case, returning zero for both pdf and cdf.
247 <a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h2"></a>
248 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.accuracy"></a></span><a class="link" href="inverse_chi_squared_dist.html#math_toolkit.dist_ref.dists.inverse_chi_squared_dist.accuracy">Accuracy</a>
251 The inverse gamma distribution is implemented in terms of the incomplete
252 gamma functions like the <a class="link" href="inverse_gamma_dist.html" title="Inverse Gamma Distribution">Inverse
253 Gamma Distribution</a> that use <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>
254 and <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a> and their
255 inverses <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a>
256 and <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>:
257 refer to the accuracy data for those functions for more information. But
258 in general, gamma (and thus inverse gamma) results are often accurate to
259 a few epsilon, >14 decimal digits accuracy for 64-bit double. unless
260 iteration is involved, as for the estimation of degrees of freedom.
263 <a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h3"></a>
264 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.implementation"></a></span><a class="link" href="inverse_chi_squared_dist.html#math_toolkit.dist_ref.dists.inverse_chi_squared_dist.implementation">Implementation</a>
267 In the following table ν is the degrees of freedom parameter and ξ is the scale
268 parameter of the distribution, <span class="emphasis"><em>x</em></span> is the random variate,
269 <span class="emphasis"><em>p</em></span> is the probability and <span class="emphasis"><em>q = 1-p</em></span>
270 its complement. Parameters α for shape and β for scale are used for the inverse
271 gamma function: α = ν/2 and β = ν * ξ/2.
273 <div class="informaltable"><table class="table">
299 Using the relation: pdf = <a class="link" href="../../sf_gamma/gamma_derivatives.html" title="Derivative of the Incomplete Gamma Function">gamma_p_derivative</a>(α,
300 β/ x, β) / x * x
312 Using the relation: p = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_q</a>(α,
325 Using the relation: q = <a class="link" href="../../sf_gamma/igamma.html" title="Incomplete Gamma Functions">gamma_p</a>(α,
338 Using the relation: x = β/ <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_q_inv</a>(α,
346 quantile from the complement
351 Using the relation: x = α/ <a class="link" href="../../sf_gamma/igamma_inv.html" title="Incomplete Gamma Function Inverses">gamma_p_inv</a>(α,
364 ν * ξ / (ν + 2)
376 no closed form analytic equation is known, but is evaluated as
389 νξ / (ν - 2) for ν > 2, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
401 2 ν² ξ² / ((ν -2)² (ν -4)) for ν >4, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
413 4 √2 √(ν-4) /(ν-6) for ν >6, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
425 12 * (5ν - 22) / ((ν - 6) * (ν - 8)) for ν >8, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
437 3 + 12 * (5ν - 22) / ((ν - 6) * (ν-8)) for ν >8, else a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
444 <a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h4"></a>
445 <span class="phrase"><a name="math_toolkit.dist_ref.dists.inverse_chi_squared_dist.references"></a></span><a class="link" href="inverse_chi_squared_dist.html#math_toolkit.dist_ref.dists.inverse_chi_squared_dist.references">References</a>
447 <div class="orderedlist"><ol class="orderedlist" type="1">
448 <li class="listitem">
449 Bayesian Data Analysis, Andrew Gelman, John B. Carlin, Hal S. Stern,
450 Donald B. Rubin, ISBN-13: 978-1584883883, Chapman & Hall; 2 edition
453 <li class="listitem">
454 Bayesian Computation with R, Jim Albert, ISBN-13: 978-0387922973, Springer;
455 2nd ed. edition (10 Jun 2009)
459 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
460 <td align="left"></td>
461 <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
462 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
463 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
464 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
465 Daryle Walker and Xiaogang Zhang<p>
466 Distributed under the Boost Software License, Version 1.0. (See accompanying
467 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>)
472 <div class="spirit-nav">
473 <a accesskey="p" href="hypergeometric_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="inverse_gamma_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>