hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_stat_prob_binomial (g01bj)

Purpose

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

Syntax

[plek, pgtk, peqk, ifail] = g01bj(n, p, k)
[plek, pgtk, peqk, ifail] = nag_stat_prob_binomial(n, p, k)

Description

Let XX denote a random variable having a binomial distribution with parameters nn and pp (n0n0 and 0 < p < 10<p<1). Then
Prob{X = k} =
(n)
k
pk(1p)nk,  k = 0,1,,n.
Prob{X=k}= n k pk(1-p)n-k,  k=0,1,,n.
The mean of the distribution is npnp and the variance is np(1p)np(1-p).
nag_stat_prob_binomial (g01bj) computes for given nn, pp and kk the probabilities:
plek = Prob{Xk}
pgtk = Prob{X > k}
peqk = Prob{X = k} .
plek=Prob{Xk} pgtk=Prob{X>k} peqk=Prob{X=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

Parameters

Compulsory Input Parameters

1:     n – int64int32nag_int scalar
The parameter nn of the binomial distribution.
Constraint: n0n0.
2:     p – double scalar
The parameter pp of the binomial distribution.
Constraint: 0.0 < p < 1.00.0<p<1.0.
3:     k – int64int32nag_int scalar
The integer kk which defines the required probabilities.
Constraint: 0kn0kn.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     plek – double scalar
The lower tail probability, Prob{Xk}Prob{Xk}.
2:     pgtk – double scalar
The upper tail probability, Prob{X > k}Prob{X>k}.
3:     peqk – double scalar
The point probability, Prob{X = k}Prob{X=k}.
4:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,n < 0n<0.
  ifail = 2ifail=2
On entry,p0.0p0.0,
orp1.0p1.0.
  ifail = 3ifail=3
On entry,k < 0k<0,
ork > nk>n.
  ifail = 4ifail=4
On entry,n is too large to be represented exactly as a double number.
  ifail = 5ifail=5
On entry,the variance ( = np(1p)=np(1-p)) exceeds 106106.

Accuracy

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

Further Comments

The time taken by nag_stat_prob_binomial (g01bj) depends on the variance ( = np(1p)=np(1-p)) and on kk. For given variance, the time is greatest when knpknp ( = the mean=the mean), and is then approximately proportional to the square-root of the variance.

Example

function nag_stat_prob_binomial_example
n = int64(4);
p = 0.5;
k = int64(2);
[plek, pgtk, peqk, ifail] = nag_stat_prob_binomial(n, p, k)
 

plek =

    0.6875


pgtk =

    0.3125


peqk =

    0.3750


ifail =

                    0


function g01bj_example
n = int64(4);
p = 0.5;
k = int64(2);
[plek, pgtk, peqk, ifail] = g01bj(n, p, k)
 

plek =

    0.6875


pgtk =

    0.3125


peqk =

    0.3750


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013