owens_t.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Owen's T function</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="../special.html" title="Chapter&#160;8.&#160;Special Functions">
  9. <link rel="prev" href="inv_hyper/atanh.html" title="atanh">
  10. <link rel="next" href="../extern_c.html" title='Chapter&#160;9.&#160;TR1 and C99 external "C" Functions'>
  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="inv_hyper/atanh.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../special.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="../extern_c.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section">
  26. <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  27. <a name="math_toolkit.owens_t"></a><a class="link" href="owens_t.html" title="Owen's T function">Owen's T function</a>
  28. </h2></div></div></div>
  29. <h5>
  30. <a name="math_toolkit.owens_t.h0"></a>
  31. <span class="phrase"><a name="math_toolkit.owens_t.synopsis"></a></span><a class="link" href="owens_t.html#math_toolkit.owens_t.synopsis">Synopsis</a>
  32. </h5>
  33. <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">special_functions</span><span class="special">/</span><span class="identifier">owens_t</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
  34. </pre>
  35. <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>
  36. <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
  37. <a class="link" href="result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">owens_t</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">h</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">a</span><span class="special">);</span>
  38. <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</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>
  39. <a class="link" href="result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">owens_t</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">h</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../policy.html" title="Chapter&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
  40. <span class="special">}}</span> <span class="comment">// namespaces</span>
  41. </pre>
  42. <h5>
  43. <a name="math_toolkit.owens_t.h1"></a>
  44. <span class="phrase"><a name="math_toolkit.owens_t.description"></a></span><a class="link" href="owens_t.html#math_toolkit.owens_t.description">Description</a>
  45. </h5>
  46. <p>
  47. Returns the <a href="http://en.wikipedia.org/wiki/Owen%27s_T_function" target="_top">Owens_t
  48. function</a> of <span class="emphasis"><em>h</em></span> and <span class="emphasis"><em>a</em></span>.
  49. </p>
  50. <p>
  51. The final <a class="link" href="../policy.html" title="Chapter&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
  52. be used to control the behaviour of the function: how it handles errors, what
  53. level of precision to use etc. Refer to the <a class="link" href="../policy.html" title="Chapter&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">policy documentation
  54. for more details</a>.
  55. </p>
  56. <p>
  57. &#8198; &#8198;
  58. </p>
  59. <div class="blockquote"><blockquote class="blockquote"><p>
  60. <span class="inlinemediaobject"><img src="../../equations/owens_t.svg"></span>
  61. </p></blockquote></div>
  62. <p>
  63. <span class="inlinemediaobject"><img src="../../graphs/plot_owens_t.png"></span>
  64. </p>
  65. <p>
  66. The function <code class="computeroutput"><span class="identifier">owens_t</span><span class="special">(</span><span class="identifier">h</span><span class="special">,</span> <span class="identifier">a</span><span class="special">)</span></code> gives the probability of the event <span class="emphasis"><em>(X
  67. &gt; h and 0 &lt; Y &lt; a * X)</em></span>, where <span class="emphasis"><em>X</em></span> and
  68. <span class="emphasis"><em>Y</em></span> are independent standard normal random variables.
  69. </p>
  70. <p>
  71. For h and a &gt; 0, T(h,a), gives the volume of an uncorrelated bivariate normal
  72. distribution with zero means and unit variances over the area between <span class="emphasis"><em>y
  73. = ax</em></span> and <span class="emphasis"><em>y = 0</em></span> and to the right of <span class="emphasis"><em>x
  74. = h</em></span>.
  75. </p>
  76. <p>
  77. That is the area shaded in the figure below (Owens 1956).
  78. </p>
  79. <div class="blockquote"><blockquote class="blockquote"><p>
  80. <span class="inlinemediaobject"><img src="../../graphs/owens_integration_area.svg" align="middle"></span>
  81. </p></blockquote></div>
  82. <p>
  83. and is also illustrated by a 3D plot.
  84. </p>
  85. <p>
  86. <span class="inlinemediaobject"><img src="../../graphs/plot_owens_3d_xyp.png"></span>
  87. </p>
  88. <p>
  89. This function is used in the computation of the <a class="link" href="dist_ref/dists/skew_normal_dist.html" title="Skew Normal Distribution">Skew
  90. Normal Distribution</a>. It is also used in the computation of bivariate
  91. and multivariate normal distribution probabilities. The return type of this
  92. function is computed using the <a class="link" href="result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>result
  93. type calculation rules</em></span></a>: the result is of type <code class="computeroutput"><span class="keyword">double</span></code> when T is an integer type, and type T
  94. otherwise.
  95. </p>
  96. <p>
  97. Owen's original paper (page 1077) provides some additional corner cases.
  98. </p>
  99. <div class="blockquote"><blockquote class="blockquote"><p>
  100. <span class="serif_italic"><span class="emphasis"><em>T(h, 0) = 0</em></span></span>
  101. </p></blockquote></div>
  102. <div class="blockquote"><blockquote class="blockquote"><p>
  103. <span class="serif_italic"><span class="emphasis"><em>T(0, a) = &#189;&#960; arctan(a)</em></span></span>
  104. </p></blockquote></div>
  105. <div class="blockquote"><blockquote class="blockquote"><p>
  106. <span class="serif_italic"><span class="emphasis"><em>T(h, 1) = &#189; G(h) [1 - G(h)]</em></span></span>
  107. </p></blockquote></div>
  108. <div class="blockquote"><blockquote class="blockquote"><p>
  109. <span class="serif_italic"><span class="emphasis"><em>T(h, &#8734;) = G(|h|)</em></span></span>
  110. </p></blockquote></div>
  111. <p>
  112. where G(h) is the univariate normal with zero mean and unit variance integral
  113. from -&#8734; to h.
  114. </p>
  115. <h5>
  116. <a name="math_toolkit.owens_t.h2"></a>
  117. <span class="phrase"><a name="math_toolkit.owens_t.accuracy"></a></span><a class="link" href="owens_t.html#math_toolkit.owens_t.accuracy">Accuracy</a>
  118. </h5>
  119. <p>
  120. Over the built-in types and range tested, errors are less than 10 * std::numeric_limits&lt;RealType&gt;::epsilon().
  121. </p>
  122. <div class="table">
  123. <a name="math_toolkit.owens_t.table_owens_t"></a><p class="title"><b>Table&#160;8.86.&#160;Error rates for owens_t</b></p>
  124. <div class="table-contents"><table class="table" summary="Error rates for owens_t">
  125. <colgroup>
  126. <col>
  127. <col>
  128. <col>
  129. <col>
  130. <col>
  131. </colgroup>
  132. <thead><tr>
  133. <th>
  134. </th>
  135. <th>
  136. <p>
  137. GNU C++ version 7.1.0<br> linux<br> double
  138. </p>
  139. </th>
  140. <th>
  141. <p>
  142. GNU C++ version 7.1.0<br> linux<br> long double
  143. </p>
  144. </th>
  145. <th>
  146. <p>
  147. Sun compiler version 0x5150<br> Sun Solaris<br> long double
  148. </p>
  149. </th>
  150. <th>
  151. <p>
  152. Microsoft Visual C++ version 14.1<br> Win32<br> double
  153. </p>
  154. </th>
  155. </tr></thead>
  156. <tbody>
  157. <tr>
  158. <td>
  159. <p>
  160. Owens T (medium small values)
  161. </p>
  162. </td>
  163. <td>
  164. <p>
  165. <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span>
  166. </p>
  167. </td>
  168. <td>
  169. <p>
  170. <span class="blue">Max = 3.34&#949; (Mean = 0.944&#949;)</span>
  171. </p>
  172. </td>
  173. <td>
  174. <p>
  175. <span class="blue">Max = 3.34&#949; (Mean = 0.911&#949;)</span>
  176. </p>
  177. </td>
  178. <td>
  179. <p>
  180. <span class="blue">Max = 4.37&#949; (Mean = 0.98&#949;)</span>
  181. </p>
  182. </td>
  183. </tr>
  184. <tr>
  185. <td>
  186. <p>
  187. Owens T (large and diverse values)
  188. </p>
  189. </td>
  190. <td>
  191. <p>
  192. <span class="blue">Max = 0&#949; (Mean = 0&#949;)</span>
  193. </p>
  194. </td>
  195. <td>
  196. <p>
  197. <span class="blue">Max = 49&#949; (Mean = 2.16&#949;)</span>
  198. </p>
  199. </td>
  200. <td>
  201. <p>
  202. <span class="blue">Max = 24.5&#949; (Mean = 1.39&#949;)</span>
  203. </p>
  204. </td>
  205. <td>
  206. <p>
  207. <span class="blue">Max = 3.78&#949; (Mean = 0.621&#949;)</span>
  208. </p>
  209. </td>
  210. </tr>
  211. </tbody>
  212. </table></div>
  213. </div>
  214. <br class="table-break"><h5>
  215. <a name="math_toolkit.owens_t.h3"></a>
  216. <span class="phrase"><a name="math_toolkit.owens_t.testing"></a></span><a class="link" href="owens_t.html#math_toolkit.owens_t.testing">Testing</a>
  217. </h5>
  218. <p>
  219. Test data was generated by Patefield and Tandy algorithms T1 and T4, and also
  220. the suggested reference routine T7.
  221. </p>
  222. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  223. <li class="listitem">
  224. T1 was rejected if the result was too small compared to <code class="computeroutput"><span class="identifier">atan</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span></code>
  225. (ie cancellation),
  226. </li>
  227. <li class="listitem">
  228. T4 was rejected if there was no convergence,
  229. </li>
  230. <li class="listitem">
  231. Both were rejected if they didn't agree.
  232. </li>
  233. </ul></div>
  234. <p>
  235. Over the built-in types and range tested, errors are less than 10 std::numeric_limits&lt;RealType&gt;::epsilon().
  236. </p>
  237. <p>
  238. However, that there was a whole domain (large <span class="emphasis"><em>h</em></span>, small
  239. <span class="emphasis"><em>a</em></span>) where it was not possible to generate any reliable
  240. test values (all the methods got rejected for one reason or another).
  241. </p>
  242. <p>
  243. There are also two sets of sanity tests: spot values are computed using <a href="http://www.wolfram.com/products/mathematica/index.html" target="_top">Wolfram Mathematica</a>
  244. and <a href="http://www.r-project.org/" target="_top">The R Project for Statistical Computing</a>.
  245. </p>
  246. <h5>
  247. <a name="math_toolkit.owens_t.h4"></a>
  248. <span class="phrase"><a name="math_toolkit.owens_t.implementation"></a></span><a class="link" href="owens_t.html#math_toolkit.owens_t.implementation">Implementation</a>
  249. </h5>
  250. <p>
  251. The function was proposed and evaluated by <a href="http://projecteuclid.org/DPubS?service=UI&amp;version=1.0&amp;verb=Display&amp;handle=euclid.aoms/1177728074" target="_top">Donald.
  252. B. Owen, Tables for computing bivariate normal probabilities, Ann. Math. Statist.,
  253. 27, 1075-1090 (1956)</a>.
  254. </p>
  255. <p>
  256. The algorithms of Patefield, M. and Tandy, D. "Fast and accurate Calculation
  257. of Owen's T-Function", Journal of Statistical Software, 5 (5), 1 - 25
  258. (2000) are adapted for C++ with arbitrary RealType.
  259. </p>
  260. <p>
  261. The Patefield-Tandy algorithm provides six methods of evalualution (T1 to T6);
  262. the best method is selected according to the values of <span class="emphasis"><em>a</em></span>
  263. and <span class="emphasis"><em>h</em></span>. See the original paper and the source in <a href="../../../../../boost/math/special_functions/owens_t.hpp" target="_top">owens_t.hpp</a>
  264. for details.
  265. </p>
  266. <p>
  267. The Patefield-Tandy algorithm is accurate to approximately 20 decimal places,
  268. so for types with greater precision we use:
  269. </p>
  270. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  271. <li class="listitem">
  272. A modified version of T1 which folds the calculation of <span class="emphasis"><em>atan(h)</em></span>
  273. into the T1 series (to avoid subtracting two values similar in magnitude),
  274. and then accelerates the resulting alternating series using method 1 from
  275. H. Cohen, F. Rodriguez Villegas, D. Zagier, "Convergence acceleration
  276. of alternating series", Bonn, (1991). The result is valid everywhere,
  277. but doesn't always converge, or may become too divergent in the first few
  278. terms to sum accurately. This is used for <span class="emphasis"><em>ah &lt; 1</em></span>.
  279. </li>
  280. <li class="listitem">
  281. A modified version of T2 which is accelerated in the same manner as T1.
  282. This is used for <span class="emphasis"><em>h &gt; 1</em></span>.
  283. </li>
  284. <li class="listitem">
  285. A version of T4 only when both T1 and T2 have failed to produce an accurate
  286. answer.
  287. </li>
  288. <li class="listitem">
  289. Fallback to the Patefiled Tandy algorithm when all the above methods fail:
  290. this happens not at all for our test data at 100 decimal digits precision.
  291. However, there is a difficult area when <span class="emphasis"><em>a</em></span> is very
  292. close to 1 and the precision increases which may cause this to happen in
  293. very exceptional circumstances.
  294. </li>
  295. </ul></div>
  296. <p>
  297. Using the above algorithm and a 100-decimal digit type, results accurate to
  298. 80 decimal places were obtained in the difficult area where <span class="emphasis"><em>a</em></span>
  299. is close to 1, and greater than 95 decimal places elsewhere.
  300. </p>
  301. </div>
  302. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  303. <td align="left"></td>
  304. <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2019 Nikhar
  305. Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
  306. Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
  307. R&#229;de, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
  308. Daryle Walker and Xiaogang Zhang<p>
  309. Distributed under the Boost Software License, Version 1.0. (See accompanying
  310. 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>)
  311. </p>
  312. </div></td>
  313. </tr></table>
  314. <hr>
  315. <div class="spirit-nav">
  316. <a accesskey="p" href="inv_hyper/atanh.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../special.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="../extern_c.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  317. </div>
  318. </body>
  319. </html>