3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Students 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.5.2">
8 <link rel="up" href="../dists.html" title="Distributions">
9 <link rel="prev" href="skew_normal_dist.html" title="Skew Normal Distribution">
10 <link rel="next" href="triangular_dist.html" title="Triangular 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="skew_normal_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="triangular_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.students_t_dist"></a><a class="link" href="students_t_dist.html" title="Students t Distribution">Students
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">students_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 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">students_t_distribution</span><span class="special">;</span>
37 <span class="keyword">typedef</span> <span class="identifier">students_t_distribution</span><span class="special"><></span> <span class="identifier">students_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 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span>
40 <span class="keyword">class</span> <span class="identifier">students_t_distribution</span>
41 <span class="special">{</span>
42 <span class="keyword">typedef</span> <span class="identifier">RealType</span> <span class="identifier">value_type</span><span class="special">;</span>
43 <span class="keyword">typedef</span> <span class="identifier">Policy</span> <span class="identifier">policy_type</span><span class="special">;</span>
45 <span class="comment">// Construct:</span>
46 <span class="identifier">students_t_distribution</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&</span> <span class="identifier">v</span><span class="special">);</span>
48 <span class="comment">// Accessor:</span>
49 <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>
51 <span class="comment">// degrees of freedom estimation:</span>
52 <span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_degrees_of_freedom</span><span class="special">(</span>
53 <span class="identifier">RealType</span> <span class="identifier">difference_from_mean</span><span class="special">,</span>
54 <span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span>
55 <span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">,</span>
56 <span class="identifier">RealType</span> <span class="identifier">sd</span><span class="special">,</span>
57 <span class="identifier">RealType</span> <span class="identifier">hint</span> <span class="special">=</span> <span class="number">100</span><span class="special">);</span>
58 <span class="special">};</span>
60 <span class="special">}}</span> <span class="comment">// namespaces</span>
63 A statistical distribution published by William Gosset in 1908. His employer,
64 Guinness Breweries, required him to publish under a pseudonym (possibly
65 to hide that they were using statistics), so he chose "Student".
66 Given N independent measurements, let
69 <span class="inlinemediaobject"><img src="../../../../equations/students_t_dist.svg"></span>
72 where <span class="emphasis"><em>M</em></span> is the population mean,<span class="emphasis"><em>μ</em></span>
73 is the sample mean, and <span class="emphasis"><em>s</em></span> is the sample variance.
76 Student's t-distribution is defined as the distribution of the random variable
77 t which is - very loosely - the "best" that we can do not knowing
78 the true standard deviation of the sample. It has the PDF:
81 <span class="inlinemediaobject"><img src="../../../../equations/students_t_ref1.svg"></span>
84 The Student's t-distribution takes a single parameter: the number of degrees
85 of freedom of the sample. When the degrees of freedom is <span class="emphasis"><em>one</em></span>
86 then this distribution is the same as the Cauchy-distribution. As the number
87 of degrees of freedom tends towards infinity, then this distribution approaches
88 the normal-distribution. The following graph illustrates how the PDF varies
89 with the degrees of freedom ν:
92 <span class="inlinemediaobject"><img src="../../../../graphs/students_t_pdf.svg" align="middle"></span>
95 <a name="math_toolkit.dist_ref.dists.students_t_dist.h0"></a>
96 <span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.member_functions"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_dist.member_functions">Member
99 <pre class="programlisting"><span class="identifier">students_t_distribution</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&</span> <span class="identifier">v</span><span class="special">);</span>
102 Constructs a Student's t-distribution with <span class="emphasis"><em>v</em></span> degrees
106 Requires <span class="emphasis"><em>v</em></span> > 0, otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
107 Note that non-integral degrees of freedom are supported, and are meaningful
108 under certain circumstances.
110 <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>
113 Returns the number of degrees of freedom of this distribution.
115 <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>
116 <span class="identifier">RealType</span> <span class="identifier">difference_from_mean</span><span class="special">,</span>
117 <span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span>
118 <span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">,</span>
119 <span class="identifier">RealType</span> <span class="identifier">sd</span><span class="special">,</span>
120 <span class="identifier">RealType</span> <span class="identifier">hint</span> <span class="special">=</span> <span class="number">100</span><span class="special">);</span>
123 Returns the number of degrees of freedom required to observe a significant
124 result in the Student's t test when the mean differs from the "true"
125 mean by <span class="emphasis"><em>difference_from_mean</em></span>.
127 <div class="variablelist">
128 <p class="title"><b></b></p>
129 <dl class="variablelist">
130 <dt><span class="term">difference_from_mean</span></dt>
132 The difference between the true mean and the sample mean that we
133 wish to show is significant.
135 <dt><span class="term">alpha</span></dt>
137 The maximum acceptable probability of rejecting the null hypothesis
138 when it is in fact true.
140 <dt><span class="term">beta</span></dt>
142 The maximum acceptable probability of failing to reject the null
143 hypothesis when it is in fact false.
145 <dt><span class="term">sd</span></dt>
147 The sample standard deviation.
149 <dt><span class="term">hint</span></dt>
151 A hint for the location to start looking for the result, a good choice
152 for this would be the sample size of a previous borderline Student's
157 <div class="note"><table border="0" summary="Note">
159 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
160 <th align="left">Note</th>
162 <tr><td align="left" valign="top"><p>
163 Remember that for a two-sided test, you must divide alpha by two before
164 calling this function.
168 For more information on this function see the <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc222.htm" target="_top">NIST
169 Engineering Statistics Handbook</a>.
172 <a name="math_toolkit.dist_ref.dists.students_t_dist.h1"></a>
173 <span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.non_member_accessors"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_dist.non_member_accessors">Non-member
177 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
178 functions</a> that are generic to all distributions are supported:
179 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
180 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
181 <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>,
182 <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>,
183 <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>,
184 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
185 <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>,
186 <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>.
189 The domain of the random variable is [-∞, +∞].
192 <a name="math_toolkit.dist_ref.dists.students_t_dist.h2"></a>
193 <span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.examples"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_dist.examples">Examples</a>
196 Various <a class="link" href="../../stat_tut/weg/st_eg.html" title="Student's t Distribution Examples">worked examples</a>
197 are available illustrating the use of the Student's t distribution.
200 <a name="math_toolkit.dist_ref.dists.students_t_dist.h3"></a>
201 <span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.accuracy"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_dist.accuracy">Accuracy</a>
204 The normal distribution is implemented in terms of the <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">incomplete
205 beta function</a> and <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">its
206 inverses</a>, refer to accuracy data on those functions for more information.
209 <a name="math_toolkit.dist_ref.dists.students_t_dist.h4"></a>
210 <span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.implementation"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_dist.implementation">Implementation</a>
213 In the following table <span class="emphasis"><em>v</em></span> is the degrees of freedom
214 of the distribution, <span class="emphasis"><em>t</em></span> is the random variate, <span class="emphasis"><em>p</em></span>
215 is the probability and <span class="emphasis"><em>q = 1-p</em></span>.
217 <div class="informaltable"><table class="table">
243 Using the relation: pdf = (v / (v + t<sup>2</sup>))<sup>(1+v)/2 </sup> / (sqrt(v) *
244 <a class="link" href="../../sf_beta/beta_function.html" title="Beta">beta</a>(v/2,
260 p = 1 - z <span class="emphasis"><em>iff t > 0</em></span>
263 p = z <span class="emphasis"><em>otherwise</em></span>
269 <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a>(v
270 / 2, 0.5, v / (v + t<sup>2</sup>)) / 2 <span class="emphasis"><em>iff v < 2t<sup>2</sup></em></span>
273 <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>(0.5,
274 v / 2, t<sup>2 </sup> / (v + t<sup>2</sup>) / 2 <span class="emphasis"><em>otherwise</em></span>
286 Using the relation: q = cdf(-t)
298 Using the relation: t = sign(p - 0.5) * sqrt(v * y / x)
304 x = <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>(v
305 / 2, 0.5, 2 * min(p, q))
311 The quantities <span class="emphasis"><em>x</em></span> and <span class="emphasis"><em>y</em></span>
312 are both returned by <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>
313 without the subtraction implied above.
320 quantile from the complement
325 Using the relation: t = -quantile(q)
361 if (v > 2) v / (v - 2) else NaN
373 if (v > 3) 0 else NaN
385 if (v > 4) 3 * (v - 2) / (v - 4) else NaN
397 if (v > 4) 6 / (df - 4) else NaN
404 If the moment index <span class="emphasis"><em>k</em></span> is less than <span class="emphasis"><em>v</em></span>,
405 then the moment is undefined. Evaluating the moment will throw a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>
406 unless ignored by a policy, when it will return <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><>::</span><span class="identifier">quiet_NaN</span><span class="special">();</span></code>
409 (For simplicity, we have not implemented the return of infinity in some
410 cases as suggested by <a href="http://en.wikipedia.org/wiki/Student%27s_t-distribution" target="_top">Wikipedia
411 Student's t</a>. See also <a href="https://svn.boost.org/trac/boost/ticket/7177" target="_top">https://svn.boost.org/trac/boost/ticket/7177</a>.)
414 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
415 <td align="left"></td>
416 <td align="right"><div class="copyright-footer">Copyright © 2006-2010, 2012-2014 Nikhar Agrawal,
417 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
418 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan Råde, Gautam Sewani,
419 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p>
420 Distributed under the Boost Software License, Version 1.0. (See accompanying
421 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>)
426 <div class="spirit-nav">
427 <a accesskey="p" href="skew_normal_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="triangular_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>