NAG Library Routine Document
g07aaf
(ci_binomial)
1
Purpose
g07aaf computes a confidence interval for the argument (the probability of a success) of a binomial distribution.
2
Specification
Fortran Interface
Integer, Intent (In) | :: |
n,
k | Integer, Intent (Inout) | :: |
ifail | Real (Kind=nag_wp), Intent (In) | :: |
clevel | Real (Kind=nag_wp), Intent (Out) | :: |
pl,
pu |
|
C Header Interface
#include nagmk26.h
void |
g07aaf_ (
const Integer *n,
const Integer *k,
const double *clevel,
double *pl,
double *pu,
Integer *ifail) |
|
3
Description
Given the number of trials,
, and the number of successes,
, this routine 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 g01fef. |
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 g01fff. |
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
( c02ajf).
|
4
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
5
Arguments
- 1: – IntegerInput
-
On entry: , the number of trials.
Constraint:
.
- 2: – IntegerInput
-
On entry: , the number of successes.
Constraint:
.
- 3: – Real (Kind=nag_wp)Input
-
On entry: the confidence level, , for two-sided interval estimate. For example will give a confidence interval.
Constraint:
.
- 4: – Real (Kind=nag_wp)Output
-
On exit: the lower limit, , of the confidence interval.
- 5: – Real (Kind=nag_wp)Output
-
On exit: the upper limit, , of the confidence interval.
- 6: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
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.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
For most cases using the beta deviates the results should have a relative accuracy of
where
is the
machine precision (see
x02ajf). 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.
8
Parallelism and Performance
g07aaf is not threaded in any implementation.
None.
10
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.
10.1
Program Text
Program Text (g07aafe.f90)
10.2
Program Data
Program Data (g07aafe.d)
10.3
Program Results
Program Results (g07aafe.r)