PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_univar_ci_binomial (g07aa)
Purpose
nag_univar_ci_binomial (g07aa) computes a confidence interval for the argument (the probability of a success) of a binomial distribution.
Syntax
Description
Given the number of trials,
, and the number of successes,
, this function computes a
confidence interval for
, the probability argument of a binomial distribution with probability function,
where
is in the interval
.
Let the confidence interval be denoted by [].
The point estimate for is .
The lower and upper confidence limits
and
are estimated by the solutions to the equations;
Three different methods are used depending on the number of trials,
, and the number of successes,
.
1. |
If .
The relationship between the beta and binomial distributions (see page 38 of Hastings and Peacock (1975)) is used to derive the equivalent equations,
where is the deviate associated with the lower tail probability, , of the beta distribution with arguments and . These beta deviates are computed using nag_stat_inv_cdf_beta (g01fe). |
2. |
If and .
The binomial variate with arguments and is approximated by a Poisson variate with mean , see page 38 of Hastings and Peacock (1975).
The relationship between the Poisson and -distributions (see page 112 of Hastings and Peacock (1975)) is used to derive the following equations;
where is the deviate associated with the lower tail probability, , of the -distribution with degrees of freedom.
In turn the relationship between the -distribution and the gamma distribution (see page 70 of Hastings and Peacock (1975)) yields the following equivalent equations;
where is the deviate associated with the lower tail probability, , of the gamma distribution with shape argument and scale argument . These deviates are computed using nag_stat_inv_cdf_gamma (g01ff). |
3. |
If and .
The binomial variate with arguments and is approximated by a Normal variate with mean and variance , see page 38 of Hastings and Peacock (1975).
The approximate lower and upper confidence limits and are the solutions to the equations;
where is the deviate associated with the lower tail probability, , of the standard Normal distribution. These equations are solved using a quadratic equation solver
( nag_zeros_quadratic_real (c02aj)).
|
References
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth
Snedecor G W and Cochran W G (1967) Statistical Methods Iowa State University Press
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
, the number of trials.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
, the number of successes.
Constraint:
.
- 3:
– double scalar
-
The confidence level, , for two-sided interval estimate. For example will give a confidence interval.
Constraint:
.
Optional Input Parameters
None.
Output Parameters
- 1:
– double scalar
-
The lower limit, , of the confidence interval.
- 2:
– double scalar
-
The upper limit, , of the confidence interval.
- 3:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
On entry, | , |
or | , |
or | , |
or | , |
or | . |
-
-
When using the relationship with the gamma distribution to calculate one of the confidence limits, the series to calculate the gamma probabilities has failed to converge. Both
pl and
pu are set to zero. This is a very unlikely error exit and if it occurs please contact
NAG.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
For most cases using the beta deviates the results should have a relative accuracy of
where
is the
machine precision (see
nag_machine_precision (x02aj)). Thus on machines with sufficiently high precision the results should be accurate to
significant figures. Some accuracy may be lost when
or
is very close to
, which will occur if
clevel is very close to
. This should not affect the usual confidence levels used.
The approximations used when is large are accurate to at least significant digits but usually to more.
Further Comments
None.
Example
The following example program reads in the number of deaths recorded among male recipients of war pensions in a six year period following an initial questionnaire in 1956. We consider two classes, non-smokers and those who reported that they smoked pipes only. The total number of males in each class is also read in. The data is taken from page 216 of
Snedecor and Cochran (1967). An estimate of the probability of a death in the six year period in each class is computed together with 95% confidence intervals for these estimates.
Open in the MATLAB editor:
g07aa_example
function g07aa_example
fprintf('g07aa example results\n\n');
n = int64([1067, 402]);
k = int64([117, 54]);
clevel = 0.95;
disp(' Probability Confidence Interval ');
for j = 1:numel(n)
[pl, pu, ifail] = g07aa(n(j), k(j), clevel);
p_hat = double(k(j))/double(n(j));
fprintf('%10.4f (%7.4f, %7.4f)\n', p_hat, pl, pu);
end
g07aa example results
Probability Confidence Interval
0.1097 ( 0.0915, 0.1300)
0.1343 ( 0.1025, 0.1716)
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015