| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (1.8.0_162) on Thu Mar 14 13:13:08 PDT 2019 --> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <title>BoundsOnBinomialProportions (com.yahoo.datasketches:sketches-core 0.13.1-SNAPSHOT API)</title> |
| <meta name="date" content="2019-03-14"> |
| <link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style"> |
| <script type="text/javascript" src="../../../script.js"></script> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| try { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="BoundsOnBinomialProportions (com.yahoo.datasketches:sketches-core 0.13.1-SNAPSHOT API)"; |
| } |
| } |
| catch(err) { |
| } |
| //--> |
| var methods = {"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"; |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a name="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.top.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../overview-summary.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"> |
| <li><a href="../../../com/yahoo/sketches/BinomialBoundsN.html" title="class in com.yahoo.sketches"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../../com/yahoo/sketches/BoundsOnRatiosInSampledSets.html" title="class in com.yahoo.sketches"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../index.html?com/yahoo/sketches/BoundsOnBinomialProportions.html" target="_top">Frames</a></li> |
| <li><a href="BoundsOnBinomialProportions.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../allclasses-noframe.html">All Classes</a></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> |
| </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 name="skip.navbar.top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <div class="header"> |
| <div class="subTitle">com.yahoo.sketches</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">java.lang.Object</a></li> |
| <li> |
| <ul class="inheritance"> |
| <li>com.yahoo.sketches.BoundsOnBinomialProportions</li> |
| </ul> |
| </li> |
| </ul> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <hr> |
| <br> |
| <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">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 =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="method.summary"> |
| <!-- --> |
| </a> |
| <h3>Method Summary</h3> |
| <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation"> |
| <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="colLast" scope="col">Method and Description</th> |
| </tr> |
| <tr id="i0" class="altColor"> |
| <td class="colFirst"><code>static double</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../com/yahoo/sketches/BoundsOnBinomialProportions.html#approximateLowerBoundOnP-long-long-double-">approximateLowerBoundOnP</a></span>(long n, |
| long k, |
| double numStdDevs)</code> |
| <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> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../com/yahoo/sketches/BoundsOnBinomialProportions.html#approximateUpperBoundOnP-long-long-double-">approximateUpperBoundOnP</a></span>(long n, |
| long k, |
| double numStdDevs)</code> |
| <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> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../com/yahoo/sketches/BoundsOnBinomialProportions.html#erf-double-">erf</a></span>(double x)</code> |
| <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> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../com/yahoo/sketches/BoundsOnBinomialProportions.html#estimateUnknownP-long-long-">estimateUnknownP</a></span>(long n, |
| long k)</code> |
| <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> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../com/yahoo/sketches/BoundsOnBinomialProportions.html#normalCDF-double-">normalCDF</a></span>(double x)</code> |
| <div class="block">Computes an approximation to normalCDF(x).</div> |
| </td> |
| </tr> |
| </table> |
| <ul class="blockList"> |
| <li class="blockList"><a name="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">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">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">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">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">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">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">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">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">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">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">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">wait</a></code></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| <div class="details"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ============ METHOD DETAIL ========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="method.detail"> |
| <!-- --> |
| </a> |
| <h3>Method Detail</h3> |
| <a name="approximateLowerBoundOnP-long-long-double-"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>approximateLowerBoundOnP</h4> |
| <pre>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 name="approximateUpperBoundOnP-long-long-double-"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>approximateUpperBoundOnP</h4> |
| <pre>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 name="estimateUnknownP-long-long-"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>estimateUnknownP</h4> |
| <pre>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 name="erf-double-"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>erf</h4> |
| <pre>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 name="normalCDF-double-"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>normalCDF</h4> |
| <pre>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> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a name="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.bottom.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../overview-summary.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"> |
| <li><a href="../../../com/yahoo/sketches/BinomialBoundsN.html" title="class in com.yahoo.sketches"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../../com/yahoo/sketches/BoundsOnRatiosInSampledSets.html" title="class in com.yahoo.sketches"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../index.html?com/yahoo/sketches/BoundsOnBinomialProportions.html" target="_top">Frames</a></li> |
| <li><a href="BoundsOnBinomialProportions.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../allclasses-noframe.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> |
| </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 name="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| <p class="legalCopy"><small>Copyright © 2015–2019. All rights reserved.</small></p> |
| </body> |
| </html> |