]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <html> |
2 | <head> | |
3 | <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> | |
4 | <title>Binomial Distribution</title> | |
5 | <link rel="stylesheet" href="../../../math.css" type="text/css"> | |
6 | <meta name="generator" content="DocBook XSL Stylesheets V1.77.1"> | |
7 | <link rel="home" href="../../../index.html" title="Math Toolkit 2.5.1"> | |
8 | <link rel="up" href="../dists.html" title="Distributions"> | |
9 | <link rel="prev" href="beta_dist.html" title="Beta Distribution"> | |
10 | <link rel="next" href="cauchy_dist.html" title="Cauchy-Lorentz Distribution"> | |
11 | </head> | |
12 | <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> | |
13 | <table cellpadding="2" width="100%"><tr> | |
14 | <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> | |
15 | <td align="center"><a href="../../../../../../../index.html">Home</a></td> | |
16 | <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> | |
17 | <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> | |
18 | <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> | |
19 | <td align="center"><a href="../../../../../../../more/index.htm">More</a></td> | |
20 | </tr></table> | |
21 | <hr> | |
22 | <div class="spirit-nav"> | |
23 | <a accesskey="p" href="beta_dist.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="cauchy_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> | |
24 | </div> | |
25 | <div class="section"> | |
26 | <div class="titlepage"><div><div><h4 class="title"> | |
27 | <a name="math_toolkit.dist_ref.dists.binomial_dist"></a><a class="link" href="binomial_dist.html" title="Binomial Distribution">Binomial | |
28 | Distribution</a> | |
29 | </h4></div></div></div> | |
30 | <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">binomial</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></pre> | |
31 | <pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span> | |
32 | ||
33 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">RealType</span> <span class="special">=</span> <span class="keyword">double</span><span class="special">,</span> | |
34 | <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a> <span class="special">=</span> <a class="link" href="../../pol_ref/pol_ref_ref.html" title="Policy Class Reference">policies::policy<></a> <span class="special">></span> | |
35 | <span class="keyword">class</span> <span class="identifier">binomial_distribution</span><span class="special">;</span> | |
36 | ||
37 | <span class="keyword">typedef</span> <span class="identifier">binomial_distribution</span><span class="special"><></span> <span class="identifier">binomial</span><span class="special">;</span> | |
38 | ||
39 | <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">RealType</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 15. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> | |
40 | <span class="keyword">class</span> <span class="identifier">binomial_distribution</span> | |
41 | <span class="special">{</span> | |
42 | <span class="keyword">public</span><span class="special">:</span> | |
43 | <span class="keyword">typedef</span> <span class="identifier">RealType</span> <span class="identifier">value_type</span><span class="special">;</span> | |
44 | <span class="keyword">typedef</span> <span class="identifier">Policy</span> <span class="identifier">policy_type</span><span class="special">;</span> | |
45 | ||
46 | <span class="keyword">static</span> <span class="keyword">const</span> <span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">clopper_pearson_exact_interval</span><span class="special">;</span> | |
47 | <span class="keyword">static</span> <span class="keyword">const</span> <span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">jeffreys_prior_interval</span><span class="special">;</span> | |
48 | ||
49 | <span class="comment">// construct:</span> | |
50 | <span class="identifier">binomial_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span> | |
51 | ||
52 | <span class="comment">// parameter access::</span> | |
53 | <span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> | |
54 | <span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> | |
55 | ||
56 | <span class="comment">// Bounds on success fraction:</span> | |
57 | <span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_lower_bound_on_p</span><span class="special">(</span> | |
58 | <span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span> | |
59 | <span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span> | |
60 | <span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">,</span> | |
61 | <span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">method</span> <span class="special">=</span> <span class="identifier">clopper_pearson_exact_interval</span><span class="special">);</span> | |
62 | <span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_upper_bound_on_p</span><span class="special">(</span> | |
63 | <span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span> | |
64 | <span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span> | |
65 | <span class="identifier">RealType</span> <span class="identifier">probability</span><span class="special">,</span> | |
66 | <span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">method</span> <span class="special">=</span> <span class="identifier">clopper_pearson_exact_interval</span><span class="special">);</span> | |
67 | ||
68 | <span class="comment">// estimate min/max number of trials:</span> | |
69 | <span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_minimum_number_of_trials</span><span class="special">(</span> | |
70 | <span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of events</span> | |
71 | <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction</span> | |
72 | <span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// risk level</span> | |
73 | ||
74 | <span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span> | |
75 | <span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of events</span> | |
76 | <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction</span> | |
77 | <span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// risk level</span> | |
78 | <span class="special">};</span> | |
79 | ||
80 | <span class="special">}}</span> <span class="comment">// namespaces</span> | |
81 | </pre> | |
82 | <p> | |
83 | The class type <code class="computeroutput"><span class="identifier">binomial_distribution</span></code> | |
84 | represents a <a href="http://mathworld.wolfram.com/BinomialDistribution.html" target="_top">binomial | |
85 | distribution</a>: it is used when there are exactly two mutually exclusive | |
86 | outcomes of a trial. These outcomes are labelled "success" and | |
87 | "failure". The <a class="link" href="binomial_dist.html" title="Binomial Distribution">Binomial | |
88 | Distribution</a> is used to obtain the probability of observing k successes | |
89 | in N trials, with the probability of success on a single trial denoted | |
90 | by p. The binomial distribution assumes that p is fixed for all trials. | |
91 | </p> | |
92 | <div class="note"><table border="0" summary="Note"> | |
93 | <tr> | |
94 | <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td> | |
95 | <th align="left">Note</th> | |
96 | </tr> | |
97 | <tr><td align="left" valign="top"><p> | |
98 | The random variable for the binomial distribution is the number of successes, | |
99 | (the number of trials is a fixed property of the distribution) whereas | |
100 | for the negative binomial, the random variable is the number of trials, | |
101 | for a fixed number of successes. | |
102 | </p></td></tr> | |
103 | </table></div> | |
104 | <p> | |
105 | The PDF for the binomial distribution is given by: | |
106 | </p> | |
107 | <p> | |
108 | <span class="inlinemediaobject"><img src="../../../../equations/binomial_ref2.svg"></span> | |
109 | </p> | |
110 | <p> | |
111 | The following two graphs illustrate how the PDF changes depending upon | |
112 | the distributions parameters, first we'll keep the success fraction <span class="emphasis"><em>p</em></span> | |
113 | fixed at 0.5, and vary the sample size: | |
114 | </p> | |
115 | <p> | |
116 | <span class="inlinemediaobject"><img src="../../../../graphs/binomial_pdf_1.svg" align="middle"></span> | |
117 | </p> | |
118 | <p> | |
119 | Alternatively, we can keep the sample size fixed at N=20 and vary the success | |
120 | fraction <span class="emphasis"><em>p</em></span>: | |
121 | </p> | |
122 | <p> | |
123 | <span class="inlinemediaobject"><img src="../../../../graphs/binomial_pdf_2.svg" align="middle"></span> | |
124 | </p> | |
125 | <div class="caution"><table border="0" summary="Caution"> | |
126 | <tr> | |
127 | <td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../doc/src/images/caution.png"></td> | |
128 | <th align="left">Caution</th> | |
129 | </tr> | |
130 | <tr><td align="left" valign="top"> | |
131 | <p> | |
132 | The Binomial distribution is a discrete distribution: internally, functions | |
133 | like the <code class="computeroutput"><span class="identifier">cdf</span></code> and <code class="computeroutput"><span class="identifier">pdf</span></code> are treated "as if" they | |
134 | are continuous functions, but in reality the results returned from these | |
135 | functions only have meaning if an integer value is provided for the random | |
136 | variate argument. | |
137 | </p> | |
138 | <p> | |
139 | The quantile function will by default return an integer result that has | |
140 | been <span class="emphasis"><em>rounded outwards</em></span>. That is to say lower quantiles | |
141 | (where the probability is less than 0.5) are rounded downward, and upper | |
142 | quantiles (where the probability is greater than 0.5) are rounded upwards. | |
143 | This behaviour ensures that if an X% quantile is requested, then <span class="emphasis"><em>at | |
144 | least</em></span> the requested coverage will be present in the central | |
145 | region, and <span class="emphasis"><em>no more than</em></span> the requested coverage | |
146 | will be present in the tails. | |
147 | </p> | |
148 | <p> | |
149 | This behaviour can be changed so that the quantile functions are rounded | |
150 | differently, or even return a real-valued result using <a class="link" href="../../pol_overview.html" title="Policy Overview">Policies</a>. | |
151 | It is strongly recommended that you read the tutorial <a class="link" href="../../pol_tutorial/understand_dis_quant.html" title="Understanding Quantiles of Discrete Distributions">Understanding | |
152 | Quantiles of Discrete Distributions</a> before using the quantile | |
153 | function on the Binomial distribution. The <a class="link" href="../../pol_ref/discrete_quant_ref.html" title="Discrete Quantile Policies">reference | |
154 | docs</a> describe how to change the rounding policy for these distributions. | |
155 | </p> | |
156 | </td></tr> | |
157 | </table></div> | |
158 | <h5> | |
159 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h0"></a> | |
160 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.member_functions"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.member_functions">Member | |
161 | Functions</a> | |
162 | </h5> | |
163 | <h6> | |
164 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h1"></a> | |
165 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.construct"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.construct">Construct</a> | |
166 | </h6> | |
167 | <pre class="programlisting"><span class="identifier">binomial_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">n</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">);</span> | |
168 | </pre> | |
169 | <p> | |
170 | Constructor: <span class="emphasis"><em>n</em></span> is the total number of trials, <span class="emphasis"><em>p</em></span> | |
171 | is the probability of success of a single trial. | |
172 | </p> | |
173 | <p> | |
174 | Requires <code class="computeroutput"><span class="number">0</span> <span class="special"><=</span> | |
175 | <span class="identifier">p</span> <span class="special"><=</span> | |
176 | <span class="number">1</span></code>, and <code class="computeroutput"><span class="identifier">n</span> | |
177 | <span class="special">>=</span> <span class="number">0</span></code>, | |
178 | otherwise calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>. | |
179 | </p> | |
180 | <h6> | |
181 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h2"></a> | |
182 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.accessors"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.accessors">Accessors</a> | |
183 | </h6> | |
184 | <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">success_fraction</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> | |
185 | </pre> | |
186 | <p> | |
187 | Returns the parameter <span class="emphasis"><em>p</em></span> from which this distribution | |
188 | was constructed. | |
189 | </p> | |
190 | <pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> | |
191 | </pre> | |
192 | <p> | |
193 | Returns the parameter <span class="emphasis"><em>n</em></span> from which this distribution | |
194 | was constructed. | |
195 | </p> | |
196 | <h6> | |
197 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h3"></a> | |
198 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.lower_bound_on_the_success_fract"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.lower_bound_on_the_success_fract">Lower | |
199 | Bound on the Success Fraction</a> | |
200 | </h6> | |
201 | <pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_lower_bound_on_p</span><span class="special">(</span> | |
202 | <span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span> | |
203 | <span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span> | |
204 | <span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span> | |
205 | <span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">method</span> <span class="special">=</span> <span class="identifier">clopper_pearson_exact_interval</span><span class="special">);</span> | |
206 | </pre> | |
207 | <p> | |
208 | Returns a lower bound on the success fraction: | |
209 | </p> | |
210 | <div class="variablelist"> | |
211 | <p class="title"><b></b></p> | |
212 | <dl class="variablelist"> | |
213 | <dt><span class="term">trials</span></dt> | |
214 | <dd><p> | |
215 | The total number of trials conducted. | |
216 | </p></dd> | |
217 | <dt><span class="term">successes</span></dt> | |
218 | <dd><p> | |
219 | The number of successes that occurred. | |
220 | </p></dd> | |
221 | <dt><span class="term">alpha</span></dt> | |
222 | <dd><p> | |
223 | The largest acceptable probability that the true value of the success | |
224 | fraction is <span class="bold"><strong>less than</strong></span> the value | |
225 | returned. | |
226 | </p></dd> | |
227 | <dt><span class="term">method</span></dt> | |
228 | <dd><p> | |
229 | An optional parameter that specifies the method to be used to compute | |
230 | the interval (See below). | |
231 | </p></dd> | |
232 | </dl> | |
233 | </div> | |
234 | <p> | |
235 | For example, if you observe <span class="emphasis"><em>k</em></span> successes from <span class="emphasis"><em>n</em></span> | |
236 | trials the best estimate for the success fraction is simply <span class="emphasis"><em>k/n</em></span>, | |
237 | but if you want to be 95% sure that the true value is <span class="bold"><strong>greater | |
238 | than</strong></span> some value, <span class="emphasis"><em>p<sub>min</sub></em></span>, then: | |
239 | </p> | |
240 | <pre class="programlisting"><span class="identifier">p</span><sub>min</sub> <span class="special">=</span> <span class="identifier">binomial_distribution</span><span class="special"><</span><span class="identifier">RealType</span><span class="special">>::</span><span class="identifier">find_lower_bound_on_p</span><span class="special">(</span> | |
241 | <span class="identifier">n</span><span class="special">,</span> <span class="identifier">k</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span> | |
242 | </pre> | |
243 | <p> | |
244 | <a class="link" href="../../stat_tut/weg/binom_eg/binom_conf.html" title="Calculating Confidence Limits on the Frequency of Occurrence for a Binomial Distribution">See worked | |
245 | example.</a> | |
246 | </p> | |
247 | <p> | |
248 | There are currently two possible values available for the <span class="emphasis"><em>method</em></span> | |
249 | optional parameter: <span class="emphasis"><em>clopper_pearson_exact_interval</em></span> | |
250 | or <span class="emphasis"><em>jeffreys_prior_interval</em></span>. These constants are both | |
251 | members of class template <code class="computeroutput"><span class="identifier">binomial_distribution</span></code>, | |
252 | so usage is for example: | |
253 | </p> | |
254 | <pre class="programlisting"><span class="identifier">p</span> <span class="special">=</span> <span class="identifier">binomial_distribution</span><span class="special"><</span><span class="identifier">RealType</span><span class="special">>::</span><span class="identifier">find_lower_bound_on_p</span><span class="special">(</span> | |
255 | <span class="identifier">n</span><span class="special">,</span> <span class="identifier">k</span><span class="special">,</span> <span class="number">0.05</span><span class="special">,</span> <span class="identifier">binomial_distribution</span><span class="special"><</span><span class="identifier">RealType</span><span class="special">>::</span><span class="identifier">jeffreys_prior_interval</span><span class="special">);</span> | |
256 | </pre> | |
257 | <p> | |
258 | The default method if this parameter is not specified is the Clopper Pearson | |
259 | "exact" interval. This produces an interval that guarantees at | |
260 | least <code class="computeroutput"><span class="number">100</span><span class="special">(</span><span class="number">1</span><span class="special">-</span><span class="identifier">alpha</span><span class="special">)%</span></code> coverage, but which is known to be overly | |
261 | conservative, sometimes producing intervals with much greater than the | |
262 | requested coverage. | |
263 | </p> | |
264 | <p> | |
265 | The alternative calculation method produces a non-informative Jeffreys | |
266 | Prior interval. It produces <code class="computeroutput"><span class="number">100</span><span class="special">(</span><span class="number">1</span><span class="special">-</span><span class="identifier">alpha</span><span class="special">)%</span></code> | |
267 | coverage only <span class="emphasis"><em>in the average case</em></span>, though is typically | |
268 | very close to the requested coverage level. It is one of the main methods | |
269 | of calculation recommended in the review by Brown, Cai and DasGupta. | |
270 | </p> | |
271 | <p> | |
272 | Please note that the "textbook" calculation method using a normal | |
273 | approximation (the Wald interval) is deliberately not provided: it is known | |
274 | to produce consistently poor results, even when the sample size is surprisingly | |
275 | large. Refer to Brown, Cai and DasGupta for a full explanation. Many other | |
276 | methods of calculation are available, and may be more appropriate for specific | |
277 | situations. Unfortunately there appears to be no consensus amongst statisticians | |
278 | as to which is "best": refer to the discussion at the end of | |
279 | Brown, Cai and DasGupta for examples. | |
280 | </p> | |
281 | <p> | |
282 | The two methods provided here were chosen principally because they can | |
283 | be used for both one and two sided intervals. See also: | |
284 | </p> | |
285 | <p> | |
286 | Lawrence D. Brown, T. Tony Cai and Anirban DasGupta (2001), Interval Estimation | |
287 | for a Binomial Proportion, Statistical Science, Vol. 16, No. 2, 101-133. | |
288 | </p> | |
289 | <p> | |
290 | T. Tony Cai (2005), One-sided confidence intervals in discrete distributions, | |
291 | Journal of Statistical Planning and Inference 131, 63-88. | |
292 | </p> | |
293 | <p> | |
294 | Agresti, A. and Coull, B. A. (1998). Approximate is better than "exact" | |
295 | for interval estimation of binomial proportions. Amer. Statist. 52 119-126. | |
296 | </p> | |
297 | <p> | |
298 | Clopper, C. J. and Pearson, E. S. (1934). The use of confidence or fiducial | |
299 | limits illustrated in the case of the binomial. Biometrika 26 404-413. | |
300 | </p> | |
301 | <h6> | |
302 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h4"></a> | |
303 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.upper_bound_on_the_success_fract"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.upper_bound_on_the_success_fract">Upper | |
304 | Bound on the Success Fraction</a> | |
305 | </h6> | |
306 | <pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_upper_bound_on_p</span><span class="special">(</span> | |
307 | <span class="identifier">RealType</span> <span class="identifier">trials</span><span class="special">,</span> | |
308 | <span class="identifier">RealType</span> <span class="identifier">successes</span><span class="special">,</span> | |
309 | <span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">,</span> | |
310 | <span class="emphasis"><em>unspecified-type</em></span> <span class="identifier">method</span> <span class="special">=</span> <span class="identifier">clopper_pearson_exact_interval</span><span class="special">);</span> | |
311 | </pre> | |
312 | <p> | |
313 | Returns an upper bound on the success fraction: | |
314 | </p> | |
315 | <div class="variablelist"> | |
316 | <p class="title"><b></b></p> | |
317 | <dl class="variablelist"> | |
318 | <dt><span class="term">trials</span></dt> | |
319 | <dd><p> | |
320 | The total number of trials conducted. | |
321 | </p></dd> | |
322 | <dt><span class="term">successes</span></dt> | |
323 | <dd><p> | |
324 | The number of successes that occurred. | |
325 | </p></dd> | |
326 | <dt><span class="term">alpha</span></dt> | |
327 | <dd><p> | |
328 | The largest acceptable probability that the true value of the success | |
329 | fraction is <span class="bold"><strong>greater than</strong></span> the value | |
330 | returned. | |
331 | </p></dd> | |
332 | <dt><span class="term">method</span></dt> | |
333 | <dd><p> | |
334 | An optional parameter that specifies the method to be used to compute | |
335 | the interval. Refer to the documentation for <code class="computeroutput"><span class="identifier">find_upper_bound_on_p</span></code> | |
336 | above for the meaning of the method options. | |
337 | </p></dd> | |
338 | </dl> | |
339 | </div> | |
340 | <p> | |
341 | For example, if you observe <span class="emphasis"><em>k</em></span> successes from <span class="emphasis"><em>n</em></span> | |
342 | trials the best estimate for the success fraction is simply <span class="emphasis"><em>k/n</em></span>, | |
343 | but if you want to be 95% sure that the true value is <span class="bold"><strong>less | |
344 | than</strong></span> some value, <span class="emphasis"><em>p<sub>max</sub></em></span>, then: | |
345 | </p> | |
346 | <pre class="programlisting"><span class="identifier">p</span><sub>max</sub> <span class="special">=</span> <span class="identifier">binomial_distribution</span><span class="special"><</span><span class="identifier">RealType</span><span class="special">>::</span><span class="identifier">find_upper_bound_on_p</span><span class="special">(</span> | |
347 | <span class="identifier">n</span><span class="special">,</span> <span class="identifier">k</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span> | |
348 | </pre> | |
349 | <p> | |
350 | <a class="link" href="../../stat_tut/weg/binom_eg/binom_conf.html" title="Calculating Confidence Limits on the Frequency of Occurrence for a Binomial Distribution">See worked | |
351 | example.</a> | |
352 | </p> | |
353 | <div class="note"><table border="0" summary="Note"> | |
354 | <tr> | |
355 | <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td> | |
356 | <th align="left">Note</th> | |
357 | </tr> | |
358 | <tr><td align="left" valign="top"> | |
359 | <p> | |
360 | In order to obtain a two sided bound on the success fraction, you call | |
361 | both <code class="computeroutput"><span class="identifier">find_lower_bound_on_p</span></code> | |
362 | <span class="bold"><strong>and</strong></span> <code class="computeroutput"><span class="identifier">find_upper_bound_on_p</span></code> | |
363 | each with the same arguments. | |
364 | </p> | |
365 | <p> | |
366 | If the desired risk level that the true success fraction lies outside | |
367 | the bounds is α, then you pass α/2 to these functions. | |
368 | </p> | |
369 | <p> | |
370 | So for example a two sided 95% confidence interval would be obtained | |
371 | by passing α = 0.025 to each of the functions. | |
372 | </p> | |
373 | <p> | |
374 | <a class="link" href="../../stat_tut/weg/binom_eg/binom_conf.html" title="Calculating Confidence Limits on the Frequency of Occurrence for a Binomial Distribution">See worked | |
375 | example.</a> | |
376 | </p> | |
377 | </td></tr> | |
378 | </table></div> | |
379 | <h6> | |
380 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h5"></a> | |
381 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.estimating_the_number_of_trials_"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.estimating_the_number_of_trials_">Estimating | |
382 | the Number of Trials Required for a Certain Number of Successes</a> | |
383 | </h6> | |
384 | <pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_minimum_number_of_trials</span><span class="special">(</span> | |
385 | <span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of events</span> | |
386 | <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction</span> | |
387 | <span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// probability threshold</span> | |
388 | </pre> | |
389 | <p> | |
390 | This function estimates the minimum number of trials required to ensure | |
391 | that more than k events is observed with a level of risk <span class="emphasis"><em>alpha</em></span> | |
392 | that k or fewer events occur. | |
393 | </p> | |
394 | <div class="variablelist"> | |
395 | <p class="title"><b></b></p> | |
396 | <dl class="variablelist"> | |
397 | <dt><span class="term">k</span></dt> | |
398 | <dd><p> | |
399 | The number of success observed. | |
400 | </p></dd> | |
401 | <dt><span class="term">p</span></dt> | |
402 | <dd><p> | |
403 | The probability of success for each trial. | |
404 | </p></dd> | |
405 | <dt><span class="term">alpha</span></dt> | |
406 | <dd><p> | |
407 | The maximum acceptable probability that k events or fewer will be | |
408 | observed. | |
409 | </p></dd> | |
410 | </dl> | |
411 | </div> | |
412 | <p> | |
413 | For example: | |
414 | </p> | |
415 | <pre class="programlisting"><span class="identifier">binomial_distribution</span><span class="special"><</span><span class="identifier">RealType</span><span class="special">>::</span><span class="identifier">find_number_of_trials</span><span class="special">(</span><span class="number">10</span><span class="special">,</span> <span class="number">0.5</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span> | |
416 | </pre> | |
417 | <p> | |
418 | Returns the smallest number of trials we must conduct to be 95% sure of | |
419 | seeing 10 events that occur with frequency one half. | |
420 | </p> | |
421 | <h6> | |
422 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h6"></a> | |
423 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.estimating_the_maximum_number_of"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.estimating_the_maximum_number_of">Estimating | |
424 | the Maximum Number of Trials to Ensure no more than a Certain Number of | |
425 | Successes</a> | |
426 | </h6> | |
427 | <pre class="programlisting"><span class="keyword">static</span> <span class="identifier">RealType</span> <span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span> | |
428 | <span class="identifier">RealType</span> <span class="identifier">k</span><span class="special">,</span> <span class="comment">// number of events</span> | |
429 | <span class="identifier">RealType</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success fraction</span> | |
430 | <span class="identifier">RealType</span> <span class="identifier">alpha</span><span class="special">);</span> <span class="comment">// probability threshold</span> | |
431 | </pre> | |
432 | <p> | |
433 | This function estimates the maximum number of trials we can conduct to | |
434 | ensure that k successes or fewer are observed, with a risk <span class="emphasis"><em>alpha</em></span> | |
435 | that more than k occur. | |
436 | </p> | |
437 | <div class="variablelist"> | |
438 | <p class="title"><b></b></p> | |
439 | <dl class="variablelist"> | |
440 | <dt><span class="term">k</span></dt> | |
441 | <dd><p> | |
442 | The number of success observed. | |
443 | </p></dd> | |
444 | <dt><span class="term">p</span></dt> | |
445 | <dd><p> | |
446 | The probability of success for each trial. | |
447 | </p></dd> | |
448 | <dt><span class="term">alpha</span></dt> | |
449 | <dd><p> | |
450 | The maximum acceptable probability that more than k events will be | |
451 | observed. | |
452 | </p></dd> | |
453 | </dl> | |
454 | </div> | |
455 | <p> | |
456 | For example: | |
457 | </p> | |
458 | <pre class="programlisting"><span class="identifier">binomial_distribution</span><span class="special"><</span><span class="identifier">RealType</span><span class="special">>::</span><span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span><span class="number">0</span><span class="special">,</span> <span class="number">1e-6</span><span class="special">,</span> <span class="number">0.05</span><span class="special">);</span> | |
459 | </pre> | |
460 | <p> | |
461 | Returns the largest number of trials we can conduct and still be 95% certain | |
462 | of not observing any events that occur with one in a million frequency. | |
463 | This is typically used in failure analysis. | |
464 | </p> | |
465 | <p> | |
466 | <a class="link" href="../../stat_tut/weg/binom_eg/binom_size_eg.html" title="Estimating Sample Sizes for a Binomial Distribution.">See Worked | |
467 | Example.</a> | |
468 | </p> | |
469 | <h5> | |
470 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h7"></a> | |
471 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.non_member_accessors"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.non_member_accessors">Non-member | |
472 | Accessors</a> | |
473 | </h5> | |
474 | <p> | |
475 | All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor | |
476 | functions</a> that are generic to all distributions are supported: | |
477 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>, | |
478 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>, | |
479 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.hazard">Hazard Function</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.chf">Cumulative Hazard Function</a>, | |
480 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mean">mean</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.median">median</a>, | |
481 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mode">mode</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.variance">variance</a>, | |
482 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>, | |
483 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.skewness">skewness</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis">kurtosis</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess">kurtosis_excess</a>, | |
484 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.range">range</a> and <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.support">support</a>. | |
485 | </p> | |
486 | <p> | |
487 | The domain for the random variable <span class="emphasis"><em>k</em></span> is <code class="computeroutput"><span class="number">0</span> <span class="special"><=</span> <span class="identifier">k</span> <span class="special"><=</span> <span class="identifier">N</span></code>, otherwise a <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a> | |
488 | is returned. | |
489 | </p> | |
490 | <p> | |
491 | It's worth taking a moment to define what these accessors actually mean | |
492 | in the context of this distribution: | |
493 | </p> | |
494 | <div class="table"> | |
495 | <a name="math_toolkit.dist_ref.dists.binomial_dist.meaning_of_the_non_member_access"></a><p class="title"><b>Table 5.1. Meaning of the non-member accessors</b></p> | |
496 | <div class="table-contents"><table class="table" summary="Meaning of the non-member accessors"> | |
497 | <colgroup> | |
498 | <col> | |
499 | <col> | |
500 | </colgroup> | |
501 | <thead><tr> | |
502 | <th> | |
503 | <p> | |
504 | Function | |
505 | </p> | |
506 | </th> | |
507 | <th> | |
508 | <p> | |
509 | Meaning | |
510 | </p> | |
511 | </th> | |
512 | </tr></thead> | |
513 | <tbody> | |
514 | <tr> | |
515 | <td> | |
516 | <p> | |
517 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density | |
518 | Function</a> | |
519 | </p> | |
520 | </td> | |
521 | <td> | |
522 | <p> | |
523 | The probability of obtaining <span class="bold"><strong>exactly k | |
524 | successes</strong></span> from n trials with success fraction p. For | |
525 | example: | |
526 | </p> | |
527 | <p> | |
528 | <code class="computeroutput"><span class="identifier">pdf</span><span class="special">(</span><span class="identifier">binomial</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span> | |
529 | <span class="identifier">p</span><span class="special">),</span> | |
530 | <span class="identifier">k</span><span class="special">)</span></code> | |
531 | </p> | |
532 | </td> | |
533 | </tr> | |
534 | <tr> | |
535 | <td> | |
536 | <p> | |
537 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution | |
538 | Function</a> | |
539 | </p> | |
540 | </td> | |
541 | <td> | |
542 | <p> | |
543 | The probability of obtaining <span class="bold"><strong>k successes | |
544 | or fewer</strong></span> from n trials with success fraction p. For | |
545 | example: | |
546 | </p> | |
547 | <p> | |
548 | <code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">binomial</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span> | |
549 | <span class="identifier">p</span><span class="special">),</span> | |
550 | <span class="identifier">k</span><span class="special">)</span></code> | |
551 | </p> | |
552 | </td> | |
553 | </tr> | |
554 | <tr> | |
555 | <td> | |
556 | <p> | |
557 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.ccdf">Complement of | |
558 | the Cumulative Distribution Function</a> | |
559 | </p> | |
560 | </td> | |
561 | <td> | |
562 | <p> | |
563 | The probability of obtaining <span class="bold"><strong>more than | |
564 | k successes</strong></span> from n trials with success fraction p. | |
565 | For example: | |
566 | </p> | |
567 | <p> | |
568 | <code class="computeroutput"><span class="identifier">cdf</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">binomial</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span> | |
569 | <span class="identifier">p</span><span class="special">),</span> | |
570 | <span class="identifier">k</span><span class="special">))</span></code> | |
571 | </p> | |
572 | </td> | |
573 | </tr> | |
574 | <tr> | |
575 | <td> | |
576 | <p> | |
577 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a> | |
578 | </p> | |
579 | </td> | |
580 | <td> | |
581 | <p> | |
582 | The <span class="bold"><strong>greatest</strong></span> number of successes | |
583 | that may be observed from n trials with success fraction p, at | |
584 | probability P. Note that the value returned is a real-number, | |
585 | and not an integer. Depending on the use case you may want to | |
586 | take either the floor or ceiling of the result. For example: | |
587 | </p> | |
588 | <p> | |
589 | <code class="computeroutput"><span class="identifier">quantile</span><span class="special">(</span><span class="identifier">binomial</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span> | |
590 | <span class="identifier">p</span><span class="special">),</span> | |
591 | <span class="identifier">P</span><span class="special">)</span></code> | |
592 | </p> | |
593 | </td> | |
594 | </tr> | |
595 | <tr> | |
596 | <td> | |
597 | <p> | |
598 | <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile_c">Quantile | |
599 | from the complement of the probability</a> | |
600 | </p> | |
601 | </td> | |
602 | <td> | |
603 | <p> | |
604 | The <span class="bold"><strong>smallest</strong></span> number of successes | |
605 | that may be observed from n trials with success fraction p, at | |
606 | probability P. Note that the value returned is a real-number, | |
607 | and not an integer. Depending on the use case you may want to | |
608 | take either the floor or ceiling of the result. For example: | |
609 | </p> | |
610 | <p> | |
611 | <code class="computeroutput"><span class="identifier">quantile</span><span class="special">(</span><span class="identifier">complement</span><span class="special">(</span><span class="identifier">binomial</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span> | |
612 | <span class="identifier">p</span><span class="special">),</span> | |
613 | <span class="identifier">P</span><span class="special">))</span></code> | |
614 | </p> | |
615 | </td> | |
616 | </tr> | |
617 | </tbody> | |
618 | </table></div> | |
619 | </div> | |
620 | <br class="table-break"><h5> | |
621 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h8"></a> | |
622 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.examples"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.examples">Examples</a> | |
623 | </h5> | |
624 | <p> | |
625 | Various <a class="link" href="../../stat_tut/weg/binom_eg.html" title="Binomial Distribution Examples">worked examples</a> | |
626 | are available illustrating the use of the binomial distribution. | |
627 | </p> | |
628 | <h5> | |
629 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h9"></a> | |
630 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.accuracy"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.accuracy">Accuracy</a> | |
631 | </h5> | |
632 | <p> | |
633 | This distribution is implemented using the incomplete beta functions <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a> and <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a>, | |
634 | please refer to these functions for information on accuracy. | |
635 | </p> | |
636 | <h5> | |
637 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h10"></a> | |
638 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.implementation"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.implementation">Implementation</a> | |
639 | </h5> | |
640 | <p> | |
641 | In the following table <span class="emphasis"><em>p</em></span> is the probability that one | |
642 | trial will be successful (the success fraction), <span class="emphasis"><em>n</em></span> | |
643 | is the number of trials, <span class="emphasis"><em>k</em></span> is the number of successes, | |
644 | <span class="emphasis"><em>p</em></span> is the probability and <span class="emphasis"><em>q = 1-p</em></span>. | |
645 | </p> | |
646 | <div class="informaltable"><table class="table"> | |
647 | <colgroup> | |
648 | <col> | |
649 | <col> | |
650 | </colgroup> | |
651 | <thead><tr> | |
652 | <th> | |
653 | <p> | |
654 | Function | |
655 | </p> | |
656 | </th> | |
657 | <th> | |
658 | <p> | |
659 | Implementation Notes | |
660 | </p> | |
661 | </th> | |
662 | </tr></thead> | |
663 | <tbody> | |
664 | <tr> | |
665 | <td> | |
666 | <p> | |
667 | ||
668 | </p> | |
669 | </td> | |
670 | <td> | |
671 | <p> | |
672 | Implementation is in terms of <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a>: | |
673 | if <sub>n</sub>C<sub>k </sub> is the binomial coefficient of a and b, then we have: | |
674 | </p> | |
675 | <p> | |
676 | <span class="inlinemediaobject"><img src="../../../../equations/binomial_ref1.svg"></span> | |
677 | </p> | |
678 | <p> | |
679 | Which can be evaluated as <code class="computeroutput"><span class="identifier">ibeta_derivative</span><span class="special">(</span><span class="identifier">k</span><span class="special">+</span><span class="number">1</span><span class="special">,</span> <span class="identifier">n</span><span class="special">-</span><span class="identifier">k</span><span class="special">+</span><span class="number">1</span><span class="special">,</span> <span class="identifier">p</span><span class="special">)</span> <span class="special">/</span> | |
680 | <span class="special">(</span><span class="identifier">n</span><span class="special">+</span><span class="number">1</span><span class="special">)</span></code> | |
681 | </p> | |
682 | <p> | |
683 | The function <a class="link" href="../../sf_beta/beta_derivative.html" title="Derivative of the Incomplete Beta Function">ibeta_derivative</a> | |
684 | is used here, since it has already been optimised for the lowest | |
685 | possible error - indeed this is really just a thin wrapper around | |
686 | part of the internals of the incomplete beta function. | |
687 | </p> | |
688 | <p> | |
689 | There are also various special cases: refer to the code for details. | |
690 | </p> | |
691 | </td> | |
692 | </tr> | |
693 | <tr> | |
694 | <td> | |
695 | <p> | |
696 | cdf | |
697 | </p> | |
698 | </td> | |
699 | <td> | |
700 | <p> | |
701 | Using the relation: | |
702 | </p> | |
703 | <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">p</span> <span class="special">=</span> <span class="identifier">I</span><span class="special">[</span><span class="identifier">sub</span> <span class="number">1</span><span class="special">-</span><span class="identifier">p</span><span class="special">](</span><span class="identifier">n</span> <span class="special">-</span> <span class="identifier">k</span><span class="special">,</span> <span class="identifier">k</span> <span class="special">+</span> <span class="number">1</span><span class="special">)</span> | |
704 | <span class="special">=</span> <span class="number">1</span> <span class="special">-</span> <span class="identifier">I</span><span class="special">[</span><span class="identifier">sub</span> <span class="identifier">p</span><span class="special">](</span><span class="identifier">k</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">n</span> <span class="special">-</span> <span class="identifier">k</span><span class="special">)</span> | |
705 | <span class="special">=</span> <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibetac</a><span class="special">(</span><span class="identifier">k</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">n</span> <span class="special">-</span> <span class="identifier">k</span><span class="special">,</span> <span class="identifier">p</span><span class="special">)</span></pre> | |
706 | <p> | |
707 | There are also various special cases: refer to the code for details. | |
708 | </p> | |
709 | </td> | |
710 | </tr> | |
711 | <tr> | |
712 | <td> | |
713 | <p> | |
714 | cdf complement | |
715 | </p> | |
716 | </td> | |
717 | <td> | |
718 | <p> | |
719 | Using the relation: q = <a class="link" href="../../sf_beta/ibeta_function.html" title="Incomplete Beta Functions">ibeta</a>(k | |
720 | + 1, n - k, p) | |
721 | </p> | |
722 | <p> | |
723 | There are also various special cases: refer to the code for details. | |
724 | </p> | |
725 | </td> | |
726 | </tr> | |
727 | <tr> | |
728 | <td> | |
729 | <p> | |
730 | quantile | |
731 | </p> | |
732 | </td> | |
733 | <td> | |
734 | <p> | |
735 | Since the cdf is non-linear in variate <span class="emphasis"><em>k</em></span> | |
736 | none of the inverse incomplete beta functions can be used here. | |
737 | Instead the quantile is found numerically using a derivative | |
738 | free method (<a class="link" href="../../roots/roots_noderiv/TOMS748.html" title="Algorithm TOMS 748: Alefeld, Potra and Shi: Enclosing zeros of continuous functions">TOMS | |
739 | 748 algorithm</a>). | |
740 | </p> | |
741 | </td> | |
742 | </tr> | |
743 | <tr> | |
744 | <td> | |
745 | <p> | |
746 | quantile from the complement | |
747 | </p> | |
748 | </td> | |
749 | <td> | |
750 | <p> | |
751 | Found numerically as above. | |
752 | </p> | |
753 | </td> | |
754 | </tr> | |
755 | <tr> | |
756 | <td> | |
757 | <p> | |
758 | mean | |
759 | </p> | |
760 | </td> | |
761 | <td> | |
762 | <p> | |
763 | <code class="computeroutput"><span class="identifier">p</span> <span class="special">*</span> | |
764 | <span class="identifier">n</span></code> | |
765 | </p> | |
766 | </td> | |
767 | </tr> | |
768 | <tr> | |
769 | <td> | |
770 | <p> | |
771 | variance | |
772 | </p> | |
773 | </td> | |
774 | <td> | |
775 | <p> | |
776 | <code class="computeroutput"><span class="identifier">p</span> <span class="special">*</span> | |
777 | <span class="identifier">n</span> <span class="special">*</span> | |
778 | <span class="special">(</span><span class="number">1</span><span class="special">-</span><span class="identifier">p</span><span class="special">)</span></code> | |
779 | </p> | |
780 | </td> | |
781 | </tr> | |
782 | <tr> | |
783 | <td> | |
784 | <p> | |
785 | mode | |
786 | </p> | |
787 | </td> | |
788 | <td> | |
789 | <p> | |
790 | <code class="computeroutput"><span class="identifier">floor</span><span class="special">(</span><span class="identifier">p</span> <span class="special">*</span> | |
791 | <span class="special">(</span><span class="identifier">n</span> | |
792 | <span class="special">+</span> <span class="number">1</span><span class="special">))</span></code> | |
793 | </p> | |
794 | </td> | |
795 | </tr> | |
796 | <tr> | |
797 | <td> | |
798 | <p> | |
799 | skewness | |
800 | </p> | |
801 | </td> | |
802 | <td> | |
803 | <p> | |
804 | <code class="computeroutput"><span class="special">(</span><span class="number">1</span> | |
805 | <span class="special">-</span> <span class="number">2</span> | |
806 | <span class="special">*</span> <span class="identifier">p</span><span class="special">)</span> <span class="special">/</span> | |
807 | <span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">n</span> <span class="special">*</span> | |
808 | <span class="identifier">p</span> <span class="special">*</span> | |
809 | <span class="special">(</span><span class="number">1</span> | |
810 | <span class="special">-</span> <span class="identifier">p</span><span class="special">))</span></code> | |
811 | </p> | |
812 | </td> | |
813 | </tr> | |
814 | <tr> | |
815 | <td> | |
816 | <p> | |
817 | kurtosis | |
818 | </p> | |
819 | </td> | |
820 | <td> | |
821 | <p> | |
822 | <code class="computeroutput"><span class="number">3</span> <span class="special">-</span> | |
823 | <span class="special">(</span><span class="number">6</span> | |
824 | <span class="special">/</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">+</span> | |
825 | <span class="special">(</span><span class="number">1</span> | |
826 | <span class="special">/</span> <span class="special">(</span><span class="identifier">n</span> <span class="special">*</span> | |
827 | <span class="identifier">p</span> <span class="special">*</span> | |
828 | <span class="special">(</span><span class="number">1</span> | |
829 | <span class="special">-</span> <span class="identifier">p</span><span class="special">)))</span></code> | |
830 | </p> | |
831 | </td> | |
832 | </tr> | |
833 | <tr> | |
834 | <td> | |
835 | <p> | |
836 | kurtosis excess | |
837 | </p> | |
838 | </td> | |
839 | <td> | |
840 | <p> | |
841 | <code class="computeroutput"><span class="special">(</span><span class="number">1</span> | |
842 | <span class="special">-</span> <span class="number">6</span> | |
843 | <span class="special">*</span> <span class="identifier">p</span> | |
844 | <span class="special">*</span> <span class="identifier">q</span><span class="special">)</span> <span class="special">/</span> | |
845 | <span class="special">(</span><span class="identifier">n</span> | |
846 | <span class="special">*</span> <span class="identifier">p</span> | |
847 | <span class="special">*</span> <span class="identifier">q</span><span class="special">)</span></code> | |
848 | </p> | |
849 | </td> | |
850 | </tr> | |
851 | <tr> | |
852 | <td> | |
853 | <p> | |
854 | parameter estimation | |
855 | </p> | |
856 | </td> | |
857 | <td> | |
858 | <p> | |
859 | The member functions <code class="computeroutput"><span class="identifier">find_upper_bound_on_p</span></code> | |
860 | <code class="computeroutput"><span class="identifier">find_lower_bound_on_p</span></code> | |
861 | and <code class="computeroutput"><span class="identifier">find_number_of_trials</span></code> | |
862 | are implemented in terms of the inverse incomplete beta functions | |
863 | <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibetac_inv</a>, | |
864 | <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibeta_inv</a>, | |
865 | and <a class="link" href="../../sf_beta/ibeta_inv_function.html" title="The Incomplete Beta Function Inverses">ibetac_invb</a> | |
866 | respectively | |
867 | </p> | |
868 | </td> | |
869 | </tr> | |
870 | </tbody> | |
871 | </table></div> | |
872 | <h5> | |
873 | <a name="math_toolkit.dist_ref.dists.binomial_dist.h11"></a> | |
874 | <span class="phrase"><a name="math_toolkit.dist_ref.dists.binomial_dist.references"></a></span><a class="link" href="binomial_dist.html#math_toolkit.dist_ref.dists.binomial_dist.references">References</a> | |
875 | </h5> | |
876 | <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> | |
877 | <li class="listitem"> | |
878 | <a href="http://mathworld.wolfram.com/BinomialDistribution.html" target="_top">Weisstein, | |
879 | Eric W. "Binomial Distribution." From MathWorld--A Wolfram | |
880 | Web Resource</a>. | |
881 | </li> | |
882 | <li class="listitem"> | |
883 | <a href="http://en.wikipedia.org/wiki/Beta_distribution" target="_top">Wikipedia | |
884 | binomial distribution</a>. | |
885 | </li> | |
886 | <li class="listitem"> | |
887 | <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda366i.htm" target="_top">NIST | |
888 | Explorary Data Analysis</a>. | |
889 | </li> | |
890 | </ul></div> | |
891 | </div> | |
892 | <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> | |
893 | <td align="left"></td> | |
894 | <td align="right"><div class="copyright-footer">Copyright © 2006-2010, 2012-2014 Nikhar Agrawal, | |
895 | Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert | |
896 | Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan Råde, Gautam Sewani, | |
897 | Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p> | |
898 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
899 | 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>) | |
900 | </p> | |
901 | </div></td> | |
902 | </tr></table> | |
903 | <hr> | |
904 | <div class="spirit-nav"> | |
905 | <a accesskey="p" href="beta_dist.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="cauchy_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> | |
906 | </div> | |
907 | </body> | |
908 | </html> |