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_inv_cdf_beta_vector (g01te)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_stat_inv_cdf_beta_vector (g01te) returns a number of deviates associated with given probabilities of the beta distribution.

Syntax

[beta, ivalid, ifail] = g01te(tail, p, a, b, 'ltail', ltail, 'lp', lp, 'la', la, 'lb', lb, 'tol', tol)
[beta, ivalid, ifail] = nag_stat_inv_cdf_beta_vector(tail, p, a, b, 'ltail', ltail, 'lp', lp, 'la', la, 'lb', lb, 'tol', tol)

Description

The deviate, βpi, associated with the lower tail probability, pi, of the beta distribution with parameters ai and bi is defined as the solution to
P Bi βpi :ai,bi = pi = Γ ai + bi Γ ai Γ bi 0 βpi Bi ai-1 1-Bi bi-1 d Bi ,   0 β pi 1 ; ​ ai , bi > 0 .  
The algorithm is a modified version of the Newton–Raphson method, following closely that of Cran et al. (1977).
An initial approximation, βi0, to βpi is found (see Cran et al. (1977)), and the Newton–Raphson iteration
βk = βk-1 - fi βk-1 fi βk-1 ,  
where fi βk = P Bi βk :ai,bi - pi  is used, with modifications to ensure that βk remains in the range 0,1.
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

Cran G W, Martin K J and Thomas G E (1977) Algorithm AS 109. Inverse of the incomplete beta function ratio Appl. Statist. 26 111–114
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth

Parameters

Compulsory Input Parameters

1:     tailltail – cell array of strings
Indicates which tail the supplied probabilities represent. For j= i-1 mod ltail +1 , for i=1,2,,maxltail,lp,la,lb:
tailj='L'
The lower tail probability, i.e., pi = P Bi βpi : ai , bi .
tailj='U'
The upper tail probability, i.e., pi = P Bi βpi : ai , bi .
Constraint: tailj='L' or 'U', for j=1,2,,ltail.
2:     plp – double array
pi, the probability of the required beta distribution as defined by tail with pi=pj, j=i-1 mod lp+1.
Constraint: 0.0pj1.0, for j=1,2,,lp.
3:     ala – double array
ai, the first parameter of the required beta distribution with ai=aj, j=i-1 mod la+1.
Constraint: 0.0<aj106, for j=1,2,,la.
4:     blb – double array
bi, the second parameter of the required beta distribution with bi=bj, j=i-1 mod lb+1.
Constraint: 0.0<bj106, for j=1,2,,lb.

Optional Input Parameters

1:     ltail int64int32nag_int scalar
Default: the dimension of the array tail.
The length of the array tail.
Constraint: ltail>0.
2:     lp int64int32nag_int scalar
Default: the dimension of the array p.
The length of the array p.
Constraint: lp>0.
3:     la int64int32nag_int scalar
Default: the dimension of the array a.
The length of the array a.
Constraint: la>0.
4:     lb int64int32nag_int scalar
Default: the dimension of the array b.
The length of the array b.
Constraint: lb>0.
5:     tol – double scalar
Default: 0.0
The relative accuracy required by you in the results. If nag_stat_inv_cdf_beta_vector (g01te) is entered with tol greater than or equal to 1.0 or less than 10×machine precision (see nag_machine_precision (x02aj)), then the value of 10×machine precision is used instead.

Output Parameters

1:     beta: – double array
The dimension of the array beta will be maxltail,lp,la,lb
βpi, the deviates for the beta distribution.
2:     ivalid: int64int32nag_int array
The dimension of the array ivalid will be maxltail,lp,la,lb
ivalidi indicates any errors with the input arguments, with
ivalidi=0
No error.
ivalidi=1
On entry,invalid value supplied in tail when calculating βpi.
ivalidi=2
On entry,pi<0.0,
orpi>1.0.
ivalidi=3
On entry,ai0.0,
orai>106,
orbi0.0,
orbi>106.
ivalidi=4
The solution has not converged but the result should be a reasonable approximation to the solution.
ivalidi=5
Requested accuracy not achieved when calculating the beta probability. The result should be a reasonable approximation to the correct solution.
3:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Note: nag_stat_inv_cdf_beta_vector (g01te) may return useful information for one or more of the following detected errors or 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  ifail=1
On entry, at least one value of tail, p, a, or b was invalid, or the solution failed to converge.
Check ivalid for more information.
   ifail=2
Constraint: ltail>0.
   ifail=3
Constraint: lp>0.
   ifail=4
Constraint: la>0.
   ifail=5
Constraint: lb>0.
   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

The required precision, given by tol, should be achieved in most circumstances.

Further Comments

The typical timing will be several times that of nag_stat_prob_beta_vector (g01se) and will be very dependent on the input argument values. See nag_stat_prob_beta_vector (g01se) for further comments on timings.

Example

This example reads lower tail probabilities for several beta distributions and calculates and prints the corresponding deviates.
function g01te_example


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

tail = {'L'};
p = [0.5; 0.99; 0.25];
a = [1.0; 1.5; 20.0];
b = [2.0; 1.5; 10.0];

[x, ivalid, ifail] = g01te( ...
                            tail, p, a, b);

fprintf('  tail  probability    a         b    deviate    ivalid\n');
ltail = numel(tail);
lp    = numel(p);
la    = numel(a);
lb    = numel(b);
len   = max ([ltail, lp, la, lb]);
for i=0:len-1
  fprintf('%5s%9.4f%10.3f%10.3f%10.4f%8d\n', tail{mod(i, ltail)+1}, ...
          p(mod(i,lp)+1), a(mod(i,la)+1), b(mod(i,lb)+1), x(i+1), ivalid(i+1));
end


g01te example results

  tail  probability    a         b    deviate    ivalid
    L   0.5000     1.000     2.000    0.2929       0
    L   0.9900     1.500     1.500    0.9672       0
    L   0.2500    20.000    10.000    0.6105       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–2015