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)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

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 X denote a random variable having a binomial distribution with parameters n and p (n0 and 0<p<1). Then
ProbX=k= n k pk1-pn-k,  k=0,1,,n.  
The mean of the distribution is np and the variance is np1-p.
nag_stat_prob_binomial (g01bj) computes for given n, p and k the probabilities:
plek=ProbXk pgtk=ProbX>k peqk=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

Parameters

Compulsory Input Parameters

1:     n int64int32nag_int scalar
The parameter n of the binomial distribution.
Constraint: n0.
2:     p – double scalar
The parameter p of the binomial distribution.
Constraint: 0.0<p<1.0.
3:     k int64int32nag_int scalar
The integer k which defines the required probabilities.
Constraint: 0kn.

Optional Input Parameters

None.

Output Parameters

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

Error Indicators and Warnings

Errors or warnings detected by the function:
   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 double number.
   ifail=5
On entry,the variance (=np1-p) exceeds 106.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

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).

Further Comments

The time taken by nag_stat_prob_binomial (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.
function g01bj_example


fprintf('g01bj example results\n\n');

n = int64([4    19     100    2000]);
k = int64([2    13     67     700]);
p =         [0.5  0.44   0.75   0.33];

fprintf('   n     p      k     plek      pgtk      peqk\n');
for i=1:4
  [plek, pgtk, peqk, ifail] = ...
  g01bj(n(i), p(i), k(i));
  fprintf('%5d%7.3f%5d%10.5f%10.5f%10.5f\n', n(i), p(i), k(i), ...
	  plek, pgtk, peqk);
end


g01bj example results

   n     p      k     plek      pgtk      peqk
    4  0.500    2   0.68750   0.31250   0.37500
   19  0.440   13   0.99138   0.00862   0.01939
  100  0.750   67   0.04460   0.95540   0.01700
 2000  0.330  700   0.97251   0.02749   0.00312

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–2015