G01TEF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G01TEF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

G01TEF returns a number of deviates associated with given probabilities of the beta distribution.

2  Specification

SUBROUTINE G01TEF ( LTAIL, TAIL, LP, P, LA, A, LB, B, TOL, BETA, IVALID, IFAIL)
INTEGER  LTAIL, LP, LA, LB, IVALID(*), IFAIL
REAL (KIND=nag_wp)  P(LP), A(LA), B(LB), TOL, BETA(*)
CHARACTER(1)  TAIL(LTAIL)

3  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 routine are designed to allow maximum flexibility in the supply of vector parameters by re-using elements of any arrays that are shorter than the total number of evaluations required. See Section 2.6 in the G01 Chapter Introduction for further information.

4  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

5  Parameters

1:     LTAIL – INTEGERInput
On entry: the length of the array TAIL.
Constraint: LTAIL>0.
2:     TAILLTAIL – CHARACTER(1) arrayInput
On entry: 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.
3:     LP – INTEGERInput
On entry: the length of the array P.
Constraint: LP>0.
4:     PLP – REAL (KIND=nag_wp) arrayInput
On entry: 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.
5:     LA – INTEGERInput
On entry: the length of the array A.
Constraint: LA>0.
6:     ALA – REAL (KIND=nag_wp) arrayInput
On entry: 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.
7:     LB – INTEGERInput
On entry: the length of the array B.
Constraint: LB>0.
8:     BLB – REAL (KIND=nag_wp) arrayInput
On entry: 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.
9:     TOL – REAL (KIND=nag_wp)Input
On entry: the relative accuracy required by you in the results. If G01TEF is entered with TOL greater than or equal to 1.0 or less than 10×machine precision (see X02AJF), then the value of 10×machine precision is used instead.
10:   BETA* – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array BETA must be at least maxLTAIL,LP,LA,LB.
On exit: βpi, the deviates for the beta distribution.
11:   IVALID* – INTEGER arrayOutput
Note: the dimension of the array IVALID must be at least maxLTAIL,LP,LA,LB.
On exit: 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.
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if IFAIL0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: G01TEF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
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
On entry, array size=value.
Constraint: LTAIL>0.
IFAIL=3
On entry, array size=value.
Constraint: LP>0.
IFAIL=4
On entry, array size=value.
Constraint: LA>0.
IFAIL=5
On entry, array size=value.
Constraint: LB>0.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

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

8  Parallelism and Performance

Not applicable.

9  Further Comments

The typical timing will be several times that of G01SEF and will be very dependent on the input parameter values. See G01SEF for further comments on timings.

10  Example

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

10.1  Program Text

Program Text (g01tefe.f90)

10.2  Program Data

Program Data (g01tefe.d)

10.3  Program Results

Program Results (g01tefe.r)


G01TEF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015