G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01TBF

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.

## 1  Purpose

G01TBF returns a number of deviates associated with given probabilities of Student's $t$-distribution with real degrees of freedom.

## 2  Specification

 SUBROUTINE G01TBF ( LTAIL, TAIL, LP, P, LDF, DF, T, IVALID, IFAIL)
 INTEGER LTAIL, LP, LDF, IVALID(*), IFAIL REAL (KIND=nag_wp) P(LP), DF(LDF), T(*) CHARACTER(1) TAIL(LTAIL)

## 3  Description

The deviate, ${t}_{{p}_{i}}$ associated with the lower tail probability, ${p}_{i}$, of the Student's $t$-distribution with ${\nu }_{i}$ degrees of freedom is defined as the solution to
 $P Ti < tpi :νi = pi = Γ νi+1 / 2 νiπ Γ νi/2 ∫ -∞ tpi 1 + Ti2 νi - νi+1 / 2 d Ti , νi ≥ 1 ; ​ -∞ < tpi < ∞ .$
For ${\nu }_{i}=1\text{​ or ​}2$ the integral equation is easily solved for ${t}_{{p}_{i}}$.
For other values of ${\nu }_{i}<3$ a transformation to the beta distribution is used and the result obtained from G01FEF.
For ${\nu }_{i}\ge 3$ an inverse asymptotic expansion of Cornish–Fisher type is used. The algorithm is described by Hill (1970).
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

Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth
Hill G W (1970) Student's $t$-distribution Comm. ACM 13(10) 617–619

## 5  Parameters

1:     $\mathrm{LTAIL}$ – INTEGERInput
On entry: the length of the array TAIL.
Constraint: ${\mathbf{LTAIL}}>0$.
2:     $\mathrm{TAIL}\left({\mathbf{LTAIL}}\right)$ – CHARACTER(1) arrayInput
On entry: indicates which tail the supplied probabilities represent. For , for $\mathit{i}=1,2,\dots ,\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{LTAIL}},{\mathbf{LP}},{\mathbf{LDF}}\right)$:
${\mathbf{TAIL}}\left(j\right)=\text{'L'}$
The lower tail probability, i.e., ${p}_{i}=P\left({T}_{i}\le {t}_{{p}_{i}}:{\nu }_{i}\right)$.
${\mathbf{TAIL}}\left(j\right)=\text{'U'}$
The upper tail probability, i.e., ${p}_{i}=P\left({T}_{i}\ge {t}_{{p}_{i}}:{\nu }_{i}\right)$.
${\mathbf{TAIL}}\left(j\right)=\text{'C'}$
The two tail (confidence interval) probability,
i.e., ${p}_{i}=P\left({T}_{i}\le \left|{t}_{{p}_{i}}\right|:{\nu }_{i}\right)-P\left({T}_{i}\le -\left|{t}_{{p}_{i}}\right|:{\nu }_{i}\right)$.
${\mathbf{TAIL}}\left(j\right)=\text{'S'}$
The two tail (significance level) probability,
i.e., ${p}_{i}=P\left({T}_{i}\ge \left|{t}_{{p}_{i}}\right|:{\nu }_{i}\right)+P\left({T}_{i}\le -\left|{t}_{{p}_{i}}\right|:{\nu }_{i}\right)$.
Constraint: ${\mathbf{TAIL}}\left(\mathit{j}\right)=\text{'L'}$, $\text{'U'}$, $\text{'C'}$ or $\text{'S'}$, for $\mathit{j}=1,2,\dots ,{\mathbf{LTAIL}}$.
3:     $\mathrm{LP}$ – INTEGERInput
On entry: the length of the array P.
Constraint: ${\mathbf{LP}}>0$.
4:     $\mathrm{P}\left({\mathbf{LP}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: ${p}_{i}$, the probability of the required Student's $t$-distribution as defined by TAIL with ${p}_{i}={\mathbf{P}}\left(j\right)$, .
Constraint: $0.0<{\mathbf{P}}\left(\mathit{j}\right)<1.0$, for $\mathit{j}=1,2,\dots ,{\mathbf{LP}}$.
5:     $\mathrm{LDF}$ – INTEGERInput
On entry: the length of the array DF.
Constraint: ${\mathbf{LDF}}>0$.
6:     $\mathrm{DF}\left({\mathbf{LDF}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: ${\nu }_{i}$, the degrees of freedom of the Student's $t$-distribution with ${\nu }_{i}={\mathbf{DF}}\left(j\right)$, .
Constraint: ${\mathbf{DF}}\left(\mathit{j}\right)\ge 1.0$, for $\mathit{j}=1,2,\dots ,{\mathbf{LDF}}$.
7:     $\mathrm{T}\left(*\right)$ – REAL (KIND=nag_wp) arrayOutput
Note: the dimension of the array T must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{LTAIL}},{\mathbf{LP}},{\mathbf{LDF}}\right)$.
On exit: ${t}_{{p}_{i}}$, the deviates for the Student's $t$-distribution.
8:     $\mathrm{IVALID}\left(*\right)$ – INTEGER arrayOutput
Note: the dimension of the array IVALID must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{LTAIL}},{\mathbf{LP}},{\mathbf{LDF}}\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 ${t}_{{p}_{i}}$.
${\mathbf{IVALID}}\left(i\right)=2$
 On entry, ${p}_{i}\le 0.0$, or ${p}_{i}\ge 1.0$.
${\mathbf{IVALID}}\left(i\right)=3$
 On entry, ${\nu }_{i}<1.0$.
${\mathbf{IVALID}}\left(i\right)=4$
The solution has failed to converge. The result returned should represent an approximation to the solution.
9:     $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ 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\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
On entry, at least one value of TAIL, P or DF was invalid, or the solution failed to converge.
${\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{LP}}>0$.
${\mathbf{IFAIL}}=4$
On entry, $\text{array size}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LDF}}>0$.
${\mathbf{IFAIL}}=-99$
See Section 3.8 in the Essential Introduction for further information.
${\mathbf{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.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

## 7  Accuracy

The results should be accurate to five significant digits, for most parameter values. The error behaviour for various parameter values is discussed in Hill (1970).

## 8  Parallelism and Performance

Not applicable.

The value ${t}_{{p}_{i}}$ may be calculated by using a transformation to the beta distribution and calling G01TEF. This routine allows you to set the required accuracy.

## 10  Example

This example reads the probability, the tail that probability represents and the degrees of freedom for a number of Student's $t$-distributions and computes the corresponding deviates.

### 10.1  Program Text

Program Text (g01tbfe.f90)

### 10.2  Program Data

Program Data (g01tbfe.d)

### 10.3  Program Results

Program Results (g01tbfe.r)