NAG CL Interface
g01fec (inv_​cdf_​beta)

Settings help

CL Name Style:


1 Purpose

g01fec returns the deviate associated with the given lower tail probability of the beta distribution.

2 Specification

#include <nag.h>
double  g01fec (double p, double a, double b, double tol, NagError *fail)
The function may be called by the names: g01fec, nag_stat_inv_cdf_beta or nag_deviates_beta.

3 Description

The deviate, βp, associated with the lower tail probability, p, of the beta distribution with parameters a and b is defined as the solution to
P(Bβp:a,b)=p=Γ(a+b) Γ(a)Γ(b) 0βpBa-1(1-B)b-1dB,  0βp1;a,b>0.  
The algorithm is a modified version of the Newton–Raphson method, following closely that of Cran et al. (1977).
An initial approximation, β0, to βp is found (see Cran et al. (1977)), and the Newton–Raphson iteration
βi=βi-1-f(βi-1) f(βi-1) ,  
where f(β)=P(Bβ:a,b)-p is used, with modifications to ensure that β remains in the range (0,1).

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 Arguments

1: p double Input
On entry: p, the lower tail probability from the required beta distribution.
Constraint: 0.0p1.0.
2: a double Input
On entry: a, the first parameter of the required beta distribution.
Constraint: 0.0<a106.
3: b double Input
On entry: b, the second parameter of the required beta distribution.
Constraint: 0.0<b106.
4: tol double Input
On entry: the relative accuracy required by you in the result. If g01fec is entered with tol greater than or equal to 1.0 or less than 10×machine precision (see X02AJC), the value of 10×machine precision is used instead.
5: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

If on exit fail.code= NE_REAL_ARG_GT, NE_REAL_ARG_LE or NE_REAL_ARG_LT, then g01fec returns 0.0.
On any of the error conditions listed below except fail.code= NE_RES_NOT_ACC or NE_SOL_NOT_CONV g01fec returns 0.0 .
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL_ARG_GT
On entry, a=value and b=value.
Constraint: a106.
On entry, a=value and b=value.
Constraint: b106.
On entry, p=value.
Constraint: p1.0.
NE_REAL_ARG_LE
On entry, a=value and b=value.
Constraint: a>0.0.
On entry, a=value and b=value.
Constraint: b>0.0.
NE_REAL_ARG_LT
On entry, p=value.
Constraint: p0.0.
NE_RES_NOT_ACC
The requested accuracy has not been achieved. Use a larger value of tol. There is doubt concerning the accuracy of the computed result. 100 iterations of the Newton–Raphson method have been performed without satisfying the accuracy criterion (see Section 9). The result should be a reasonable approximation of the solution.
NE_SOL_NOT_CONV
The solution has failed to converge. However, the result should be a reasonable approximation. Requested accuracy not achieved when calculating beta probability. You should try setting tol larger.

7 Accuracy

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

8 Parallelism and Performance

g01fec is not threaded in any implementation.

9 Further Comments

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

10 Example

This example reads lower tail probabilities for several beta distributions and calculates and prints the corresponding deviates until the end of data is reached.

10.1 Program Text

Program Text (g01fece.c)

10.2 Program Data

Program Data (g01fece.d)

10.3 Program Results

Program Results (g01fece.r)