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">
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 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">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 20. 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">// 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">&</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 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".
69 Given N independent measurements, let
71 <div class="blockquote"><blockquote class="blockquote"><p>
72 <span class="inlinemediaobject"><img src="../../../../equations/students_t_dist.svg"></span>
74 </p></blockquote></div>
76 where <span class="emphasis"><em>M</em></span> is the population mean, μ is the sample mean,
77 and <span class="emphasis"><em>s</em></span> is the sample variance.
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:
85 <div class="blockquote"><blockquote class="blockquote"><p>
86 <span class="inlinemediaobject"><img src="../../../../equations/students_t_ref1.svg"></span>
88 </p></blockquote></div>
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 ν:
97 <div class="blockquote"><blockquote class="blockquote"><p>
98 <span class="inlinemediaobject"><img src="../../../../graphs/students_t_pdf.svg" align="middle"></span>
100 </p></blockquote></div>
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
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">&</span> <span class="identifier">v</span><span class="special">);</span>
109 Constructs a Student's t-distribution with <span class="emphasis"><em>v</em></span> degrees
113 Requires <span class="emphasis"><em>v</em></span> > 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.
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>
121 returns the number of degrees of freedom of this distribution.
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>
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>.
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>
140 The difference between the true mean and the sample mean that we
141 wish to show is significant.
143 <dt><span class="term">alpha</span></dt>
145 The maximum acceptable probability of rejecting the null hypothesis
146 when it is in fact true.
148 <dt><span class="term">beta</span></dt>
150 The maximum acceptable probability of failing to reject the null
151 hypothesis when it is in fact false.
153 <dt><span class="term">sd</span></dt>
155 The sample standard deviation.
157 <dt><span class="term">hint</span></dt>
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
165 <div class="note"><table border="0" summary="Note">
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>
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.
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>.
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
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 [-∞, +∞].
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>
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.
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>
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.
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>
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>.
225 <div class="informaltable"><table class="table">
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,
268 <span class="serif_italic">p = 1 - z <span class="emphasis"><em>iff t > 0</em></span></span>
271 <span class="serif_italic">p = z <span class="emphasis"><em>otherwise</em></span></span>
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 < 2t<sup>2</sup></em></span>
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>
294 Using the relation: q = cdf(-t)
306 Using the relation: <span class="serif_italic">t = sign(p -
307 0.5) * sqrt(v * y / x)</span>
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>
317 <span class="serif_italic">y = 1 - x</span>
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.
329 quantile from the complement
334 Using the relation: t = -quantile(q)
370 if (v > 2) v / (v - 2) else NaN
382 if (v > 3) 0 else NaN
394 if (v > 4) 3 * (v - 2) / (v - 4) else NaN
406 if (v > 4) 6 / (df - 4) else NaN
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"><>::</span><span class="identifier">quiet_NaN</span><span class="special">();</span></code>
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>
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>.)
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 © 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å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>)
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>