g01bj returns the lower tail, upper tail and point probabilities associated with a binomial distribution.

Syntax

C#
public static void g01bj(
	int n,
	double p,
	int k,
	out double plek,
	out double pgtk,
	out double peqk,
	out int ifail
)
Visual Basic
Public Shared Sub g01bj ( _
	n As Integer, _
	p As Double, _
	k As Integer, _
	<OutAttribute> ByRef plek As Double, _
	<OutAttribute> ByRef pgtk As Double, _
	<OutAttribute> ByRef peqk As Double, _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g01bj(
	int n, 
	double p, 
	int k, 
	[OutAttribute] double% plek, 
	[OutAttribute] double% pgtk, 
	[OutAttribute] double% peqk, 
	[OutAttribute] int% ifail
)
F#
static member g01bj : 
        n : int * 
        p : float * 
        k : int * 
        plek : float byref * 
        pgtk : float byref * 
        peqk : float byref * 
        ifail : int byref -> unit 

Parameters

n
Type: System..::..Int32
On entry: the parameter n of the binomial distribution.
Constraint: n0.
p
Type: System..::..Double
On entry: the parameter p of the binomial distribution.
Constraint: 0.0<p<1.0.
k
Type: System..::..Int32
On entry: the integer k which defines the required probabilities.
Constraint: 0kn.
plek
Type: System..::..Double%
On exit: the lower tail probability, ProbXk.
pgtk
Type: System..::..Double%
On exit: the upper tail probability, ProbX>k.
peqk
Type: System..::..Double%
On exit: the point probability, ProbX=k.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

Description

Let X denote a random variable having a binomial distribution with parameters n and p (n0 and 0<p<1). Then
ProbX=k=nkpk1-pn-k,  k=0,1,,n.
The mean of the distribution is np and the variance is np1-p.
g01bj computes for given n, p and k the probabilities:
plek=ProbXkpgtk=ProbX>kpeqk=ProbX=k.
The method is similar to the method for the Poisson distribution described in Knüsel (1986).

References

Knüsel L (1986) Computation of the chi-square and Poisson distribution SIAM J. Sci. Statist. Comput. 7 1022–1036

Error Indicators and Warnings

Errors or warnings detected by the method:
ifail=1
On entry,n<0.
ifail=2
On entry,p0.0,
orp1.0.
ifail=3
On entry,k<0,
ork>n.
ifail=4
On entry,n is too large to be represented exactly as a real number.
ifail=5
On entry,the variance (=np1-p) exceeds 106.
ifail=-9000
An error occured, see message report.

Accuracy

Results are correct to a relative accuracy of at least 10-6 on machines with a precision of 9 or more decimal digits, and to a relative accuracy of at least 10-3 on machines of lower precision (provided that the results do not underflow to zero).

Parallelism and Performance

None.

Further Comments

The time taken by g01bj depends on the variance (=np1-p) and on k. For given variance, the time is greatest when knp (=the mean), and is then approximately proportional to the square-root of the variance.

Example

This example reads values of n and p from a data file until end-of-file is reached, and prints the corresponding probabilities.

Example program (C#): g01bje.cs

Example program data: g01bje.d

Example program results: g01bje.r

See Also