1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>F 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.12.0"> 8<link rel="up" href="../dists.html" title="Distributions"> 9<link rel="prev" href="extreme_dist.html" title="Extreme Value Distribution"> 10<link rel="next" href="gamma_dist.html" title="Gamma (and Erlang) 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="extreme_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="gamma_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.f_dist"></a><a class="link" href="f_dist.html" title="F Distribution">F Distribution</a> 28</h4></div></div></div> 29<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">fisher_f</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></pre> 30<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> 31 32<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> 33 <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 21. 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> 34<span class="keyword">class</span> <span class="identifier">fisher_f_distribution</span><span class="special">;</span> 35 36<span class="keyword">typedef</span> <span class="identifier">fisher_f_distribution</span><span class="special"><></span> <span class="identifier">fisher_f</span><span class="special">;</span> 37 38<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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> 39<span class="keyword">class</span> <span class="identifier">fisher_f_distribution</span> 40<span class="special">{</span> 41<span class="keyword">public</span><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 44 <span class="comment">// Construct:</span> 45 <span class="identifier">fisher_f_distribution</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&</span> <span class="identifier">i</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&</span> <span class="identifier">j</span><span class="special">);</span> 46 47 <span class="comment">// Accessors:</span> 48 <span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom1</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> 49 <span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom2</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> 50<span class="special">};</span> 51 52<span class="special">}}</span> <span class="comment">//namespaces</span> 53</pre> 54<p> 55 The F distribution is a continuous distribution that arises when testing 56 whether two samples have the same variance. If χ<sup>2</sup><sub>m</sub> and χ<sup>2</sup><sub>n</sub> are independent 57 variates each distributed as Chi-Squared with <span class="emphasis"><em>m</em></span> and 58 <span class="emphasis"><em>n</em></span> degrees of freedom, then the test statistic: 59 </p> 60<div class="blockquote"><blockquote class="blockquote"><p> 61 <span class="serif_italic">F<sub>n,m</sub> = (χ<sup>2</sup><sub>n</sub> / n) / (χ<sup>2</sup><sub>m</sub> / m)</span> 62 </p></blockquote></div> 63<p> 64 Is distributed over the range [0, ∞] with an F distribution, and has the 65 PDF: 66 </p> 67<div class="blockquote"><blockquote class="blockquote"><p> 68 <span class="inlinemediaobject"><img src="../../../../equations/fisher_pdf.svg"></span> 69 70 </p></blockquote></div> 71<p> 72 The following graph illustrates how the PDF varies depending on the two 73 degrees of freedom parameters. 74 </p> 75<div class="blockquote"><blockquote class="blockquote"><p> 76 <span class="inlinemediaobject"><img src="../../../../graphs/fisher_f_pdf.svg" align="middle"></span> 77 78 </p></blockquote></div> 79<h5> 80<a name="math_toolkit.dist_ref.dists.f_dist.h0"></a> 81 <span class="phrase"><a name="math_toolkit.dist_ref.dists.f_dist.member_functions"></a></span><a class="link" href="f_dist.html#math_toolkit.dist_ref.dists.f_dist.member_functions">Member Functions</a> 82 </h5> 83<pre class="programlisting"><span class="identifier">fisher_f_distribution</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&</span> <span class="identifier">df1</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">RealType</span><span class="special">&</span> <span class="identifier">df2</span><span class="special">);</span> 84</pre> 85<p> 86 Constructs an F-distribution with numerator degrees of freedom <span class="emphasis"><em>df1</em></span> 87 and denominator degrees of freedom <span class="emphasis"><em>df2</em></span>. 88 </p> 89<p> 90 Requires that <span class="emphasis"><em>df1</em></span> and <span class="emphasis"><em>df2</em></span> are 91 both greater than zero, otherwise <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a> 92 is called. 93 </p> 94<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom1</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> 95</pre> 96<p> 97 Returns the numerator degrees of freedom parameter of the distribution. 98 </p> 99<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">degrees_of_freedom2</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span> 100</pre> 101<p> 102 Returns the denominator degrees of freedom parameter of the distribution. 103 </p> 104<h5> 105<a name="math_toolkit.dist_ref.dists.f_dist.h1"></a> 106 <span class="phrase"><a name="math_toolkit.dist_ref.dists.f_dist.non_member_accessors"></a></span><a class="link" href="f_dist.html#math_toolkit.dist_ref.dists.f_dist.non_member_accessors">Non-member 107 Accessors</a> 108 </h5> 109<p> 110 All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor 111 functions</a> that are generic to all distributions are supported: 112 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>, 113 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>, 114 <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>, 115 <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>, 116 <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>, 117 <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>, 118 <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>, 119 <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>. 120 </p> 121<p> 122 The domain of the random variable is [0, +∞]. 123 </p> 124<h5> 125<a name="math_toolkit.dist_ref.dists.f_dist.h2"></a> 126 <span class="phrase"><a name="math_toolkit.dist_ref.dists.f_dist.examples"></a></span><a class="link" href="f_dist.html#math_toolkit.dist_ref.dists.f_dist.examples">Examples</a> 127 </h5> 128<p> 129 Various <a class="link" href="../../stat_tut/weg/f_eg.html" title="F Distribution Examples">worked examples</a> 130 are available illustrating the use of the F Distribution. 131 </p> 132<h5> 133<a name="math_toolkit.dist_ref.dists.f_dist.h3"></a> 134 <span class="phrase"><a name="math_toolkit.dist_ref.dists.f_dist.accuracy"></a></span><a class="link" href="f_dist.html#math_toolkit.dist_ref.dists.f_dist.accuracy">Accuracy</a> 135 </h5> 136<p> 137 The normal distribution is implemented in terms of the <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">incomplete 138 beta function</a> and its <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">inverses</a>, 139 refer to those functions for accuracy data. 140 </p> 141<h5> 142<a name="math_toolkit.dist_ref.dists.f_dist.h4"></a> 143 <span class="phrase"><a name="math_toolkit.dist_ref.dists.f_dist.implementation"></a></span><a class="link" href="f_dist.html#math_toolkit.dist_ref.dists.f_dist.implementation">Implementation</a> 144 </h5> 145<p> 146 In the following table <span class="emphasis"><em>v1</em></span> and <span class="emphasis"><em>v2</em></span> 147 are the first and second degrees of freedom parameters of the distribution, 148 <span class="emphasis"><em>x</em></span> is the random variate, <span class="emphasis"><em>p</em></span> is 149 the probability, and <span class="emphasis"><em>q = 1-p</em></span>. 150 </p> 151<div class="informaltable"><table class="table"> 152<colgroup> 153<col> 154<col> 155</colgroup> 156<thead><tr> 157<th> 158 <p> 159 Function 160 </p> 161 </th> 162<th> 163 <p> 164 Implementation Notes 165 </p> 166 </th> 167</tr></thead> 168<tbody> 169<tr> 170<td> 171 <p> 172 pdf 173 </p> 174 </td> 175<td> 176 <p> 177 The usual form of the PDF is given by: 178 </p> 179 <div class="blockquote"><blockquote class="blockquote"><p> 180 <span class="inlinemediaobject"><img src="../../../../equations/fisher_pdf.svg"></span> 181 182 </p></blockquote></div> 183 <p> 184 However, that form is hard to evaluate directly without incurring 185 problems with either accuracy or numeric overflow. 186 </p> 187 <p> 188 Direct differentiation of the CDF expressed in terms of the incomplete 189 beta function 190 </p> 191 <p> 192 led to the following two formulas: 193 </p> 194 <div class="blockquote"><blockquote class="blockquote"><p> 195 <span class="serif_italic">f<sub>v1,v2</sub>(x) = y * <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a>(v2 196 / 2, v1 / 2, v2 / (v2 + v1 * x))</span> 197 </p></blockquote></div> 198 <p> 199 with y = (v2 * v1) / ((v2 + v1 * x) * (v2 + v1 * x)) 200 </p> 201 <p> 202 and 203 </p> 204 <div class="blockquote"><blockquote class="blockquote"><p> 205 <span class="serif_italic">f<sub>v1,v2</sub>(x) = y * <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a>(v1 206 / 2, v2 / 2, v1 * x / (v2 + v1 * x))</span> 207 </p></blockquote></div> 208 <p> 209 with y = (z * v1 - x * v1 * v1) / z<sup>2</sup> 210 </p> 211 <p> 212 and z = v2 + v1 * x 213 </p> 214 <p> 215 The first of these is used for v1 * x > v2, otherwise the 216 second is used. 217 </p> 218 <p> 219 The aim is to keep the <span class="emphasis"><em>x</em></span> argument to <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a> 220 away from 1 to avoid rounding error. 221 </p> 222 </td> 223</tr> 224<tr> 225<td> 226 <p> 227 cdf 228 </p> 229 </td> 230<td> 231 <p> 232 Using the relations: 233 </p> 234 <div class="blockquote"><blockquote class="blockquote"><p> 235 <span class="serif_italic">p = <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a>(v1 236 / 2, v2 / 2, v1 * x / (v2 + v1 * x))</span> 237 </p></blockquote></div> 238 <p> 239 and 240 </p> 241 <div class="blockquote"><blockquote class="blockquote"><p> 242 <span class="serif_italic">:p = <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>(v2 243 / 2, v1 / 2, v2 / (v2 + v1 * x))</span> 244 </p></blockquote></div> 245 <p> 246 The first is used for v1 * x > v2, otherwise the second is 247 used. 248 </p> 249 <p> 250 The aim is to keep the <span class="emphasis"><em>x</em></span> argument to <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a> well 251 away from 1 to avoid rounding error. 252 </p> 253 </td> 254</tr> 255<tr> 256<td> 257 <p> 258 cdf complement 259 </p> 260 </td> 261<td> 262 <p> 263 Using the relations: 264 </p> 265 <div class="blockquote"><blockquote class="blockquote"><p> 266 <span class="serif_italic">p = <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>(v1 267 / 2, v2 / 2, v1 * x / (v2 + v1 * x))</span> 268 </p></blockquote></div> 269 <p> 270 and 271 </p> 272 <div class="blockquote"><blockquote class="blockquote"><p> 273 <span class="serif_italic">p = <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a>(v2 274 / 2, v1 / 2, v2 / (v2 + v1 * x))</span> 275 </p></blockquote></div> 276 <p> 277 The first is used for v1 * x < v2, otherwise the second is 278 used. 279 </p> 280 <p> 281 The aim is to keep the <span class="emphasis"><em>x</em></span> argument to <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a> well 282 away from 1 to avoid rounding error. 283 </p> 284 </td> 285</tr> 286<tr> 287<td> 288 <p> 289 quantile 290 </p> 291 </td> 292<td> 293 <p> 294 Using the relation: 295 </p> 296 <div class="blockquote"><blockquote class="blockquote"><p> 297 <span class="serif_italic">x = v2 * a / (v1 * b)</span> 298 </p></blockquote></div> 299 <p> 300 where: 301 </p> 302 <div class="blockquote"><blockquote class="blockquote"><p> 303 <span class="serif_italic">a = <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>(v1 304 / 2, v2 / 2, p)</span> 305 </p></blockquote></div> 306 <p> 307 and 308 </p> 309 <div class="blockquote"><blockquote class="blockquote"><p> 310 <span class="serif_italic">b = 1 - a</span> 311 </p></blockquote></div> 312 <p> 313 Quantities <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span> 314 are both computed by <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a> 315 without the subtraction implied above. 316 </p> 317 </td> 318</tr> 319<tr> 320<td> 321 <p> 322 quantile 323 </p> 324 <p> 325 from the complement 326 </p> 327 </td> 328<td> 329 <p> 330 Using the relation: 331 </p> 332 <div class="blockquote"><blockquote class="blockquote"><p> 333 <span class="serif_italic">x = v2 * a / (v1 * b)</span> 334 </p></blockquote></div> 335 <p> 336 where 337 </p> 338 <div class="blockquote"><blockquote class="blockquote"><p> 339 <span class="serif_italic">a = <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibetac_inv</a>(v1 340 / 2, v2 / 2, p)</span> 341 </p></blockquote></div> 342 <p> 343 and 344 </p> 345 <div class="blockquote"><blockquote class="blockquote"><p> 346 <span class="serif_italic">b = 1 - a</span> 347 </p></blockquote></div> 348 <p> 349 Quantities <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span> 350 are both computed by <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibetac_inv</a> 351 without the subtraction implied above. 352 </p> 353 </td> 354</tr> 355<tr> 356<td> 357 <p> 358 mean 359 </p> 360 </td> 361<td> 362 <p> 363 v2 / (v2 - 2) 364 </p> 365 </td> 366</tr> 367<tr> 368<td> 369 <p> 370 variance 371 </p> 372 </td> 373<td> 374 <p> 375 2 * v2<sup>2 </sup> * (v1 + v2 - 2) / (v1 * (v2 - 2) * (v2 - 2) * (v2 - 4)) 376 </p> 377 </td> 378</tr> 379<tr> 380<td> 381 <p> 382 mode 383 </p> 384 </td> 385<td> 386 <p> 387 v2 * (v1 - 2) / (v1 * (v2 + 2)) 388 </p> 389 </td> 390</tr> 391<tr> 392<td> 393 <p> 394 skewness 395 </p> 396 </td> 397<td> 398 <p> 399 2 * (v2 + 2 * v1 - 2) * sqrt((2 * v2 - 8) / (v1 * (v2 + v1 - 400 2))) / (v2 - 6) 401 </p> 402 </td> 403</tr> 404<tr> 405<td> 406 <p> 407 kurtosis and kurtosis excess 408 </p> 409 </td> 410<td> 411 <p> 412 Refer to, <a href="http://mathworld.wolfram.com/F-Distribution.html" target="_top">Weisstein, 413 Eric W. "F-Distribution." From MathWorld--A Wolfram 414 Web Resource.</a> 415 </p> 416 </td> 417</tr> 418</tbody> 419</table></div> 420</div> 421<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 422<td align="left"></td> 423<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 424 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 425 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 426 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 427 Daryle Walker and Xiaogang Zhang<p> 428 Distributed under the Boost Software License, Version 1.0. (See accompanying 429 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>) 430 </p> 431</div></td> 432</tr></table> 433<hr> 434<div class="spirit-nav"> 435<a accesskey="p" href="extreme_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="gamma_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 436</div> 437</body> 438</html> 439