| <!DOCTYPE HTML> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc --> |
| <title>BoundsOnBinomialProportions (datasketches-java 4.0.0 API)</title> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style"> |
| <link rel="stylesheet" type="text/css" href="../../../../jquery/jquery-ui.min.css" title="Style"> |
| <link rel="stylesheet" type="text/css" href="../../../../jquery-ui.overrides.css" title="Style"> |
| <script type="text/javascript" src="../../../../script.js"></script> |
| <script type="text/javascript" src="../../../../jquery/jszip/dist/jszip.min.js"></script> |
| <script type="text/javascript" src="../../../../jquery/jszip-utils/dist/jszip-utils.min.js"></script> |
| <!--[if IE]> |
| <script type="text/javascript" src="../../../../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script> |
| <![endif]--> |
| <script type="text/javascript" src="../../../../jquery/jquery-3.6.0.min.js"></script> |
| <script type="text/javascript" src="../../../../jquery/jquery-ui.min.js"></script> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| try { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="BoundsOnBinomialProportions (datasketches-java 4.0.0 API)"; |
| } |
| } |
| catch(err) { |
| } |
| //--> |
| var data = {"i0":9,"i1":9,"i2":9,"i3":9,"i4":9}; |
| var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],8:["t4","Concrete Methods"]}; |
| var altColor = "altColor"; |
| var rowColor = "rowColor"; |
| var tableTab = "tableTab"; |
| var activeTableTab = "activeTableTab"; |
| var pathtoroot = "../../../../"; |
| var useModuleDirectories = true; |
| loadScripts(document, 'script');</script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <header role="banner"> |
| <nav role="navigation"> |
| <div class="fixedNav"> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a id="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <a id="navbar.top.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../index.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="class-use/BoundsOnBinomialProportions.html">Use</a></li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../../allclasses.html">All Classes</a></li> |
| </ul> |
| <ul class="navListSearch"> |
| <li><label for="search">SEARCH:</label> |
| <input type="text" id="search" value="search" disabled="disabled"> |
| <input type="reset" id="reset" value="reset" disabled="disabled"> |
| </li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_top"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Nested | </li> |
| <li>Field | </li> |
| <li>Constr | </li> |
| <li><a href="#method.summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li>Constr | </li> |
| <li><a href="#method.detail">Method</a></li> |
| </ul> |
| </div> |
| <a id="skip.navbar.top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| </div> |
| <div class="navPadding"> </div> |
| <script type="text/javascript"><!-- |
| $('.navPadding').css('padding-top', $('.fixedNav').css("height")); |
| //--> |
| </script> |
| </nav> |
| </header> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <main role="main"> |
| <div class="header"> |
| <div class="subTitle"><span class="packageLabelInType">Package</span> <a href="package-summary.html">org.apache.datasketches.common</a></div> |
| <h2 title="Class BoundsOnBinomialProportions" class="title">Class BoundsOnBinomialProportions</h2> |
| </div> |
| <div class="contentContainer"> |
| <ul class="inheritance"> |
| <li><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">java.lang.Object</a></li> |
| <li> |
| <ul class="inheritance"> |
| <li>org.apache.datasketches.common.BoundsOnBinomialProportions</li> |
| </ul> |
| </li> |
| </ul> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <hr> |
| <pre>public final class <span class="typeNameLabel">BoundsOnBinomialProportions</span> |
| extends <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">Object</a></pre> |
| <div class="block">Confidence intervals for binomial proportions. |
| |
| <p>This class computes an approximation to the Clopper-Pearson confidence interval |
| for a binomial proportion. Exact Clopper-Pearson intervals are strictly |
| conservative, but these approximations are not.</p> |
| |
| <p>The main inputs are numbers <i>n</i> and <i>k</i>, which are not the same as other things |
| that are called <i>n</i> and <i>k</i> in our sketching library. There is also a third |
| parameter, numStdDev, that specifies the desired confidence level.</p> |
| <ul> |
| <li><i>n</i> is the number of independent randomized trials. It is given and therefore known.</li> |
| <li><i>p</i> is the probability of a trial being a success. It is unknown.</li> |
| <li><i>k</i> is the number of trials (out of <i>n</i>) that turn out to be successes. It is |
| a random variable governed by a binomial distribution. After any given |
| batch of <i>n</i> independent trials, the random variable <i>k</i> has a specific |
| value which is observed and is therefore known.</li> |
| <li><i>pHat</i> = <i>k</i> / <i>n</i> is an unbiased estimate of the unknown success |
| probability <i>p</i>.</li> |
| </ul> |
| |
| <p>Alternatively, consider a coin with unknown heads probability <i>p</i>. Where |
| <i>n</i> is the number of independent flips of that coin, and <i>k</i> is the number |
| of times that the coin comes up heads during a given batch of <i>n</i> flips. |
| This class computes a frequentist confidence interval [lowerBoundOnP, upperBoundOnP] for the |
| unknown <i>p</i>.</p> |
| |
| <p>Conceptually, the desired confidence level is specified by a tail probability delta.</p> |
| |
| <p>Ideally, over a large ensemble of independent batches of trials, |
| the fraction of batches in which the true <i>p</i> lies below lowerBoundOnP would be at most |
| delta, and the fraction of batches in which the true <i>p</i> lies above upperBoundOnP |
| would also be at most delta. |
| |
| <p>Setting aside the philosophical difficulties attaching to that statement, it isn't quite |
| true because we are approximating the Clopper-Pearson interval.</p> |
| |
| <p>Finally, we point out that in this class's interface, the confidence parameter delta is |
| not specified directly, but rather through a "number of standard deviations" numStdDev. |
| The library effectively converts that to a delta via delta = normalCDF (-1.0 * numStdDev).</p> |
| |
| <p>It is perhaps worth emphasizing that the library is NOT merely adding and subtracting |
| numStdDev standard deviations to the estimate. It is doing something better, that to some |
| extent accounts for the fact that the binomial distribution has a non-gaussian shape.</p> |
| |
| <p>In particular, it is using an approximation to the inverse of the incomplete beta function |
| that appears as formula 26.5.22 on page 945 of the "Handbook of Mathematical Functions" |
| by Abramowitz and Stegun.</p></div> |
| <dl> |
| <dt><span class="simpleTagLabel">Author:</span></dt> |
| <dd>Kevin Lang</dd> |
| </dl> |
| </li> |
| </ul> |
| </div> |
| <div class="summary"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ========== METHOD SUMMARY =========== --> |
| <section> |
| <ul class="blockList"> |
| <li class="blockList"><a id="method.summary"> |
| <!-- --> |
| </a> |
| <h3>Method Summary</h3> |
| <table class="memberSummary"> |
| <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd"> </span></span><span id="t1" class="tableTab"><span><a href="javascript:show(1);">Static Methods</a></span><span class="tabEnd"> </span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd"> </span></span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colSecond" scope="col">Method</th> |
| <th class="colLast" scope="col">Description</th> |
| </tr> |
| <tr id="i0" class="altColor"> |
| <td class="colFirst"><code>static double</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#approximateLowerBoundOnP(long,long,double)">approximateLowerBoundOnP</a></span>​(long n, |
| long k, |
| double numStdDevs)</code></th> |
| <td class="colLast"> |
| <div class="block">Computes lower bound of approximate Clopper-Pearson confidence interval for a binomial |
| proportion.</div> |
| </td> |
| </tr> |
| <tr id="i1" class="rowColor"> |
| <td class="colFirst"><code>static double</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#approximateUpperBoundOnP(long,long,double)">approximateUpperBoundOnP</a></span>​(long n, |
| long k, |
| double numStdDevs)</code></th> |
| <td class="colLast"> |
| <div class="block">Computes upper bound of approximate Clopper-Pearson confidence interval for a binomial |
| proportion.</div> |
| </td> |
| </tr> |
| <tr id="i2" class="altColor"> |
| <td class="colFirst"><code>static double</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#erf(double)">erf</a></span>​(double x)</code></th> |
| <td class="colLast"> |
| <div class="block">Computes an approximation to the erf() function.</div> |
| </td> |
| </tr> |
| <tr id="i3" class="rowColor"> |
| <td class="colFirst"><code>static double</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#estimateUnknownP(long,long)">estimateUnknownP</a></span>​(long n, |
| long k)</code></th> |
| <td class="colLast"> |
| <div class="block">Computes an estimate of an unknown binomial proportion.</div> |
| </td> |
| </tr> |
| <tr id="i4" class="altColor"> |
| <td class="colFirst"><code>static double</code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#normalCDF(double)">normalCDF</a></span>​(double x)</code></th> |
| <td class="colLast"> |
| <div class="block">Computes an approximation to normalCDF(x).</div> |
| </td> |
| </tr> |
| </table> |
| <ul class="blockList"> |
| <li class="blockList"><a id="methods.inherited.from.class.java.lang.Object"> |
| <!-- --> |
| </a> |
| <h3>Methods inherited from class java.lang.<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">Object</a></h3> |
| <code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang" class="externalLink">clone</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang" class="externalLink">equals</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang" class="externalLink">finalize</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang" class="externalLink">getClass</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang" class="externalLink">hashCode</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang" class="externalLink">notify</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang" class="externalLink">notifyAll</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang" class="externalLink">toString</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang" class="externalLink">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang" class="externalLink">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait(long,int)" title="class or interface in java.lang" class="externalLink">wait</a></code></li> |
| </ul> |
| </li> |
| </ul> |
| </section> |
| </li> |
| </ul> |
| </div> |
| <div class="details"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ============ METHOD DETAIL ========== --> |
| <section> |
| <ul class="blockList"> |
| <li class="blockList"><a id="method.detail"> |
| <!-- --> |
| </a> |
| <h3>Method Detail</h3> |
| <a id="approximateLowerBoundOnP(long,long,double)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>approximateLowerBoundOnP</h4> |
| <pre class="methodSignature">public static double approximateLowerBoundOnP​(long n, |
| long k, |
| double numStdDevs)</pre> |
| <div class="block">Computes lower bound of approximate Clopper-Pearson confidence interval for a binomial |
| proportion. |
| |
| <p>Implementation Notes:<br> |
| The approximateLowerBoundOnP is defined with respect to the right tail of the binomial |
| distribution.</p> |
| <ul> |
| <li>We want to solve for the <i>p</i> for which sum<sub><i>j,k,n</i></sub>bino(<i>j;n,p</i>) |
| = delta.</li> |
| <li>We now restate that in terms of the left tail.</li> |
| <li>We want to solve for the p for which sum<sub><i>j,0,(k-1)</i></sub>bino(<i>j;n,p</i>) |
| = 1 - delta.</li> |
| <li>Define <i>x</i> = 1-<i>p</i>.</li> |
| <li>We want to solve for the <i>x</i> for which I<sub><i>x(n-k+1,k)</i></sub> = 1 - delta.</li> |
| <li>We specify 1-delta via numStdDevs through the right tail of the standard normal |
| distribution.</li> |
| <li>Smaller values of numStdDevs correspond to bigger values of 1-delta and hence to smaller |
| values of delta. In fact, usefully small values of delta correspond to negative values of |
| numStdDevs.</li> |
| <li>return <i>p</i> = 1-<i>x</i>.</li> |
| </ul></div> |
| <dl> |
| <dt><span class="paramLabel">Parameters:</span></dt> |
| <dd><code>n</code> - is the number of trials. Must be non-negative.</dd> |
| <dd><code>k</code> - is the number of successes. Must be non-negative, and cannot exceed n.</dd> |
| <dd><code>numStdDevs</code> - the number of standard deviations defining the confidence interval</dd> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>the lower bound of the approximate Clopper-Pearson confidence interval for the |
| unknown success probability.</dd> |
| </dl> |
| </li> |
| </ul> |
| <a id="approximateUpperBoundOnP(long,long,double)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>approximateUpperBoundOnP</h4> |
| <pre class="methodSignature">public static double approximateUpperBoundOnP​(long n, |
| long k, |
| double numStdDevs)</pre> |
| <div class="block">Computes upper bound of approximate Clopper-Pearson confidence interval for a binomial |
| proportion. |
| |
| <p>Implementation Notes:<br> |
| The approximateUpperBoundOnP is defined with respect to the left tail of the binomial |
| distribution.</p> |
| <ul> |
| <li>We want to solve for the <i>p</i> for which sum<sub><i>j,0,k</i></sub>bino(<i>j;n,p</i>) |
| = delta.</li> |
| <li>Define <i>x</i> = 1-<i>p</i>.</li> |
| <li>We want to solve for the <i>x</i> for which I<sub><i>x(n-k,k+1)</i></sub> = delta.</li> |
| <li>We specify delta via numStdDevs through the right tail of the standard normal |
| distribution.</li> |
| <li>Bigger values of numStdDevs correspond to smaller values of delta.</li> |
| <li>return <i>p</i> = 1-<i>x</i>.</li> |
| </ul></div> |
| <dl> |
| <dt><span class="paramLabel">Parameters:</span></dt> |
| <dd><code>n</code> - is the number of trials. Must be non-negative.</dd> |
| <dd><code>k</code> - is the number of successes. Must be non-negative, and cannot exceed <i>n</i>.</dd> |
| <dd><code>numStdDevs</code> - the number of standard deviations defining the confidence interval</dd> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>the upper bound of the approximate Clopper-Pearson confidence interval for the |
| unknown success probability.</dd> |
| </dl> |
| </li> |
| </ul> |
| <a id="estimateUnknownP(long,long)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>estimateUnknownP</h4> |
| <pre class="methodSignature">public static double estimateUnknownP​(long n, |
| long k)</pre> |
| <div class="block">Computes an estimate of an unknown binomial proportion.</div> |
| <dl> |
| <dt><span class="paramLabel">Parameters:</span></dt> |
| <dd><code>n</code> - is the number of trials. Must be non-negative.</dd> |
| <dd><code>k</code> - is the number of successes. Must be non-negative, and cannot exceed n.</dd> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>the estimate of the unknown binomial proportion.</dd> |
| </dl> |
| </li> |
| </ul> |
| <a id="erf(double)"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>erf</h4> |
| <pre class="methodSignature">public static double erf​(double x)</pre> |
| <div class="block">Computes an approximation to the erf() function.</div> |
| <dl> |
| <dt><span class="paramLabel">Parameters:</span></dt> |
| <dd><code>x</code> - is the input to the erf function</dd> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>returns erf(x), accurate to roughly 7 decimal digits.</dd> |
| </dl> |
| </li> |
| </ul> |
| <a id="normalCDF(double)"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>normalCDF</h4> |
| <pre class="methodSignature">public static double normalCDF​(double x)</pre> |
| <div class="block">Computes an approximation to normalCDF(x).</div> |
| <dl> |
| <dt><span class="paramLabel">Parameters:</span></dt> |
| <dd><code>x</code> - is the input to the normalCDF function</dd> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd>returns the approximation to normalCDF(x).</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </section> |
| </li> |
| </ul> |
| </div> |
| </div> |
| </main> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <footer role="contentinfo"> |
| <nav role="navigation"> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a id="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <a id="navbar.bottom.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../index.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="class-use/BoundsOnBinomialProportions.html">Use</a></li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../allclasses.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_bottom"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Nested | </li> |
| <li>Field | </li> |
| <li>Constr | </li> |
| <li><a href="#method.summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li>Constr | </li> |
| <li><a href="#method.detail">Method</a></li> |
| </ul> |
| </div> |
| <a id="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </nav> |
| <p class="legalCopy"><small>Copyright © 2015–2022 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p> |
| </footer> |
| </body> |
| </html> |