# NAG FL Interfaceg01sef (prob_​beta_​vector)

## 1Purpose

g01sef computes a number of lower or upper tail probabilities for the beta distribution.

## 2Specification

Fortran Interface
 Subroutine g01sef ( tail, beta, la, a, lb, b, p,
 Integer, Intent (In) :: ltail, lbeta, la, lb Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: ivalid(*) Real (Kind=nag_wp), Intent (In) :: beta(lbeta), a(la), b(lb) Real (Kind=nag_wp), Intent (Out) :: p(*) Character (1), Intent (In) :: tail(ltail)
#include <nag.h>
 void g01sef_ (const Integer *ltail, const char tail[], const Integer *lbeta, const double beta[], const Integer *la, const double a[], const Integer *lb, const double b[], double p[], Integer ivalid[], Integer *ifail, const Charlen length_tail)
The routine may be called by the names g01sef or nagf_stat_prob_beta_vector.

## 3Description

The lower tail probability, $P\left({B}_{i}\le {\beta }_{i}:{a}_{i},{b}_{i}\right)$ is defined by
 $P Bi ≤ βi :ai,bi = Γ ai + bi Γ ai Γ bi ∫ 0 βi Bi ai-1 1-Bi bi-1 dBi = Iβi ai,bi , 0 ≤ βi ≤ 1 ; ai , bi > 0 .$
The function ${I}_{{\beta }_{i}}\left({a}_{i},{b}_{i}\right)$, also known as the incomplete beta function is calculated using s14ccf.
The input arrays to this routine 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 Section 2.6 in the G01 Chapter Introduction for further information.

## 4References

NIST Digital Library of Mathematical Functions
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth
Majumder K L and Bhattacharjee G P (1973) Algorithm AS 63. The incomplete beta integral Appl. Statist. 22 409–411

## 5Arguments

1: $\mathbf{ltail}$Integer Input
On entry: the length of the array tail.
Constraint: ${\mathbf{ltail}}>0$.
2: $\mathbf{tail}\left({\mathbf{ltail}}\right)$Character(1) array Input
On entry: indicates whether a lower or upper tail probabilities are required. For , for $\mathit{i}=1,2,\dots ,\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ltail}},{\mathbf{lbeta}},{\mathbf{la}},{\mathbf{lb}}\right)$:
${\mathbf{tail}}\left(j\right)=\text{'L'}$
The lower tail probability is returned, i.e., ${p}_{i}=P\left({B}_{i}\le {\beta }_{i}:{a}_{i},{b}_{i}\right)$.
${\mathbf{tail}}\left(j\right)=\text{'U'}$
The upper tail probability is returned, i.e., ${p}_{i}=P\left({B}_{i}\ge {\beta }_{i}:{a}_{i},{b}_{i}\right)$.
Constraint: ${\mathbf{tail}}\left(\mathit{j}\right)=\text{'L'}$ or $\text{'U'}$, for $\mathit{j}=1,2,\dots ,{\mathbf{ltail}}$.
3: $\mathbf{lbeta}$Integer Input
On entry: the length of the array beta.
Constraint: ${\mathbf{lbeta}}>0$.
4: $\mathbf{beta}\left({\mathbf{lbeta}}\right)$Real (Kind=nag_wp) array Input
On entry: ${\beta }_{i}$, the value of the beta variate with ${\beta }_{i}={\mathbf{beta}}\left(j\right)$, .
Constraint: $0.0\le {\mathbf{beta}}\left(\mathit{j}\right)\le 1.0$, for $\mathit{j}=1,2,\dots ,{\mathbf{lbeta}}$.
5: $\mathbf{la}$Integer Input
On entry: the length of the array a.
Constraint: ${\mathbf{la}}>0$.
6: $\mathbf{a}\left({\mathbf{la}}\right)$Real (Kind=nag_wp) array Input
On entry: ${a}_{i}$, the first parameter of the required beta distribution with ${a}_{i}={\mathbf{a}}\left(j\right)$, .
Constraint: ${\mathbf{a}}\left(\mathit{j}\right)>0.0$, for $\mathit{j}=1,2,\dots ,{\mathbf{la}}$.
7: $\mathbf{lb}$Integer Input
On entry: the length of the array b.
Constraint: ${\mathbf{lb}}>0$.
8: $\mathbf{b}\left({\mathbf{lb}}\right)$Real (Kind=nag_wp) array Input
On entry: ${b}_{i}$, the second parameter of the required beta distribution with ${b}_{i}={\mathbf{b}}\left(j\right)$, .
Constraint: ${\mathbf{b}}\left(\mathit{j}\right)>0.0$, for $\mathit{j}=1,2,\dots ,{\mathbf{lb}}$.
9: $\mathbf{p}\left(*\right)$Real (Kind=nag_wp) array Output
Note: the dimension of the array p must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ltail}},{\mathbf{lbeta}},{\mathbf{la}},{\mathbf{lb}}\right)$.
On exit: ${p}_{i}$, the probabilities for the beta distribution.
10: $\mathbf{ivalid}\left(*\right)$Integer array Output
Note: the dimension of the array ivalid must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ltail}},{\mathbf{lbeta}},{\mathbf{la}},{\mathbf{lb}}\right)$.
On exit: ${\mathbf{ivalid}}\left(i\right)$ indicates any errors with the input arguments, with
${\mathbf{ivalid}}\left(i\right)=0$
No error.
${\mathbf{ivalid}}\left(i\right)=1$
On entry, invalid value supplied in tail when calculating ${p}_{i}$.
${\mathbf{ivalid}}\left(i\right)=2$
On entry, ${\beta }_{i}<0.0$, or, ${\beta }_{i}>1.0$.
${\mathbf{ivalid}}\left(i\right)=3$
On entry, ${a}_{i}\le 0.0$, or, ${b}_{i}\le 0.0$.
11: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value 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 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).
Errors or warnings detected by the routine:
Note: in some cases g01sef may return useful information.
${\mathbf{ifail}}=1$
On entry, at least one value of beta, a, b or tail was invalid.
${\mathbf{ifail}}=2$
On entry, $\text{array size}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ltail}}>0$.
${\mathbf{ifail}}=3$
On entry, $\text{array size}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lbeta}}>0$.
${\mathbf{ifail}}=4$
On entry, $\text{array size}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{la}}>0$.
${\mathbf{ifail}}=5$
On entry, $\text{array size}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lb}}>0$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface 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

g01sef is not threaded in any implementation.

None.

## 10Example

This example reads values from a number of beta distributions and computes the associated lower tail probabilities.

### 10.1Program Text

Program Text (g01sefe.f90)

### 10.2Program Data

Program Data (g01sefe.d)

### 10.3Program Results

Program Results (g01sefe.r)