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.77.1">
7 <link rel=
"home" href=
"../../../index.html" title=
"Math Toolkit 2.5.1">
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 15. 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 Wolfram Mathematica and in
<a href=
"http://www.r-project.org/" target=
"_top">The R Project for Statistical Computing
</a>
78 (geoR) with default scale =
1/degrees of freedom.
83 <div class=
"itemizedlist"><ul class=
"itemizedlist" style=
"list-style-type: disc; ">
85 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>
88 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>
91 R inverse chi_squared distribution functions
<a href=
"http://hosho.ees.hokudai.ac.jp/~kubo/Rdoc/library/geoR/html/InvChisquare.html" target=
"_top">R
95 Inverse chi_squared distribution functions
<a href=
"http://mathworld.wolfram.com/InverseChi-SquaredDistribution.html" target=
"_top">Weisstein,
96 Eric W.
"Inverse Chi-Squared Distribution." From MathWorld--A
97 Wolfram Web Resource.
</a>
100 Inverse chi_squared distribution reference
<a href=
"http://reference.wolfram.com/mathematica/ref/InverseChiSquareDistribution.html" target=
"_top">Weisstein,
101 Eric W.
"Inverse Chi-Squared Distribution reference." From
102 Wolfram Mathematica.
</a>
106 The inverse_chi_squared distribution is used in
<a href=
"http://en.wikipedia.org/wiki/Bayesian_statistics" target=
"_top">Bayesian
107 statistics
</a>: the scaled inverse chi-square is conjugate prior for
108 the normal distribution with known mean, model parameter
σ² (variance).
111 See
<a href=
"http://en.wikipedia.org/wiki/Conjugate_prior" target=
"_top">conjugate
112 priors including a table of distributions and their priors.
</a>
115 See also
<a class=
"link" href=
"inverse_gamma_dist.html" title=
"Inverse Gamma Distribution">Inverse
116 Gamma Distribution
</a> and
<a class=
"link" href=
"chi_squared_dist.html" title=
"Chi Squared Distribution">Chi
117 Squared Distribution
</a>.
120 The inverse_chi_squared distribution is a special case of a inverse_gamma
121 distribution with
ν (degrees_of_freedom) shape (
α) and scale (
β) where
124    α=
ν /
2 and
β =
½.
126 <div class=
"note"><table border=
"0" summary=
"Note">
128 <td rowspan=
"2" align=
"center" valign=
"top" width=
"25"><img alt=
"[Note]" src=
"../../../../../../../doc/src/images/note.png"></td>
129 <th align=
"left">Note
</th>
131 <tr><td align=
"left" valign=
"top">
133 This distribution
<span class=
"bold"><strong>does
</strong></span> provide the typedef:
135 <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>
137 If you want a
<code class=
"computeroutput"><span class=
"keyword">double
</span></code> precision
138 inverse_chi_squared distribution you can use
140 <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>
142 or you can write
<code class=
"computeroutput"><span class=
"identifier">inverse_chi_squared
</span>
143 <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>
148 For degrees of freedom parameter
ν, the (
<span class=
"bold"><strong>unscaled
</strong></span>)
149 inverse chi_squared distribution is defined by the probability density
153    f(x;
ν) =
2<sup>-
ν/
2</sup> x
<sup>-
ν/
2-
1</sup> e
<sup>-
1/
2x
</sup> /
Γ(
ν/
2)
156 and Cumulative Density Function (CDF)
159    F(x;
ν) =
Γ(
ν/
2,
1/
2x) /
Γ(
ν/
2)
162 For degrees of freedom parameter
ν and scale parameter
ξ, the
<span class=
"bold"><strong>scaled
</strong></span>
163 inverse chi_squared distribution is defined by the probability density
167    f(x;
ν,
ξ) = (
ξν/
2)
<sup>ν/
2</sup> e
<sup>-
νξ/
2x
</sup> x
<sup>-
1-
ν/
2</sup> /
Γ(
ν/
2)
170 and Cumulative Density Function (CDF)
173    F(x;
ν,
ξ) =
Γ(
ν/
2,
νξ/
2x) /
Γ(
ν/
2)
176 The following graphs illustrate how the PDF and CDF of the inverse chi_squared
177 distribution varies for a few values of parameters
ν and
ξ:
180 <span class=
"inlinemediaobject"><img src=
"../../../../graphs/inverse_chi_squared_pdf.svg" align=
"middle"></span>
183 <span class=
"inlinemediaobject"><img src=
"../../../../graphs/inverse_chi_squared_cdf.svg" align=
"middle"></span>
186 <a name=
"math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h0"></a>
187 <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
190 <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>
191 <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>
194 Constructs an inverse chi_squared distribution with
ν degrees of freedom
195 <span class=
"emphasis"><em>df
</em></span>, and scale
<span class=
"emphasis"><em>scale
</em></span> with default
199 Requires that the degrees of freedom
ν parameter is greater than zero, otherwise
200 calls
<a class=
"link" href=
"../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error
</a>.
202 <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>
205 Returns the degrees_of_freedom
ν parameter of this distribution.
207 <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>
210 Returns the scale
ξ parameter of this distribution.
213 <a name=
"math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h1"></a>
214 <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
218 All the
<a class=
"link" href=
"../nmp.html" title=
"Non-Member Properties">usual non-member accessor
219 functions
</a> that are generic to all distributions are supported:
220 <a class=
"link" href=
"../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function
</a>,
221 <a class=
"link" href=
"../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function
</a>,
222 <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>,
223 <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>,
224 <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>,
225 <a class=
"link" href=
"../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation
</a>,
226 <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>,
227 <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>.
230 The domain of the random variate is [
0,+
∞].
232 <div class=
"note"><table border=
"0" summary=
"Note">
234 <td rowspan=
"2" align=
"center" valign=
"top" width=
"25"><img alt=
"[Note]" src=
"../../../../../../../doc/src/images/note.png"></td>
235 <th align=
"left">Note
</th>
237 <tr><td align=
"left" valign=
"top"><p>
238 Unlike some definitions, this implementation supports a random variate
239 equal to zero as a special case, returning zero for both pdf and cdf.
243 <a name=
"math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h2"></a>
244 <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>
247 The inverse gamma distribution is implemented in terms of the incomplete
248 gamma functions like the
<a class=
"link" href=
"inverse_gamma_dist.html" title=
"Inverse Gamma Distribution">Inverse
249 Gamma Distribution
</a> that use
<a class=
"link" href=
"../../sf_gamma/igamma.html" title=
"Incomplete Gamma Functions">gamma_p
</a>
250 and
<a class=
"link" href=
"../../sf_gamma/igamma.html" title=
"Incomplete Gamma Functions">gamma_q
</a> and their
251 inverses
<a class=
"link" href=
"../../sf_gamma/igamma_inv.html" title=
"Incomplete Gamma Function Inverses">gamma_p_inv
</a>
252 and
<a class=
"link" href=
"../../sf_gamma/igamma_inv.html" title=
"Incomplete Gamma Function Inverses">gamma_q_inv
</a>:
253 refer to the accuracy data for those functions for more information. But
254 in general, gamma (and thus inverse gamma) results are often accurate to
255 a few epsilon,
>14 decimal digits accuracy for
64-bit double. unless
256 iteration is involved, as for the estimation of degrees of freedom.
259 <a name=
"math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h3"></a>
260 <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>
263 In the following table
ν is the degrees of freedom parameter and
ξ is the scale
264 parameter of the distribution,
<span class=
"emphasis"><em>x
</em></span> is the random variate,
265 <span class=
"emphasis"><em>p
</em></span> is the probability and
<span class=
"emphasis"><em>q =
1-p
</em></span>
266 its complement. Parameters
α for shape and
β for scale are used for the inverse
267 gamma function:
α =
ν/
2 and
β =
ν *
ξ/
2.
269 <div class=
"informaltable"><table class=
"table">
295 Using the relation: pdf =
<a class=
"link" href=
"../../sf_gamma/gamma_derivatives.html" title=
"Derivative of the Incomplete Gamma Function">gamma_p_derivative
</a>(
α,
296 β/ x,
β) / x * x
308 Using the relation: p =
<a class=
"link" href=
"../../sf_gamma/igamma.html" title=
"Incomplete Gamma Functions">gamma_q
</a>(
α,
321 Using the relation: q =
<a class=
"link" href=
"../../sf_gamma/igamma.html" title=
"Incomplete Gamma Functions">gamma_p
</a>(
α,
334 Using the relation: x =
β  /
<a class=
"link" href=
"../../sf_gamma/igamma_inv.html" title=
"Incomplete Gamma Function Inverses">gamma_q_inv
</a>(
α,
342 quantile from the complement
347 Using the relation: x =
α  /
<a class=
"link" href=
"../../sf_gamma/igamma_inv.html" title=
"Incomplete Gamma Function Inverses">gamma_p_inv
</a>(
α,
360 ν *
ξ / (
ν +
2)
372 no closed form analytic equation is known, but is evaluated as
385 νξ / (
ν -
2) for
ν > 2, else a
<a class=
"link" href=
"../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error
</a>
397 2 ν² ξ² / ((
ν -
2)
² (
ν -
4)) for
ν >4, else a
<a class=
"link" href=
"../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error
</a>
409 4 √2 √(
ν-
4) /(
ν-
6) for
ν >6, else a
<a class=
"link" href=
"../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error
</a>
421 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>
433 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>
440 <a name=
"math_toolkit.dist_ref.dists.inverse_chi_squared_dist.h4"></a>
441 <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>
443 <div class=
"orderedlist"><ol class=
"orderedlist" type=
"1">
444 <li class=
"listitem">
445 Bayesian Data Analysis, Andrew Gelman, John B. Carlin, Hal S. Stern,
446 Donald B. Rubin, ISBN-
13:
978-
1584883883, Chapman
& Hall;
2 edition
449 <li class=
"listitem">
450 Bayesian Computation with R, Jim Albert, ISBN-
13:
978-
0387922973, Springer;
451 2nd ed. edition (
10 Jun
2009)
455 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
456 <td align=
"left"></td>
457 <td align=
"right"><div class=
"copyright-footer">Copyright
© 2006-
2010,
2012-
2014 Nikhar Agrawal,
458 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
459 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R
åde, Gautam Sewani,
460 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang
<p>
461 Distributed under the Boost Software License, Version
1.0. (See accompanying
462 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>)
467 <div class=
"spirit-nav">
468 <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>