BinomialCI
Description
BinomialCI returns the confidence interval for the proportion of successes in a binomial experiment. The output is a 3-element column vector with p-hat, p-lower, and p-upper. The 95% CI is returned by default but the user can choose a different alpha value. The exact method is used, returning a conservative CI guaranteed to give the desired coverage (at a minimum).
Syntax
BinomialCI(n_s, N, [alpha = 0.05])
n_sis the number of successes in the binomial experiment, however that is definedNis the total number of trials in the binomial experimentalphais the desired significance level; by default it is 0.05 so the returned CI is guaranteed to have coverage of at least 95% (assuming the binomial model applies to the experiment)
The output is a 3-element column vector containing the following elements:
- the point estimate of the success rate
- the lower limit of the CI
- the upper limit of the CI
Example
Imagine you are interested in whether a given measurement protocol is biased and so you analyze a reference material of known composition 25 times, and 18 of those measurements have a positive bias. The cell formula below (assuming the default prefix) will return the 95% CI:
// cell formula
=L.BinomialCI(18,25)
// output column vector
0.72
0.506123178
0.879283311In the output: 0.72 is the success rate (ie the fraction of measurements with positive bias) and the 95% CI is (0.506, 0.879). Since the CI does not contain the value of 0.5 we conclude that the method is biased.
Source Code
BinomialCI = LAMBDA(
n_s, // number of successes in the experiment
N, // number of binomial trials
[alpha], // optional significance level (default 5%)
LET(
alpha, IF(ISOMITTED(alpha), 5%, alpha),
// calculate point estimate
p_hat, n_s / N,
// calculate lower limit
p_lower, IF(
n_s = 0,
0, // by definition
BETA.INV(alpha / 2, n_s, N - n_s + 1)
),
// calculate upper limit
p_upper, IF(n_s = N, 1, BETA.INV(1 - alpha / 2, n_s + 1, N - n_s)),
VSTACK(p_hat, p_lower, p_upper)
)
);