• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>The Incomplete Beta Function Inverses</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="../sf_beta.html" title="Beta Functions">
9<link rel="prev" href="ibeta_function.html" title="Incomplete Beta Functions">
10<link rel="next" href="beta_derivative.html" title="Derivative of the Incomplete Beta Function">
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="ibeta_function.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_beta.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="beta_derivative.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h3 class="title">
27<a name="math_toolkit.sf_beta.ibeta_inv_function"></a><a class="link" href="ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">The Incomplete
28      Beta Function Inverses</a>
29</h3></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">special_functions</span><span class="special">/</span><span class="identifier">beta</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
31</pre>
32<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
34<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
35<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">ibeta_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">);</span>
36
37<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
38<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">ibeta_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
39
40<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T4</span><span class="special">&gt;</span>
41<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">ibeta_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">T4</span><span class="special">*</span> <span class="identifier">py</span><span class="special">);</span>
42
43<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T4</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">&gt;</span>
44<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">ibeta_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">T4</span><span class="special">*</span> <span class="identifier">py</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
45
46<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
47<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">ibetac_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">);</span>
48
49<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
50<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">ibetac_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
51
52<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T4</span><span class="special">&gt;</span>
53<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">ibetac_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">,</span> <span class="identifier">T4</span><span class="special">*</span> <span class="identifier">py</span><span class="special">);</span>
54
55<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T4</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">&gt;</span>
56<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">ibetac_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">,</span> <span class="identifier">T4</span><span class="special">*</span> <span class="identifier">py</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
57
58<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
59<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">ibeta_inva</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">);</span>
60
61<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
62<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">ibeta_inva</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
63
64<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
65<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">ibetac_inva</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">);</span>
66
67<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
68<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">ibetac_inva</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
69
70<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
71<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">ibeta_invb</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">);</span>
72
73<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
74<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">ibeta_invb</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
75
76<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
77<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">ibetac_invb</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">);</span>
78
79<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
80<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">ibetac_invb</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
81
82<span class="special">}}</span> <span class="comment">// namespaces</span>
83</pre>
84<h5>
85<a name="math_toolkit.sf_beta.ibeta_inv_function.h0"></a>
86        <span class="phrase"><a name="math_toolkit.sf_beta.ibeta_inv_function.description"></a></span><a class="link" href="ibeta_inv_function.html#math_toolkit.sf_beta.ibeta_inv_function.description">Description</a>
87      </h5>
88<p>
89        There are six <a href="http://functions.wolfram.com/GammaBetaErf/" target="_top">incomplete
90        beta function inverses</a> which allow you solve for any of the three
91        parameters to the incomplete beta, starting from either the result of the
92        incomplete beta (p) or its complement (q).
93      </p>
94<p>
95        The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
96        be used to control the behaviour of the function: how it handles errors,
97        what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy
98        documentation for more details</a>.
99      </p>
100<div class="tip"><table border="0" summary="Tip">
101<tr>
102<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../doc/src/images/tip.png"></td>
103<th align="left">Tip</th>
104</tr>
105<tr><td align="left" valign="top">
106<p>
107          When people normally talk about the inverse of the incomplete beta function,
108          they are talking about inverting on parameter <span class="emphasis"><em>x</em></span>. These
109          are implemented here as <code class="computeroutput"><span class="identifier">ibeta_inv</span></code>
110          and <code class="computeroutput"><span class="identifier">ibetac_inv</span></code>, and are
111          by far the most efficient of the inverses presented here.
112        </p>
113<p>
114          The inverses on the <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span> parameters
115          find use in some statistical applications, but have to be computed by rather
116          brute force numerical techniques and are consequently several times slower.
117          These are implemented here as <code class="computeroutput"><span class="identifier">ibeta_inva</span></code>
118          and <code class="computeroutput"><span class="identifier">ibeta_invb</span></code>, and complement
119          versions <code class="computeroutput"><span class="identifier">ibetac_inva</span></code> and
120          <code class="computeroutput"><span class="identifier">ibetac_invb</span></code>.
121        </p>
122</td></tr>
123</table></div>
124<p>
125        The return type of these functions is computed using the <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>result
126        type calculation rules</em></span></a> when called with arguments T1...TN
127        of different types.
128      </p>
129<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
130<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">ibeta_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">);</span>
131
132<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
133<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">ibeta_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
134
135<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T4</span><span class="special">&gt;</span>
136<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">ibeta_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">T4</span><span class="special">*</span> <span class="identifier">py</span><span class="special">);</span>
137
138<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T4</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">&gt;</span>
139<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">ibeta_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">T4</span><span class="special">*</span> <span class="identifier">py</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
140</pre>
141<p>
142        Returns a value <span class="emphasis"><em>x</em></span> such that: <code class="computeroutput"><span class="identifier">p</span>
143        <span class="special">=</span> <span class="identifier">ibeta</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span>
144        <span class="identifier">b</span><span class="special">,</span> <span class="identifier">x</span><span class="special">);</span></code> and
145        sets <code class="computeroutput"><span class="special">*</span><span class="identifier">py</span>
146        <span class="special">=</span> <span class="number">1</span> <span class="special">-</span> <span class="identifier">x</span></code> when
147        the <code class="computeroutput"><span class="identifier">py</span></code> parameter is provided
148        and is non-null. Note that internally this function computes whichever is
149        the smaller of <code class="computeroutput"><span class="identifier">x</span></code> and <code class="computeroutput"><span class="number">1</span><span class="special">-</span><span class="identifier">x</span></code>,
150        and therefore the value assigned to <code class="computeroutput"><span class="special">*</span><span class="identifier">py</span></code> is free from cancellation errors. That
151        means that even if the function returns <code class="computeroutput"><span class="number">1</span></code>,
152        the value stored in <code class="computeroutput"><span class="special">*</span><span class="identifier">py</span></code>
153        may be non-zero, albeit very small.
154      </p>
155<p>
156        Requires: <span class="emphasis"><em>a,b &gt; 0</em></span> and <span class="emphasis"><em>0 &lt;= p &lt;= 1</em></span>.
157      </p>
158<p>
159        The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
160        be used to control the behaviour of the function: how it handles errors,
161        what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy
162        documentation for more details</a>.
163      </p>
164<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
165<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">ibetac_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">);</span>
166
167<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
168<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">ibetac_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
169
170<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T4</span><span class="special">&gt;</span>
171<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">ibetac_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">,</span> <span class="identifier">T4</span><span class="special">*</span> <span class="identifier">py</span><span class="special">);</span>
172
173<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T4</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">&gt;</span>
174<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">ibetac_inv</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">q</span><span class="special">,</span> <span class="identifier">T4</span><span class="special">*</span> <span class="identifier">py</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
175</pre>
176<p>
177        Returns a value <span class="emphasis"><em>x</em></span> such that: <code class="computeroutput"><span class="identifier">q</span>
178        <span class="special">=</span> <span class="identifier">ibetac</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span>
179        <span class="identifier">b</span><span class="special">,</span> <span class="identifier">x</span><span class="special">);</span></code> and
180        sets <code class="computeroutput"><span class="special">*</span><span class="identifier">py</span>
181        <span class="special">=</span> <span class="number">1</span> <span class="special">-</span> <span class="identifier">x</span></code> when
182        the <code class="computeroutput"><span class="identifier">py</span></code> parameter is provided
183        and is non-null. Note that internally this function computes whichever is
184        the smaller of <code class="computeroutput"><span class="identifier">x</span></code> and <code class="computeroutput"><span class="number">1</span><span class="special">-</span><span class="identifier">x</span></code>,
185        and therefore the value assigned to <code class="computeroutput"><span class="special">*</span><span class="identifier">py</span></code> is free from cancellation errors. That
186        means that even if the function returns <code class="computeroutput"><span class="number">1</span></code>,
187        the value stored in <code class="computeroutput"><span class="special">*</span><span class="identifier">py</span></code>
188        may be non-zero, albeit very small.
189      </p>
190<p>
191        Requires: <span class="emphasis"><em>a,b &gt; 0</em></span> and <span class="emphasis"><em>0 &lt;= q &lt;= 1</em></span>.
192      </p>
193<p>
194        The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
195        be used to control the behaviour of the function: how it handles errors,
196        what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy
197        documentation for more details</a>.
198      </p>
199<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
200<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">ibeta_inva</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">);</span>
201
202<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
203<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">ibeta_inva</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
204</pre>
205<p>
206        Returns a value <span class="emphasis"><em>a</em></span> such that: <code class="computeroutput"><span class="identifier">p</span>
207        <span class="special">=</span> <span class="identifier">ibeta</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span>
208        <span class="identifier">b</span><span class="special">,</span> <span class="identifier">x</span><span class="special">);</span></code>
209      </p>
210<p>
211        Requires: <span class="emphasis"><em>b &gt; 0</em></span>, <span class="emphasis"><em>0 &lt; x &lt; 1</em></span>
212        and <span class="emphasis"><em>0 &lt;= p &lt;= 1</em></span>.
213      </p>
214<p>
215        The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
216        be used to control the behaviour of the function: how it handles errors,
217        what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy
218        documentation for more details</a>.
219      </p>
220<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
221<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">ibetac_inva</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">);</span>
222
223<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
224<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">ibetac_inva</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
225</pre>
226<p>
227        Returns a value <span class="emphasis"><em>a</em></span> such that: <code class="computeroutput"><span class="identifier">q</span>
228        <span class="special">=</span> <span class="identifier">ibetac</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span>
229        <span class="identifier">b</span><span class="special">,</span> <span class="identifier">x</span><span class="special">);</span></code>
230      </p>
231<p>
232        Requires: <span class="emphasis"><em>b &gt; 0</em></span>, <span class="emphasis"><em>0 &lt; x &lt; 1</em></span>
233        and <span class="emphasis"><em>0 &lt;= q &lt;= 1</em></span>.
234      </p>
235<p>
236        The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
237        be used to control the behaviour of the function: how it handles errors,
238        what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy
239        documentation for more details</a>.
240      </p>
241<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
242<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">ibeta_invb</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">);</span>
243
244<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
245<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">ibeta_invb</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
246</pre>
247<p>
248        Returns a value <span class="emphasis"><em>b</em></span> such that: <code class="computeroutput"><span class="identifier">p</span>
249        <span class="special">=</span> <span class="identifier">ibeta</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span>
250        <span class="identifier">b</span><span class="special">,</span> <span class="identifier">x</span><span class="special">);</span></code>
251      </p>
252<p>
253        Requires: <span class="emphasis"><em>a &gt; 0</em></span>, <span class="emphasis"><em>0 &lt; x &lt; 1</em></span>
254        and <span class="emphasis"><em>0 &lt;= p &lt;= 1</em></span>.
255      </p>
256<p>
257        The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
258        be used to control the behaviour of the function: how it handles errors,
259        what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy
260        documentation for more details</a>.
261      </p>
262<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</span><span class="special">&gt;</span>
263<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">ibetac_invb</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">);</span>
264
265<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T3</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">&gt;</span>
266<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">ibetac_invb</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T3</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
267</pre>
268<p>
269        Returns a value <span class="emphasis"><em>b</em></span> such that: <code class="computeroutput"><span class="identifier">q</span>
270        <span class="special">=</span> <span class="identifier">ibetac</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span>
271        <span class="identifier">b</span><span class="special">,</span> <span class="identifier">x</span><span class="special">);</span></code>
272      </p>
273<p>
274        Requires: <span class="emphasis"><em>a &gt; 0</em></span>, <span class="emphasis"><em>0 &lt; x &lt; 1</em></span>
275        and <span class="emphasis"><em>0 &lt;= q &lt;= 1</em></span>.
276      </p>
277<p>
278        The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
279        be used to control the behaviour of the function: how it handles errors,
280        what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy
281        documentation for more details</a>.
282      </p>
283<h5>
284<a name="math_toolkit.sf_beta.ibeta_inv_function.h1"></a>
285        <span class="phrase"><a name="math_toolkit.sf_beta.ibeta_inv_function.accuracy"></a></span><a class="link" href="ibeta_inv_function.html#math_toolkit.sf_beta.ibeta_inv_function.accuracy">Accuracy</a>
286      </h5>
287<p>
288        The accuracy of these functions should closely follow that of the regular
289        forward incomplete beta functions. However, note that in some parts of their
290        domain, these functions can be extremely sensitive to changes in input, particularly
291        when the argument <span class="emphasis"><em>p</em></span> (or it's complement <span class="emphasis"><em>q</em></span>)
292        is very close to <code class="computeroutput"><span class="number">0</span></code> or <code class="computeroutput"><span class="number">1</span></code>.
293      </p>
294<p>
295        Comparisons to other libraries are shown below, note that our test data exercises
296        some rather extreme cases in the incomplete beta function which many other
297        libraries fail to handle:
298      </p>
299<div class="table">
300<a name="math_toolkit.sf_beta.ibeta_inv_function.table_ibeta_inv"></a><p class="title"><b>Table 8.22. Error rates for ibeta_inv</b></p>
301<div class="table-contents"><table class="table" summary="Error rates for ibeta_inv">
302<colgroup>
303<col>
304<col>
305<col>
306<col>
307<col>
308</colgroup>
309<thead><tr>
310<th>
311              </th>
312<th>
313                <p>
314                  GNU C++ version 7.1.0<br> linux<br> double
315                </p>
316              </th>
317<th>
318                <p>
319                  GNU C++ version 7.1.0<br> linux<br> long double
320                </p>
321              </th>
322<th>
323                <p>
324                  Sun compiler version 0x5150<br> Sun Solaris<br> long double
325                </p>
326              </th>
327<th>
328                <p>
329                  Microsoft Visual C++ version 14.1<br> Win32<br> double
330                </p>
331              </th>
332</tr></thead>
333<tbody><tr>
334<td>
335                <p>
336                  Inverse incomplete beta
337                </p>
338              </td>
339<td>
340                <p>
341                  <span class="blue">Max = 11ε (Mean = 0.345ε)</span><br> <br>
342                  (<span class="emphasis"><em>Rmath 3.2.3:</em></span> <span class="red">Max = 1.14e+121ε (Mean
343                  = 3.28e+119ε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_ibeta_inv_Rmath_3_2_3_Inverse_incomplete_beta">And
344                  other failures.</a>)</span>
345                </p>
346              </td>
347<td>
348                <p>
349                  <span class="blue">Max = 3.8e+04ε (Mean = 2.66e+03ε)</span>
350                </p>
351              </td>
352<td>
353                <p>
354                  <span class="blue">Max = 4.07e+04ε (Mean = 2.86e+03ε)</span>
355                </p>
356              </td>
357<td>
358                <p>
359                  <span class="blue">Max = 8.59e+03ε (Mean = 277ε)</span>
360                </p>
361              </td>
362</tr></tbody>
363</table></div>
364</div>
365<br class="table-break"><div class="table">
366<a name="math_toolkit.sf_beta.ibeta_inv_function.table_ibetac_inv"></a><p class="title"><b>Table 8.23. Error rates for ibetac_inv</b></p>
367<div class="table-contents"><table class="table" summary="Error rates for ibetac_inv">
368<colgroup>
369<col>
370<col>
371<col>
372<col>
373<col>
374</colgroup>
375<thead><tr>
376<th>
377              </th>
378<th>
379                <p>
380                  GNU C++ version 7.1.0<br> linux<br> double
381                </p>
382              </th>
383<th>
384                <p>
385                  GNU C++ version 7.1.0<br> linux<br> long double
386                </p>
387              </th>
388<th>
389                <p>
390                  Sun compiler version 0x5150<br> Sun Solaris<br> long double
391                </p>
392              </th>
393<th>
394                <p>
395                  Microsoft Visual C++ version 14.1<br> Win32<br> double
396                </p>
397              </th>
398</tr></thead>
399<tbody><tr>
400<td>
401                <p>
402                  Inverse incomplete beta
403                </p>
404              </td>
405<td>
406                <p>
407                  <span class="blue">Max = 0.977ε (Mean = 0.0976ε)</span><br>
408                  <br> (<span class="emphasis"><em>Rmath 3.2.3:</em></span> <span class="red">Max
409                  = 3.01e+132ε (Mean = 8.65e+130ε) <a class="link" href="../logs_and_tables/logs.html#errors_GNU_C_version_7_1_0_linux_double_ibetac_inv_Rmath_3_2_3_Inverse_incomplete_beta">And
410                  other failures.</a>)</span>
411                </p>
412              </td>
413<td>
414                <p>
415                  <span class="blue">Max = 4.88e+04ε (Mean = 3.16e+03ε)</span>
416                </p>
417              </td>
418<td>
419                <p>
420                  <span class="blue">Max = 5.05e+04ε (Mean = 3.33e+03ε)</span>
421                </p>
422              </td>
423<td>
424                <p>
425                  <span class="blue">Max = 2.93e+03ε (Mean = 198ε)</span>
426                </p>
427              </td>
428</tr></tbody>
429</table></div>
430</div>
431<br class="table-break"><div class="table">
432<a name="math_toolkit.sf_beta.ibeta_inv_function.table_ibeta_inva"></a><p class="title"><b>Table 8.24. Error rates for ibeta_inva</b></p>
433<div class="table-contents"><table class="table" summary="Error rates for ibeta_inva">
434<colgroup>
435<col>
436<col>
437<col>
438<col>
439<col>
440</colgroup>
441<thead><tr>
442<th>
443              </th>
444<th>
445                <p>
446                  GNU C++ version 7.1.0<br> linux<br> double
447                </p>
448              </th>
449<th>
450                <p>
451                  GNU C++ version 7.1.0<br> linux<br> long double
452                </p>
453              </th>
454<th>
455                <p>
456                  Sun compiler version 0x5150<br> Sun Solaris<br> long double
457                </p>
458              </th>
459<th>
460                <p>
461                  Microsoft Visual C++ version 14.1<br> Win32<br> double
462                </p>
463              </th>
464</tr></thead>
465<tbody><tr>
466<td>
467                <p>
468                  Inverse incomplete beta
469                </p>
470              </td>
471<td>
472                <p>
473                  <span class="blue">Max = 0.602ε (Mean = 0.0239ε)</span>
474                </p>
475              </td>
476<td>
477                <p>
478                  <span class="blue">Max = 377ε (Mean = 24.4ε)</span>
479                </p>
480              </td>
481<td>
482                <p>
483                  <span class="blue">Max = 438ε (Mean = 31.3ε)</span>
484                </p>
485              </td>
486<td>
487                <p>
488                  <span class="blue">Max = 242ε (Mean = 22.9ε)</span>
489                </p>
490              </td>
491</tr></tbody>
492</table></div>
493</div>
494<br class="table-break"><div class="table">
495<a name="math_toolkit.sf_beta.ibeta_inv_function.table_ibetac_inva"></a><p class="title"><b>Table 8.25. Error rates for ibetac_inva</b></p>
496<div class="table-contents"><table class="table" summary="Error rates for ibetac_inva">
497<colgroup>
498<col>
499<col>
500<col>
501<col>
502<col>
503</colgroup>
504<thead><tr>
505<th>
506              </th>
507<th>
508                <p>
509                  GNU C++ version 7.1.0<br> linux<br> double
510                </p>
511              </th>
512<th>
513                <p>
514                  GNU C++ version 7.1.0<br> linux<br> long double
515                </p>
516              </th>
517<th>
518                <p>
519                  Sun compiler version 0x5150<br> Sun Solaris<br> long double
520                </p>
521              </th>
522<th>
523                <p>
524                  Microsoft Visual C++ version 14.1<br> Win32<br> double
525                </p>
526              </th>
527</tr></thead>
528<tbody><tr>
529<td>
530                <p>
531                  Inverse incomplete beta
532                </p>
533              </td>
534<td>
535                <p>
536                  <span class="blue">Max = 0.683ε (Mean = 0.0314ε)</span>
537                </p>
538              </td>
539<td>
540                <p>
541                  <span class="blue">Max = 382ε (Mean = 22.2ε)</span>
542                </p>
543              </td>
544<td>
545                <p>
546                  <span class="blue">Max = 315ε (Mean = 23.7ε)</span>
547                </p>
548              </td>
549<td>
550                <p>
551                  <span class="blue">Max = 408ε (Mean = 26.7ε)</span>
552                </p>
553              </td>
554</tr></tbody>
555</table></div>
556</div>
557<br class="table-break"><div class="table">
558<a name="math_toolkit.sf_beta.ibeta_inv_function.table_ibeta_invb"></a><p class="title"><b>Table 8.26. Error rates for ibeta_invb</b></p>
559<div class="table-contents"><table class="table" summary="Error rates for ibeta_invb">
560<colgroup>
561<col>
562<col>
563<col>
564<col>
565<col>
566</colgroup>
567<thead><tr>
568<th>
569              </th>
570<th>
571                <p>
572                  GNU C++ version 7.1.0<br> linux<br> double
573                </p>
574              </th>
575<th>
576                <p>
577                  GNU C++ version 7.1.0<br> linux<br> long double
578                </p>
579              </th>
580<th>
581                <p>
582                  Sun compiler version 0x5150<br> Sun Solaris<br> long double
583                </p>
584              </th>
585<th>
586                <p>
587                  Microsoft Visual C++ version 14.1<br> Win32<br> double
588                </p>
589              </th>
590</tr></thead>
591<tbody><tr>
592<td>
593                <p>
594                  Inverse incomplete beta
595                </p>
596              </td>
597<td>
598                <p>
599                  <span class="blue">Max = 0.765ε (Mean = 0.0422ε)</span>
600                </p>
601              </td>
602<td>
603                <p>
604                  <span class="blue">Max = 407ε (Mean = 27.2ε)</span>
605                </p>
606              </td>
607<td>
608                <p>
609                  <span class="blue">Max = 407ε (Mean = 24.4ε)</span>
610                </p>
611              </td>
612<td>
613                <p>
614                  <span class="blue">Max = 409ε (Mean = 19.3ε)</span>
615                </p>
616              </td>
617</tr></tbody>
618</table></div>
619</div>
620<br class="table-break"><div class="table">
621<a name="math_toolkit.sf_beta.ibeta_inv_function.table_ibetac_invb"></a><p class="title"><b>Table 8.27. Error rates for ibetac_invb</b></p>
622<div class="table-contents"><table class="table" summary="Error rates for ibetac_invb">
623<colgroup>
624<col>
625<col>
626<col>
627<col>
628<col>
629</colgroup>
630<thead><tr>
631<th>
632              </th>
633<th>
634                <p>
635                  GNU C++ version 7.1.0<br> linux<br> double
636                </p>
637              </th>
638<th>
639                <p>
640                  GNU C++ version 7.1.0<br> linux<br> long double
641                </p>
642              </th>
643<th>
644                <p>
645                  Sun compiler version 0x5150<br> Sun Solaris<br> long double
646                </p>
647              </th>
648<th>
649                <p>
650                  Microsoft Visual C++ version 14.1<br> Win32<br> double
651                </p>
652              </th>
653</tr></thead>
654<tbody><tr>
655<td>
656                <p>
657                  Inverse incomplete beta
658                </p>
659              </td>
660<td>
661                <p>
662                  <span class="blue">Max = 0.724ε (Mean = 0.0303ε)</span>
663                </p>
664              </td>
665<td>
666                <p>
667                  <span class="blue">Max = 317ε (Mean = 19.8ε)</span>
668                </p>
669              </td>
670<td>
671                <p>
672                  <span class="blue">Max = 369ε (Mean = 22.6ε)</span>
673                </p>
674              </td>
675<td>
676                <p>
677                  <span class="blue">Max = 271ε (Mean = 16.4ε)</span>
678                </p>
679              </td>
680</tr></tbody>
681</table></div>
682</div>
683<br class="table-break"><h5>
684<a name="math_toolkit.sf_beta.ibeta_inv_function.h2"></a>
685        <span class="phrase"><a name="math_toolkit.sf_beta.ibeta_inv_function.testing"></a></span><a class="link" href="ibeta_inv_function.html#math_toolkit.sf_beta.ibeta_inv_function.testing">Testing</a>
686      </h5>
687<p>
688        There are two sets of tests:
689      </p>
690<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
691<li class="listitem">
692            Basic sanity checks attempt to "round-trip" from <span class="emphasis"><em>a,
693            b</em></span> and <span class="emphasis"><em>x</em></span> to <span class="emphasis"><em>p</em></span> or
694            <span class="emphasis"><em>q</em></span> and back again. These tests have quite generous
695            tolerances: in general both the incomplete beta and its inverses change
696            so rapidly, that round tripping to more than a couple of significant
697            digits isn't possible. This is especially true when <span class="emphasis"><em>p</em></span>
698            or <span class="emphasis"><em>q</em></span> is very near one: in this case there isn't
699            enough "information content" in the input to the inverse function
700            to get back where you started.
701          </li>
702<li class="listitem">
703            Accuracy checks using high precision test values. These measure the accuracy
704            of the result, given exact input values.
705          </li>
706</ul></div>
707<h5>
708<a name="math_toolkit.sf_beta.ibeta_inv_function.h3"></a>
709        <span class="phrase"><a name="math_toolkit.sf_beta.ibeta_inv_function.implementation_of_ibeta_inv_and_"></a></span><a class="link" href="ibeta_inv_function.html#math_toolkit.sf_beta.ibeta_inv_function.implementation_of_ibeta_inv_and_">Implementation
710        of ibeta_inv and ibetac_inv</a>
711      </h5>
712<p>
713        These two functions share a common implementation.
714      </p>
715<p>
716        First an initial approximation to x is computed then the last few bits are
717        cleaned up using <a href="http://en.wikipedia.org/wiki/Simple_rational_approximation" target="_top">Halley
718        iteration</a>. The iteration limit is set to 1/2 of the number of bits
719        in T, which by experiment is sufficient to ensure that the inverses are at
720        least as accurate as the normal incomplete beta functions. Up to 5 iterations
721        may be required in extreme cases, although normally only one or two are required.
722        Further, the number of iterations required decreases with increasing <span class="emphasis"><em>a</em></span>
723        and <span class="emphasis"><em>b</em></span> (which generally form the more important use cases).
724      </p>
725<p>
726        The initial guesses used for iteration are obtained as follows:
727      </p>
728<p>
729        Firstly recall that:
730      </p>
731<div class="blockquote"><blockquote class="blockquote"><p>
732          <span class="inlinemediaobject"><img src="../../../equations/ibeta_inv5.svg"></span>
733
734        </p></blockquote></div>
735<p>
736        We may wish to start from either p or q, and to calculate either x or y.
737        In addition at any stage we can exchange a for b, p for q, and x for y if
738        it results in a more manageable problem.
739      </p>
740<p>
741        For <code class="computeroutput"><span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span> <span class="special">&gt;=</span> <span class="number">5</span></code> the initial guess is computed using the methods
742        described in:
743      </p>
744<p>
745        Asymptotic Inversion of the Incomplete Beta Function, by N. M. <a href="http://homepages.cwi.nl/~nicot/" target="_top">Temme</a>.
746        Journal of Computational and Applied Mathematics 41 (1992) 145-157.
747      </p>
748<p>
749        The nearly symmetrical case (section 2 of the paper) is used for
750      </p>
751<div class="blockquote"><blockquote class="blockquote"><p>
752          <span class="inlinemediaobject"><img src="../../../equations/ibeta_inv2.svg"></span>
753
754        </p></blockquote></div>
755<p>
756        and involves solving the inverse error function first. The method is accurate
757        to at least 2 decimal digits when <code class="literal">a = 5</code> rising to at least
758        8 digits when <code class="literal">a = 10<sup>5</sup></code>.
759      </p>
760<p>
761        The general error function case (section 3 of the paper) is used for
762      </p>
763<div class="blockquote"><blockquote class="blockquote"><p>
764          <span class="inlinemediaobject"><img src="../../../equations/ibeta_inv3.svg"></span>
765
766        </p></blockquote></div>
767<p>
768        and again expresses the inverse incomplete beta in terms of the inverse of
769        the error function. The method is accurate to at least 2 decimal digits when
770        <code class="literal">a+b = 5</code> rising to 11 digits when <code class="literal">a+b = 10<sup>5</sup></code>.
771        However, when the result is expected to be very small, and when a+b is also
772        small, then its accuracy tails off, in this case when p<sup>1/a</sup> &lt; 0.0025 then
773        it is better to use the following as an initial estimate:
774      </p>
775<div class="blockquote"><blockquote class="blockquote"><p>
776          <span class="inlinemediaobject"><img src="../../../equations/ibeta_inv4.svg"></span>
777
778        </p></blockquote></div>
779<p>
780        Finally the for all other cases where <code class="computeroutput"><span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span> <span class="special">&gt;</span>
781        <span class="number">5</span></code> the method of section 4 of the paper
782        is used. This expresses the inverse incomplete beta in terms of the inverse
783        of the incomplete gamma function, and is therefore significantly more expensive
784        to compute than the other cases. However the method is accurate to at least
785        3 decimal digits when <code class="literal">a = 5</code> rising to at least 10 digits
786        when <code class="literal">a = 10<sup>5</sup></code>. This method is limited to a &gt; b, and
787        therefore we need to perform an exchange a for b, p for q and x for y when
788        this is not the case. In addition when p is close to 1 the method is inaccurate
789        should we actually want y rather than x as output. Therefore when q is small
790        (<code class="literal">q<sup>1/p</sup> &lt; 10<sup>-3</sup></code>) we use:
791      </p>
792<div class="blockquote"><blockquote class="blockquote"><p>
793          <span class="inlinemediaobject"><img src="../../../equations/ibeta_inv6.svg"></span>
794
795        </p></blockquote></div>
796<p>
797        which is both cheaper to compute than the full method, and a more accurate
798        estimate on q.
799      </p>
800<p>
801        When a and b are both small there is a distinct lack of information in the
802        literature on how to proceed. I am extremely grateful to Prof Nico Temme
803        who provided the following information with a great deal of patience and
804        explanation on his part. Any errors that follow are entirely my own, and
805        not Prof Temme's.
806      </p>
807<p>
808        When a and b are both less than 1, then there is a point of inflection in
809        the incomplete beta at point <code class="computeroutput"><span class="identifier">xs</span>
810        <span class="special">=</span> <span class="special">(</span><span class="number">1</span> <span class="special">-</span> <span class="identifier">a</span><span class="special">)</span> <span class="special">/</span> <span class="special">(</span><span class="number">2</span> <span class="special">-</span> <span class="identifier">a</span>
811        <span class="special">-</span> <span class="identifier">b</span><span class="special">)</span></code>. Therefore if <code class="literal">p &gt; I<sub>x</sub>(a,b)</code>
812        we swap a for b, p for q and x for y, so that now we always look for a point
813        x below the point of inflection <code class="computeroutput"><span class="identifier">xs</span></code>,
814        and on a convex curve. An initial estimate for x is made with:
815      </p>
816<div class="blockquote"><blockquote class="blockquote"><p>
817          <span class="inlinemediaobject"><img src="../../../equations/ibeta_inv7.svg"></span>
818
819        </p></blockquote></div>
820<p>
821        which is provably below the true value for x: <a href="http://en.wikipedia.org/wiki/Newton%27s_method" target="_top">Newton
822        iteration</a> will therefore smoothly converge on x without problems
823        caused by overshooting etc.
824      </p>
825<p>
826        When a and b are both greater than 1, but a+b is too small to use the other
827        methods mentioned above, we proceed as follows. Observe that there is a point
828        of inflection in the incomplete beta at <code class="computeroutput"><span class="identifier">xs</span>
829        <span class="special">=</span> <span class="special">(</span><span class="number">1</span> <span class="special">-</span> <span class="identifier">a</span><span class="special">)</span> <span class="special">/</span> <span class="special">(</span><span class="number">2</span> <span class="special">-</span> <span class="identifier">a</span>
830        <span class="special">-</span> <span class="identifier">b</span><span class="special">)</span></code>. Therefore if <code class="literal">p &gt; I<sub>x</sub>(a,b)</code>
831        we swap a for b, p for q and x for y, so that now we always look for a point
832        x below the point of inflection <code class="computeroutput"><span class="identifier">xs</span></code>,
833        and on a concave curve. An initial estimate for x is made with:
834      </p>
835<div class="blockquote"><blockquote class="blockquote"><p>
836          <span class="inlinemediaobject"><img src="../../../equations/ibeta_inv4.svg"></span>
837
838        </p></blockquote></div>
839<p>
840        which can be improved somewhat to:
841      </p>
842<div class="blockquote"><blockquote class="blockquote"><p>
843          <span class="inlinemediaobject"><img src="../../../equations/ibeta_inv1.svg"></span>
844
845        </p></blockquote></div>
846<p>
847        when b and x are both small (I've used b &lt; a and x &lt; 0.2). This actually
848        under-estimates x, which drops us on the wrong side of x for Newton iteration
849        to converge monotonically. However, use of higher derivatives and Halley
850        iteration keeps everything under control.
851      </p>
852<p>
853        The final case to be considered if when one of a and b is less than or equal
854        to 1, and the other greater that 1. Here, if b &lt; a we swap a for b, p
855        for q and x for y. Now the curve of the incomplete beta is convex with no
856        points of inflection in [0,1]. For small p, x can be estimated using
857      </p>
858<div class="blockquote"><blockquote class="blockquote"><p>
859          <span class="inlinemediaobject"><img src="../../../equations/ibeta_inv4.svg"></span>
860
861        </p></blockquote></div>
862<p>
863        which under-estimates x, and drops us on the right side of the true value
864        for Newton iteration to converge monotonically. However, when p is large
865        this can quite badly underestimate x. This is especially an issue when we
866        really want to find y, in which case this method can be an arbitrary number
867        of order of magnitudes out, leading to very poor convergence during iteration.
868      </p>
869<p>
870        Things can be improved by considering the incomplete beta as a distorted
871        quarter circle, and estimating y from:
872      </p>
873<div class="blockquote"><blockquote class="blockquote"><p>
874          <span class="inlinemediaobject"><img src="../../../equations/ibeta_inv8.svg"></span>
875
876        </p></blockquote></div>
877<p>
878        This doesn't guarantee that we will drop in on the right side of x for monotonic
879        convergence, but it does get us close enough that Halley iteration rapidly
880        converges on the true value.
881      </p>
882<h5>
883<a name="math_toolkit.sf_beta.ibeta_inv_function.h4"></a>
884        <span class="phrase"><a name="math_toolkit.sf_beta.ibeta_inv_function.implementation_of_inverses_on_th"></a></span><a class="link" href="ibeta_inv_function.html#math_toolkit.sf_beta.ibeta_inv_function.implementation_of_inverses_on_th">Implementation
885        of inverses on the a and b parameters</a>
886      </h5>
887<p>
888        These four functions share a common implementation.
889      </p>
890<p>
891        First an initial approximation is computed for <span class="emphasis"><em>a</em></span> or
892        <span class="emphasis"><em>b</em></span>: where possible this uses a Cornish-Fisher expansion
893        for the negative binomial distribution to get within around 1 of the result.
894        However, when <span class="emphasis"><em>a</em></span> or <span class="emphasis"><em>b</em></span> are very small
895        the Cornish Fisher expansion is not usable, in this case the initial approximation
896        is chosen so that I<sub>x</sub>(a, b) is near the middle of the range [0,1].
897      </p>
898<p>
899        This initial guess is then used as a starting value for a generic root finding
900        algorithm. The algorithm converges rapidly on the root once it has been bracketed,
901        but bracketing the root may take several iterations. A better initial approximation
902        for <span class="emphasis"><em>a</em></span> or <span class="emphasis"><em>b</em></span> would improve these
903        functions quite substantially: currently 10-20 incomplete beta function invocations
904        are required to find the root.
905      </p>
906</div>
907<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
908<td align="left"></td>
909<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
910      Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
911      Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
912      Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
913      Daryle Walker and Xiaogang Zhang<p>
914        Distributed under the Boost Software License, Version 1.0. (See accompanying
915        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>)
916      </p>
917</div></td>
918</tr></table>
919<hr>
920<div class="spirit-nav">
921<a accesskey="p" href="ibeta_function.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../sf_beta.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="beta_derivative.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
922</div>
923</body>
924</html>
925