PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_stat_prob_binomial_vector (g01sj)
Purpose
nag_stat_prob_binomial_vector (g01sj) returns a number of the lower tail, upper tail and point probabilities for the binomial distribution.
Syntax
[
plek,
pgtk,
peqk,
ivalid,
ifail] = g01sj(
n,
p,
k, 'ln',
ln, 'lp',
lp, 'lk',
lk)
[
plek,
pgtk,
peqk,
ivalid,
ifail] = nag_stat_prob_binomial_vector(
n,
p,
k, 'ln',
ln, 'lp',
lp, 'lk',
lk)
Description
Let
denote a vector of random variables each having a binomial distribution with parameters
and
(
and
). Then
The mean of the each distribution is given by
and the variance by
.
nag_stat_prob_binomial_vector (g01sj) computes, for given
,
and
, the probabilities:
,
and
using an algorithm similar to that described in
Knüsel (1986) for the Poisson distribution.
The input arrays to this function are designed to allow maximum flexibility in the supply of vector arguments by re-using elements of any arrays that are shorter than the total number of evaluations required. See
Vectorized Routines in the G01 Chapter Introduction for further information.
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:
– int64int32nag_int array
-
, the first parameter of the binomial distribution with , , for .
Constraint:
, for .
- 2:
– double array
-
, the second parameter of the binomial distribution with , .
Constraint:
, for .
- 3:
– int64int32nag_int array
-
, the integer which defines the required probabilities with , .
Constraint:
.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
n.
The length of the array
n
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the array
p.
The length of the array
p
Constraint:
.
- 3:
– int64int32nag_int scalar
-
Default:
the dimension of the array
k.
The length of the array
k
Constraint:
.
Output Parameters
- 1:
– double array
-
The dimension of the array
plek will be
, the lower tail probabilities.
- 2:
– double array
-
The dimension of the array
pgtk will be
, the upper tail probabilities.
- 3:
– double array
-
The dimension of the array
peqk will be
, the point probabilities.
- 4:
– int64int32nag_int array
-
The dimension of the array
ivalid will be
indicates any errors with the input arguments, with
- No error.
On entry, | , |
or | . |
On entry, | is too large to be represented exactly as a real number. |
On entry, | the variance () exceeds . |
- 5:
– 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:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
- W
-
On entry, at least one value of
n,
p or
k was invalid.
Check
ivalid for more information.
-
-
Constraint: .
-
-
Constraint: .
-
-
Constraint: .
-
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
Results are correct to a relative accuracy of at least on machines with a precision of or more decimal digits, and to a relative accuracy of at least on machines of lower precision (provided that the results do not underflow to zero).
Further Comments
The time taken by nag_stat_prob_binomial_vector (g01sj) to calculate each probability depends on the variance () and on . For given variance, the time is greatest when (), and is then approximately proportional to the square-root of the variance.
Example
This example reads a vector of values for , and , and prints the corresponding probabilities.
Open in the MATLAB editor:
g01sj_example
function g01sj_example
fprintf('g01sj example results\n\n');
n = [int64(4); 19; 100; 2000];
p = [ 0.500; 0.440; 0.750; 0.330];
k = [int64(2); 13; 67; 700];
[plek, pgtk, peqk, ivalid, ifail] = ...
g01sj(n, p, k);
fprintf(' n p k plek pgtk peqk\n');
ln = numel(n);
lp = numel(p);
lk = numel(k);
len = max ([ln, lp, lk]);
for i=0:len-1
fprintf('%5d%8.3f%5d%10.5f%10.5f%10.5f\n', n(mod(i,ln)+1), ...
p(mod(i,lp)+1), k(mod(i,lk)+1), plek(i+1), pgtk(i+1), peqk(i+1));
end
g01sj 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)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015