# NAG Library Routine Document

## 1Purpose

g01eef computes the upper and lower tail probabilities and the probability density function of the beta distribution with parameters $a$ and $b$.

## 2Specification

Fortran Interface
 Subroutine g01eef ( x, a, b, tol, p, q, pdf,
 Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x, a, b, tol Real (Kind=nag_wp), Intent (Out) :: p, q, pdf
#include nagmk26.h
 void g01eef_ (const double *x, const double *a, const double *b, const double *tol, double *p, double *q, double *pdf, Integer *ifail)

## 3Description

The probability density function of the beta distribution with parameters $a$ and $b$ is:
 $fB:a,b=Γa+b ΓaΓb Ba-11-Bb-1, 0≤B≤1;a,b>0.$
The lower tail probability, $P\left(B\le \beta :a,b\right)$ is defined by
 $PB≤β:a,b=Γa+b ΓaΓb ∫0βBa-11-Bb-1dB=Iβa,b, 0≤β≤1;a,b>0.$
The function ${I}_{x}\left(a,b\right)$, also known as the incomplete beta function is calculated using s14ccf.
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth

## 5Arguments

1:     $\mathbf{x}$ – Real (Kind=nag_wp)Input
On entry: $\beta$, the value of the beta variate.
Constraint: $0.0\le {\mathbf{x}}\le 1.0$.
2:     $\mathbf{a}$ – Real (Kind=nag_wp)Input
On entry: $a$, the first parameter of the required beta distribution.
Constraint: $0.0<{\mathbf{a}}\le {10}^{6}$.
3:     $\mathbf{b}$ – Real (Kind=nag_wp)Input
On entry: $b$, the second parameter of the required beta distribution.
Constraint: $0.0<{\mathbf{b}}\le {10}^{6}$.
4:     $\mathbf{tol}$ – Real (Kind=nag_wp)Input
On entry: this argument is no longer referenced, but is included for backwards compatability.
5:     $\mathbf{p}$ – Real (Kind=nag_wp)Output
On exit: the lower tail probability, $P\left(B\le \beta :a,b\right)$.
6:     $\mathbf{q}$ – Real (Kind=nag_wp)Output
On exit: the upper tail probability, $P\left(B\ge \beta :a,b\right)$.
7:     $\mathbf{pdf}$ – Real (Kind=nag_wp)Output
On exit: the probability density function, $f\left(B:a,b\right)$.
8:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ 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 arguments may be useful even if ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value $-\mathbf{1}\text{​ or ​}1$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Note: g01eef may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{x}}\le 1.0$.
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{x}}\ge 0.0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{a}}=〈\mathit{\text{value}}〉$ and ${\mathbf{b}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{a}}>0.0$.
On entry, ${\mathbf{a}}=〈\mathit{\text{value}}〉$ and ${\mathbf{b}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{b}}>0.0$.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

The accuracy is limited by the error in the incomplete beta function. See Section 7 in s14ccf for further details.

## 8Parallelism and Performance

g01eef is not threaded in any implementation.

None.

## 10Example

This example reads values from a number of beta distributions and computes the associated upper and lower tail probabilities and the corresponding value of the probability density function.

### 10.1Program Text

Program Text (g01eefe.f90)

### 10.2Program Data

Program Data (g01eefe.d)

### 10.3Program Results

Program Results (g01eefe.r)

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