]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <html> |
2 | <head> | |
3 | <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> | |
4 | <title>Estimating Sample Sizes for a 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="../binom_eg.html" title="Binomial Distribution Examples"> | |
9 | <link rel="prev" href="binom_conf.html" title="Calculating Confidence Limits on the Frequency of Occurrence for a Binomial Distribution"> | |
10 | <link rel="next" href="../geometric_eg.html" title="Geometric Distribution Examples"> | |
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="binom_conf.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../binom_eg.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="../geometric_eg.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> | |
24 | </div> | |
25 | <div class="section"> | |
26 | <div class="titlepage"><div><div><h5 class="title"> | |
27 | <a name="math_toolkit.stat_tut.weg.binom_eg.binom_size_eg"></a><a class="link" href="binom_size_eg.html" title="Estimating Sample Sizes for a Binomial Distribution.">Estimating | |
28 | Sample Sizes for a Binomial Distribution.</a> | |
29 | </h5></div></div></div> | |
30 | <p> | |
31 | Imagine you have a critical component that you know will fail in 1 in | |
32 | N "uses" (for some suitable definition of "use"). | |
33 | You may want to schedule routine replacement of the component so that | |
34 | its chance of failure between routine replacements is less than P%. If | |
35 | the failures follow a binomial distribution (each time the component | |
36 | is "used" it either fails or does not) then the static member | |
37 | function <code class="computeroutput"><span class="identifier">binomial_distibution</span><span class="special"><>::</span><span class="identifier">find_maximum_number_of_trials</span></code> | |
38 | can be used to estimate the maximum number of "uses" of that | |
39 | component for some acceptable risk level <span class="emphasis"><em>alpha</em></span>. | |
40 | </p> | |
41 | <p> | |
42 | The example program <a href="../../../../../../example/binomial_sample_sizes.cpp" target="_top">binomial_sample_sizes.cpp</a> | |
43 | demonstrates its usage. It centres on a routine that prints out a table | |
44 | of maximum sample sizes for various probability thresholds: | |
45 | </p> | |
46 | <pre class="programlisting"><span class="keyword">void</span> <span class="identifier">find_max_sample_size</span><span class="special">(</span> | |
47 | <span class="keyword">double</span> <span class="identifier">p</span><span class="special">,</span> <span class="comment">// success ratio.</span> | |
48 | <span class="keyword">unsigned</span> <span class="identifier">successes</span><span class="special">)</span> <span class="comment">// Total number of observed successes permitted.</span> | |
49 | <span class="special">{</span> | |
50 | </pre> | |
51 | <p> | |
52 | The routine then declares a table of probability thresholds: these are | |
53 | the maximum acceptable probability that <span class="emphasis"><em>successes</em></span> | |
54 | or fewer events will be observed. In our example, <span class="emphasis"><em>successes</em></span> | |
55 | will be always zero, since we want no component failures, but in other | |
56 | situations non-zero values may well make sense. | |
57 | </p> | |
58 | <pre class="programlisting"><span class="keyword">double</span> <span class="identifier">alpha</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">0.5</span><span class="special">,</span> <span class="number">0.25</span><span class="special">,</span> <span class="number">0.1</span><span class="special">,</span> <span class="number">0.05</span><span class="special">,</span> <span class="number">0.01</span><span class="special">,</span> <span class="number">0.001</span><span class="special">,</span> <span class="number">0.0001</span><span class="special">,</span> <span class="number">0.00001</span> <span class="special">};</span> | |
59 | </pre> | |
60 | <p> | |
61 | Much of the rest of the program is pretty-printing, the important part | |
62 | is in the calculation of maximum number of permitted trials for each | |
63 | value of alpha: | |
64 | </p> | |
65 | <pre class="programlisting"><span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">alpha</span><span class="special">)/</span><span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">alpha</span><span class="special">[</span><span class="number">0</span><span class="special">]);</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> | |
66 | <span class="special">{</span> | |
67 | <span class="comment">// Confidence value:</span> | |
68 | <span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">fixed</span> <span class="special"><<</span> <span class="identifier">setprecision</span><span class="special">(</span><span class="number">3</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">setw</span><span class="special">(</span><span class="number">10</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">right</span> <span class="special"><<</span> <span class="number">100</span> <span class="special">*</span> <span class="special">(</span><span class="number">1</span><span class="special">-</span><span class="identifier">alpha</span><span class="special">[</span><span class="identifier">i</span><span class="special">]);</span> | |
69 | <span class="comment">// calculate trials:</span> | |
70 | <span class="keyword">double</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">binomial</span><span class="special">::</span><span class="identifier">find_maximum_number_of_trials</span><span class="special">(</span> | |
71 | <span class="identifier">successes</span><span class="special">,</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">alpha</span><span class="special">[</span><span class="identifier">i</span><span class="special">]);</span> | |
72 | <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">floor</span><span class="special">(</span><span class="identifier">t</span><span class="special">);</span> | |
73 | <span class="comment">// Print Trials:</span> | |
74 | <span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">fixed</span> <span class="special"><<</span> <span class="identifier">setprecision</span><span class="special">(</span><span class="number">5</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">setw</span><span class="special">(</span><span class="number">15</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">right</span> <span class="special"><<</span> <span class="identifier">t</span> <span class="special"><<</span> <span class="identifier">endl</span><span class="special">;</span> | |
75 | <span class="special">}</span> | |
76 | </pre> | |
77 | <p> | |
78 | Note that since we're calculating the maximum number of trials permitted, | |
79 | we'll err on the safe side and take the floor of the result. Had we been | |
80 | calculating the <span class="emphasis"><em>minimum</em></span> number of trials required | |
81 | to observe a certain number of <span class="emphasis"><em>successes</em></span> using | |
82 | <code class="computeroutput"><span class="identifier">find_minimum_number_of_trials</span></code> | |
83 | we would have taken the ceiling instead. | |
84 | </p> | |
85 | <p> | |
86 | We'll finish off by looking at some sample output, firstly for a 1 in | |
87 | 1000 chance of component failure with each use: | |
88 | </p> | |
89 | <pre class="programlisting">________________________ | |
90 | Maximum Number of Trials | |
91 | ________________________ | |
92 | ||
93 | Success ratio = 0.001 | |
94 | Maximum Number of "successes" permitted = 0 | |
95 | ||
96 | ||
97 | ____________________________ | |
98 | Confidence Max Number | |
99 | Value (%) Of Trials | |
100 | ____________________________ | |
101 | 50.000 692 | |
102 | 75.000 287 | |
103 | 90.000 105 | |
104 | 95.000 51 | |
105 | 99.000 10 | |
106 | 99.900 0 | |
107 | 99.990 0 | |
108 | 99.999 0 | |
109 | </pre> | |
110 | <p> | |
111 | So 51 "uses" of the component would yield a 95% chance that | |
112 | no component failures would be observed. | |
113 | </p> | |
114 | <p> | |
115 | Compare that with a 1 in 1 million chance of component failure: | |
116 | </p> | |
117 | <pre class="programlisting">________________________ | |
118 | Maximum Number of Trials | |
119 | ________________________ | |
120 | ||
121 | Success ratio = 0.0000010 | |
122 | Maximum Number of "successes" permitted = 0 | |
123 | ||
124 | ||
125 | ____________________________ | |
126 | Confidence Max Number | |
127 | Value (%) Of Trials | |
128 | ____________________________ | |
129 | 50.000 693146 | |
130 | 75.000 287681 | |
131 | 90.000 105360 | |
132 | 95.000 51293 | |
133 | 99.000 10050 | |
134 | 99.900 1000 | |
135 | 99.990 100 | |
136 | 99.999 10 | |
137 | </pre> | |
138 | <p> | |
139 | In this case, even 1000 uses of the component would still yield a less | |
140 | than 1 in 1000 chance of observing a component failure (i.e. a 99.9% | |
141 | chance of no failure). | |
142 | </p> | |
143 | </div> | |
144 | <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> | |
145 | <td align="left"></td> | |
146 | <td align="right"><div class="copyright-footer">Copyright © 2006-2010, 2012-2014 Nikhar Agrawal, | |
147 | Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert | |
148 | Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan Råde, Gautam Sewani, | |
149 | Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p> | |
150 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
151 | 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>) | |
152 | </p> | |
153 | </div></td> | |
154 | </tr></table> | |
155 | <hr> | |
156 | <div class="spirit-nav"> | |
157 | <a accesskey="p" href="binom_conf.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../binom_eg.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="../geometric_eg.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> | |
158 | </div> | |
159 | </body> | |
160 | </html> |