datasketches-cpp
|
Confidence intervals for binomial proportions. More...
#include <bounds_binomial_proportions.hpp>
Static Public Member Functions | |
static double | approximate_lower_bound_on_p (uint64_t n, uint64_t k, double num_std_devs) |
Computes lower bound of approximate Clopper-Pearson confidence interval for a binomial proportion. More... | |
static double | approximate_upper_bound_on_p (uint64_t n, uint64_t k, double num_std_devs) |
Computes upper bound of approximate Clopper-Pearson confidence interval for a binomial proportion. More... | |
static double | estimate_unknown_p (uint64_t n, uint64_t k) |
Computes an estimate of an unknown binomial proportion. More... | |
static double | erf (double x) |
Computes an approximation to the erf() function. More... | |
static double | normal_cdf (double x) |
Computes an approximation to normal_cdf(x). More... | |
Confidence intervals for binomial proportions.
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.
The main inputs are numbers n and k, which are not the same as other things that are called n and k in our sketching library. There is also a third parameter, numStdDev, that specifies the desired confidence level.
Alternatively, consider a coin with unknown heads probability p. Where n is the number of independent flips of that coin, and k is the number of times that the coin comes up heads during a given batch of n flips. This class computes a frequentist confidence interval [lowerBoundOnP, upperBoundOnP] for the unknown p.
Conceptually, the desired confidence level is specified by a tail probability delta.
Ideally, over a large ensemble of independent batches of trials, the fraction of batches in which the true p lies below lowerBoundOnP would be at most delta, and the fraction of batches in which the true p lies above upperBoundOnP would also be at most delta.
Setting aside the philosophical difficulties attaching to that statement, it isn't quite true because we are approximating the Clopper-Pearson interval.
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).
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.
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.
|
inlinestatic |
Computes lower bound of approximate Clopper-Pearson confidence interval for a binomial proportion.
Implementation Notes:
The approximateLowerBoundOnP is defined with respect to the right tail of the binomial distribution.
n | is the number of trials. Must be non-negative. |
k | is the number of successes. Must be non-negative, and cannot exceed n. |
num_std_devs | the number of standard deviations defining the confidence interval |
|
inlinestatic |
Computes upper bound of approximate Clopper-Pearson confidence interval for a binomial proportion.
Implementation Notes:
The approximateUpperBoundOnP is defined with respect to the left tail of the binomial distribution.
n | is the number of trials. Must be non-negative. |
k | is the number of successes. Must be non-negative, and cannot exceed n. |
num_std_devs | the number of standard deviations defining the confidence interval |
|
inlinestatic |
Computes an estimate of an unknown binomial proportion.
n | is the number of trials. Must be non-negative. |
k | is the number of successes. Must be non-negative, and cannot exceed n. |
|
inlinestatic |
Computes an approximation to the erf() function.
x | is the input to the erf function |
|
inlinestatic |
Computes an approximation to normal_cdf(x).
x | is the input to the normal_cdf function |