PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_stat_prob_hypergeom_vector (g01sl)
Purpose
nag_stat_prob_hypergeom_vector (g01sl) returns a number of the lower tail, upper tail and point probabilities for the hypergeometric distribution.
Syntax
[
plek,
pgtk,
peqk,
ivalid,
ifail] = g01sl(
n,
l,
m,
k, 'ln',
ln, 'll',
ll, 'lm',
lm, 'lk',
lk)
[
plek,
pgtk,
peqk,
ivalid,
ifail] = nag_stat_prob_hypergeom_vector(
n,
l,
m,
k, 'ln',
ln, 'll',
ll, 'lm',
lm, 'lk',
lk)
Description
Let
denote a vector of random variables having a hypergeometric distribution with parameters
,
and
. Then
where
,
and
.
The hypergeometric distribution may arise if in a population of size a number are marked. From this population a sample of size is drawn and of these are observed to be marked.
The mean of the distribution , and the variance .
nag_stat_prob_hypergeom_vector (g01sl) 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 parameter of the hypergeometric distribution with , , for .
Constraint:
, for .
- 2:
– int64int32nag_int array
-
, the parameter of the hypergeometric distribution with , .
Constraint:
.
- 3:
– int64int32nag_int array
-
, the parameter of the hypergeometric distribution with , .
Constraint:
.
- 4:
– 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
l.
The length of the array
l
Constraint:
.
- 3:
– int64int32nag_int scalar
-
Default:
the dimension of the array
m.
The length of the array
m
Constraint:
.
- 4:
– 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 | , |
or | , |
or | . |
On entry, | is too large to be represented exactly as a real number. |
- 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,
l,
m or
k was invalid, or the variance was too large.
Check
ivalid for more information.
-
-
Constraint: .
-
-
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 (provided that the results do not underflow to zero).
Further Comments
The time taken by
nag_stat_prob_hypergeom_vector (g01sl) to calculate each probability depends on the variance (see
Description) and on
. For given variance, the time is greatest when
(
the mean), 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:
g01sl_example
function g01sl_example
fprintf('g01sl example results\n\n');
n = [int64(10); 40; 155; 1000];
l = [int64( 2); 10; 35; 444];
m = [int64( 5); 3; 122; 500];
k = [int64( 1); 2; 22; 220];
[plek, pgtk, peqk, ivalid, ifail] = ...
g01sl(n, l, m, k);
fprintf(' n l m k plek pgtk peqk\n');
ln = numel(n);
ll = numel(l);
lm = numel(m);
lk = numel(k);
len = max ([ln, ll, lm, lk]);
for i=0:len-1
fprintf('%4d%4d%4d%4d%10.5f%10.5f%10.5f\n', n(mod(i,ln)+1), ...
l(mod(i,ll)+1), m(mod(i,lm)+1), k(mod(i,lk)+1), plek(i+1), ...
pgtk(i+1), peqk(i+1));
end
g01sl example results
n l m k plek pgtk peqk
10 2 5 1 0.77778 0.22222 0.55556
40 10 3 2 0.98785 0.01215 0.13664
155 35 122 22 0.01101 0.98899 0.00779
1000 444 500 220 0.42429 0.57571 0.04913
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015