nag_deviates_beta (g01fec) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_deviates_beta (g01fec)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

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

2  Specification

#include <nag.h>
#include <nagg01.h>
double  nag_deviates_beta (double p, double a, double b, double tol, NagError *fail)

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
PBβp:a,b=p=Γa+b ΓaΓb 0βpBa-11-Bb-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β=PBβ: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:     pdoubleInput
On entry: p, the lower tail probability from the required beta distribution.
Constraint: 0.0p1.0.
2:     adoubleInput
On entry: a, the first parameter of the required beta distribution.
Constraint: 0.0<a106.
3:     bdoubleInput
On entry: b, the second parameter of the required beta distribution.
Constraint: 0.0<b106.
4:     toldoubleInput
On entry: the relative accuracy required by you in the result. If nag_deviates_beta (g01fec) is entered with tol greater than or equal to 1.0 or less than 10×machine precision (see nag_machine_precision (X02AJC)), then the value of 10×machine precision is used instead.
5:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

On any of the error conditions listed below except fail.code= NE_RES_NOT_ACC or NE_SOL_NOT_CONV nag_deviates_beta (g01fec) returns 0.0 .
NE_ALLOC_FAIL
Dynamic memory allocation failed.
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.
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

Not applicable.

9  Further Comments

The typical timing will be several times that of nag_prob_beta_dist (g01eec) and will be very dependent on the input argument values. See nag_prob_beta_dist (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)


nag_deviates_beta (g01fec) (PDF version)
g01 Chapter Contents
g01 Chapter Introduction
NAG Library Manual

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