Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / math / doc / html / math_toolkit / dist_ref / dists / students_t_dist.html
1 <html>
2 <head>
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.11.0">
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">
11 </head>
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>
20 </tr></table>
21 <hr>
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>
24 </div>
25 <div class="section">
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
28         t Distribution</a>
29 </h4></div></div></div>
30 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</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">&gt;</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>
32
33 <span class="keyword">template</span> <span class="special">&lt;</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&#160;20.&#160;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&lt;&gt;</a> <span class="special">&gt;</span>
35 <span class="keyword">class</span> <span class="identifier">students_t_distribution</span><span class="special">;</span>
36
37 <span class="keyword">typedef</span> <span class="identifier">students_t_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">students_t</span><span class="special">;</span>
38
39 <span class="keyword">template</span> <span class="special">&lt;</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&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</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>
44
45    <span class="comment">// Constructor:</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">&amp;</span> <span class="identifier">v</span><span class="special">);</span>
47
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>
50
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>
59
60 <span class="special">}}</span> <span class="comment">// namespaces</span>
61 </pre>
62 <p>
63           Student's t-distribution is a statistical distribution published by William
64           Gosset in 1908. His employer, Guinness Breweries, required him to publish
65           under a pseudonym (possibly to hide that they were using statistics to
66           improve beer quality), so he chose "Student".
67         </p>
68 <p>
69           Given N independent measurements, let
70         </p>
71 <div class="blockquote"><blockquote class="blockquote"><p>
72             <span class="inlinemediaobject"><img src="../../../../equations/students_t_dist.svg"></span>
73
74           </p></blockquote></div>
75 <p>
76           where <span class="emphasis"><em>M</em></span> is the population mean, &#956; is the sample mean,
77           and <span class="emphasis"><em>s</em></span> is the sample variance.
78         </p>
79 <p>
80           <a href="https://en.wikipedia.org/wiki/Student%27s_t-distribution" target="_top">Student's
81           t-distribution</a> is defined as the distribution of the random variable
82           t which is - very loosely - the "best" that we can do while not
83           knowing the true standard deviation of the sample. It has the PDF:
84         </p>
85 <div class="blockquote"><blockquote class="blockquote"><p>
86             <span class="inlinemediaobject"><img src="../../../../equations/students_t_ref1.svg"></span>
87
88           </p></blockquote></div>
89 <p>
90           The Student's t-distribution takes a single parameter: the number of degrees
91           of freedom of the sample. When the degrees of freedom is <span class="emphasis"><em>one</em></span>
92           then this distribution is the same as the Cauchy-distribution. As the number
93           of degrees of freedom tends towards infinity, then this distribution approaches
94           the normal-distribution. The following graph illustrates how the PDF varies
95           with the degrees of freedom &#957;:
96         </p>
97 <div class="blockquote"><blockquote class="blockquote"><p>
98             <span class="inlinemediaobject"><img src="../../../../graphs/students_t_pdf.svg" align="middle"></span>
99
100           </p></blockquote></div>
101 <h5>
102 <a name="math_toolkit.dist_ref.dists.students_t_dist.h0"></a>
103           <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
104           Functions</a>
105         </h5>
106 <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">&amp;</span> <span class="identifier">v</span><span class="special">);</span>
107 </pre>
108 <p>
109           Constructs a Student's t-distribution with <span class="emphasis"><em>v</em></span> degrees
110           of freedom.
111         </p>
112 <p>
113           Requires <span class="emphasis"><em>v</em></span> &gt; 0, including infinity (if RealType
114           permits), otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
115           Note that non-integral degrees of freedom are supported, and are meaningful
116           under certain circumstances.
117         </p>
118 <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>
119 </pre>
120 <p>
121           returns the number of degrees of freedom of this distribution.
122         </p>
123 <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>
124    <span class="identifier">RealType</span> <span class="identifier">difference_from_mean</span><span class="special">,</span>
125    <span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span>
126    <span class="identifier">RealType</span> <span class="identifier">beta</span><span class="special">,</span>
127    <span class="identifier">RealType</span> <span class="identifier">sd</span><span class="special">,</span>
128    <span class="identifier">RealType</span> <span class="identifier">hint</span> <span class="special">=</span> <span class="number">100</span><span class="special">);</span>
129 </pre>
130 <p>
131           returns the number of degrees of freedom required to observe a significant
132           result in the Student's t test when the mean differs from the "true"
133           mean by <span class="emphasis"><em>difference_from_mean</em></span>.
134         </p>
135 <div class="variablelist">
136 <p class="title"><b></b></p>
137 <dl class="variablelist">
138 <dt><span class="term">difference_from_mean</span></dt>
139 <dd><p>
140                 The difference between the true mean and the sample mean that we
141                 wish to show is significant.
142               </p></dd>
143 <dt><span class="term">alpha</span></dt>
144 <dd><p>
145                 The maximum acceptable probability of rejecting the null hypothesis
146                 when it is in fact true.
147               </p></dd>
148 <dt><span class="term">beta</span></dt>
149 <dd><p>
150                 The maximum acceptable probability of failing to reject the null
151                 hypothesis when it is in fact false.
152               </p></dd>
153 <dt><span class="term">sd</span></dt>
154 <dd><p>
155                 The sample standard deviation.
156               </p></dd>
157 <dt><span class="term">hint</span></dt>
158 <dd><p>
159                 A hint for the location to start looking for the result, a good choice
160                 for this would be the sample size of a previous borderline Student's
161                 t test.
162               </p></dd>
163 </dl>
164 </div>
165 <div class="note"><table border="0" summary="Note">
166 <tr>
167 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
168 <th align="left">Note</th>
169 </tr>
170 <tr><td align="left" valign="top"><p>
171             Remember that for a two-sided test, you must divide alpha by two before
172             calling this function.
173           </p></td></tr>
174 </table></div>
175 <p>
176           For more information on this function see the <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc222.htm" target="_top">NIST
177           Engineering Statistics Handbook</a>.
178         </p>
179 <h5>
180 <a name="math_toolkit.dist_ref.dists.students_t_dist.h1"></a>
181           <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
182           Accessors</a>
183         </h5>
184 <p>
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>.
195         </p>
196 <p>
197           The domain of the random variable is [-&#8734;, +&#8734;].
198         </p>
199 <h5>
200 <a name="math_toolkit.dist_ref.dists.students_t_dist.h2"></a>
201           <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>
202         </h5>
203 <p>
204           Various <a class="link" href="../../stat_tut/weg/st_eg.html" title="Student's t Distribution Examples">worked examples</a>
205           are available illustrating the use of the Student's t distribution.
206         </p>
207 <h5>
208 <a name="math_toolkit.dist_ref.dists.students_t_dist.h3"></a>
209           <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>
210         </h5>
211 <p>
212           The normal distribution is implemented in terms of the <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">incomplete
213           beta function</a> and <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">its
214           inverses</a>, refer to accuracy data on those functions for more information.
215         </p>
216 <h5>
217 <a name="math_toolkit.dist_ref.dists.students_t_dist.h4"></a>
218           <span class="phrase"><a name="math_toolkit.dist_ref.dists.students_t_dist.implementation0"></a></span><a class="link" href="students_t_dist.html#math_toolkit.dist_ref.dists.students_t_dist.implementation0">Implementation</a>
219         </h5>
220 <p>
221           In the following table <span class="emphasis"><em>v</em></span> is the degrees of freedom
222           of the distribution, <span class="emphasis"><em>t</em></span> is the random variate, <span class="emphasis"><em>p</em></span>
223           is the probability and <span class="emphasis"><em>q = 1-p</em></span>.
224         </p>
225 <div class="informaltable"><table class="table">
226 <colgroup>
227 <col>
228 <col>
229 </colgroup>
230 <thead><tr>
231 <th>
232                   <p>
233                     Function
234                   </p>
235                 </th>
236 <th>
237                   <p>
238                     Implementation Notes
239                   </p>
240                 </th>
241 </tr></thead>
242 <tbody>
243 <tr>
244 <td>
245                   <p>
246                     pdf
247                   </p>
248                 </td>
249 <td>
250                   <p>
251                     Using the relation: <span class="serif_italic">pdf = (v / (v
252                     + t<sup>2</sup>))<sup>(1+v)/2 </sup> / (sqrt(v) * <a class="link" href="../../sf_beta/beta_function.html" title="Beta">beta</a>(v/2,
253                     0.5))</span>
254                   </p>
255                 </td>
256 </tr>
257 <tr>
258 <td>
259                   <p>
260                     cdf
261                   </p>
262                 </td>
263 <td>
264                   <p>
265                     Using the relations:
266                   </p>
267                   <p>
268                     <span class="serif_italic">p = 1 - z <span class="emphasis"><em>iff t &gt; 0</em></span></span>
269                   </p>
270                   <p>
271                     <span class="serif_italic">p = z <span class="emphasis"><em>otherwise</em></span></span>
272                   </p>
273                   <p>
274                     where z is given by:
275                   </p>
276                   <p>
277                     <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a>(v
278                     / 2, 0.5, v / (v + t<sup>2</sup>)) / 2 <span class="emphasis"><em>iff v &lt; 2t<sup>2</sup></em></span>
279                   </p>
280                   <p>
281                     <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>(0.5,
282                     v / 2, t<sup>2 </sup> / (v + t<sup>2</sup>) / 2 <span class="emphasis"><em>otherwise</em></span>
283                   </p>
284                 </td>
285 </tr>
286 <tr>
287 <td>
288                   <p>
289                     cdf complement
290                   </p>
291                 </td>
292 <td>
293                   <p>
294                     Using the relation: q = cdf(-t)
295                   </p>
296                 </td>
297 </tr>
298 <tr>
299 <td>
300                   <p>
301                     quantile
302                   </p>
303                 </td>
304 <td>
305                   <p>
306                     Using the relation: <span class="serif_italic">t = sign(p -
307                     0.5) * sqrt(v * y / x)</span>
308                   </p>
309                   <p>
310                     where:
311                   </p>
312                   <p>
313                     <span class="serif_italic">x = <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>(v
314                     / 2, 0.5, 2 * min(p, q)) </span>
315                   </p>
316                   <p>
317                     <span class="serif_italic">y = 1 - x</span>
318                   </p>
319                   <p>
320                     The quantities <span class="emphasis"><em>x</em></span> and <span class="emphasis"><em>y</em></span>
321                     are both returned by <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>
322                     without the subtraction implied above.
323                   </p>
324                 </td>
325 </tr>
326 <tr>
327 <td>
328                   <p>
329                     quantile from the complement
330                   </p>
331                 </td>
332 <td>
333                   <p>
334                     Using the relation: t = -quantile(q)
335                   </p>
336                 </td>
337 </tr>
338 <tr>
339 <td>
340                   <p>
341                     mode
342                   </p>
343                 </td>
344 <td>
345                   <p>
346                     0
347                   </p>
348                 </td>
349 </tr>
350 <tr>
351 <td>
352                   <p>
353                     mean
354                   </p>
355                 </td>
356 <td>
357                   <p>
358                     0
359                   </p>
360                 </td>
361 </tr>
362 <tr>
363 <td>
364                   <p>
365                     variance
366                   </p>
367                 </td>
368 <td>
369                   <p>
370                     if (v &gt; 2) v / (v - 2) else NaN
371                   </p>
372                 </td>
373 </tr>
374 <tr>
375 <td>
376                   <p>
377                     skewness
378                   </p>
379                 </td>
380 <td>
381                   <p>
382                     if (v &gt; 3) 0 else NaN
383                   </p>
384                 </td>
385 </tr>
386 <tr>
387 <td>
388                   <p>
389                     kurtosis
390                   </p>
391                 </td>
392 <td>
393                   <p>
394                     if (v &gt; 4) 3 * (v - 2) / (v - 4) else NaN
395                   </p>
396                 </td>
397 </tr>
398 <tr>
399 <td>
400                   <p>
401                     kurtosis excess
402                   </p>
403                 </td>
404 <td>
405                   <p>
406                     if (v &gt; 4) 6 / (df - 4) else NaN
407                   </p>
408                 </td>
409 </tr>
410 </tbody>
411 </table></div>
412 <p>
413           If the moment index <span class="emphasis"><em>k</em></span> is less than <span class="emphasis"><em>v</em></span>,
414           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>
415           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">&lt;&gt;::</span><span class="identifier">quiet_NaN</span><span class="special">();</span></code>
416         </p>
417 <h6>
418 <a name="math_toolkit.dist_ref.dists.students_t_dist.h5"></a>
419           <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>
420         </h6>
421 <p>
422           (By popular demand, we now support infinite argument and random deviate.
423           But we have not implemented the return of infinity as suggested by <a href="http://en.wikipedia.org/wiki/Student%27s_t-distribution" target="_top">Wikipedia
424           Student's t</a>, instead throwing a domain error or return NaN. See
425           also <a href="https://svn.boost.org/trac/boost/ticket/7177" target="_top">https://svn.boost.org/trac/boost/ticket/7177</a>.)
426         </p>
427 </div>
428 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
429 <td align="left"></td>
430 <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2019 Nikhar
431       Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
432       Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
433       R&#229;de, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
434       Daryle Walker and Xiaogang Zhang<p>
435         Distributed under the Boost Software License, Version 1.0. (See accompanying
436         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>)
437       </p>
438 </div></td>
439 </tr></table>
440 <hr>
441 <div class="spirit-nav">
442 <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>
443 </div>
444 </body>
445 </html>