G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01HBF

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

G01HBF returns the upper tail, lower tail or central probability associated with a multivariate Normal distribution of up to ten dimensions.

## 2  Specification

 FUNCTION G01HBF ( TAIL, N, A, B, XMU, SIG, LDSIG, TOL, WK, LWK, IFAIL)
 REAL (KIND=nag_wp) G01HBF
 INTEGER N, LDSIG, LWK, IFAIL REAL (KIND=nag_wp) A(N), B(N), XMU(N), SIG(LDSIG,N), TOL, WK(LWK) CHARACTER(1) TAIL

## 3  Description

Let the vector random variable $X={\left({X}_{1},{X}_{2},\dots ,{X}_{n}\right)}^{\mathrm{T}}$ follow an $n$-dimensional multivariate Normal distribution with mean vector $\mu$ and $n$ by $n$ variance-covariance matrix $\Sigma$, then the probability density function, $f\left(X:\mu ,\Sigma \right)$, is given by
 $fX:μ,Σ = 2π - 1/2 n Σ -1/2 exp -12 X-μT Σ-1 X-μ .$
The lower tail probability is defined by:
 $PX1≤b1,…,Xn≤bn: μ ,Σ=∫-∞ b1⋯∫-∞ bnfX : μ ,Σ dXn⋯dX1.$
The upper tail probability is defined by:
 $PX1≥a1,…,Xn≥an:μ,Σ=∫a1∞⋯∫an∞fX:μ,ΣdXn⋯dX1.$
The central probability is defined by:
 $Pa1≤X1≤b1,…,an≤Xn≤bn: μ ,Σ=∫a1b1⋯∫anbnfX : μ ,Σ dXn⋯dX1.$
To evaluate the probability for $n\ge 3$, the probability density function of ${X}_{1},{X}_{2},\dots ,{X}_{n}$ is considered as the product of the conditional probability of ${X}_{1},{X}_{2},\dots ,{X}_{n-2}$ given ${X}_{n-1}$ and ${X}_{n}$ and the marginal bivariate Normal distribution of ${X}_{n-1}$ and ${X}_{n}$. The bivariate Normal probability can be evaluated as described in G01HAF and numerical integration is then used over the remaining $n-2$ dimensions. In the case of $n=3$, D01AJF is used and for $n>3$ D01FCF is used.
To evaluate the probability for $n=1$ a direct call to G01EAF is made and for $n=2$ calls to G01HAF are made.

## 4  References

Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin

## 5  Parameters

1:     TAIL – CHARACTER(1)Input
On entry: indicates which probability is to be returned.
${\mathbf{TAIL}}=\text{'L'}$
The lower tail probability is returned.
${\mathbf{TAIL}}=\text{'U'}$
The upper tail probability is returned.
${\mathbf{TAIL}}=\text{'C'}$
The central probability is returned.
Constraint: ${\mathbf{TAIL}}=\text{'L'}$, $\text{'U'}$ or $\text{'C'}$.
2:     N – INTEGERInput
On entry: $n$, the number of dimensions.
Constraint: $1\le {\mathbf{N}}\le 10$.
3:     A(N) – REAL (KIND=nag_wp) arrayInput
On entry: if ${\mathbf{TAIL}}=\text{'C'}$ or $\text{'U'}$, the lower bounds, ${a}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
If ${\mathbf{TAIL}}=\text{'L'}$, A is not referenced.
4:     B(N) – REAL (KIND=nag_wp) arrayInput
On entry: if ${\mathbf{TAIL}}=\text{'C'}$ or $\text{'L'}$, the upper bounds, ${b}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
If ${\mathbf{TAIL}}=\text{'U'}$ B, is not referenced.
Constraint: if ${\mathbf{TAIL}}=\text{'C'}$, ${\mathbf{A}}\left(\mathit{i}\right)<{\mathbf{B}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,n$.
5:     XMU(N) – REAL (KIND=nag_wp) arrayInput
On entry: $\mu$, the mean vector of the multivariate Normal distribution.
6:     SIG(LDSIG,N) – REAL (KIND=nag_wp) arrayInput
On entry: $\Sigma$, the variance-covariance matrix of the multivariate Normal distribution. Only the lower triangle is referenced.
Constraint: $\Sigma$ must be positive definite.
7:     LDSIG – INTEGERInput
On entry: the first dimension of the array SIG as declared in the (sub)program from which G01HBF is called.
Constraint: ${\mathbf{LDSIG}}\ge {\mathbf{N}}$.
8:     TOL – REAL (KIND=nag_wp)Input
On entry: if $n>2$ the relative accuracy required for the probability, and if the upper or the lower tail probability is requested then TOL is also used to determine the cut-off points, see Section 7.
If $n=1$, TOL is not referenced.
Suggested value: ${\mathbf{TOL}}=0.0001$.
Constraint: if ${\mathbf{N}}>1$, ${\mathbf{TOL}}>0.0$.
9:     WK(LWK) – REAL (KIND=nag_wp) arrayWorkspace
10:   LWK – INTEGERInput
On entry: the length of workspace provided in array WK. This workspace is used by the numerical integration routines D01AJF for $n=3$ and D01FCF for $n>3$.
If $n=3$, then the maximum number of sub-intervals used by D01AJF is ${\mathbf{LWK}}/4$. Note, however, increasing LWK above $1000$ will not increase the maximum number of sub-intervals above $250$.
If $n>3$ the maximum number of integrand evaluations used by D01FCF is $\alpha \left({\mathbf{LWK}}/n-1\right)$, where $\alpha ={2}^{n-2}+2{\left(n-2\right)}^{2}+2\left(n-2\right)+1$.
If $n=1\text{​ or ​}2$, then WK will not be used.
Suggested value: 2000 if $n>3$ and $1000$ if $n=3$.
Constraints:
• if ${\mathbf{N}}=1$, ${\mathbf{LWK}}\ge 1$;
• if ${\mathbf{N}}\ge 3$, ${\mathbf{LWK}}\ge 4×{\mathbf{N}}$.
11:   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, because for this routine the values of the output parameters 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).

## 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).
Note: G01HBF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
If on exit ${\mathbf{IFAIL}}={\mathbf{1}}$, ${\mathbf{2}}$ or ${\mathbf{3}}$, then G01HBF returns zero.
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{N}}<1$, or ${\mathbf{N}}>10$, or ${\mathbf{LDSIG}}<{\mathbf{N}}$, or ${\mathbf{TAIL}}\ne \text{'L'}$, $\text{'U'}$ or $\text{'C'}$, or ${\mathbf{N}}>1$ and ${\mathbf{TOL}}\le 0.0$, or LWK is too small.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{TAIL}}=\text{'C'}$ and ${\mathbf{A}}\left(i\right)\ge {\mathbf{B}}\left(i\right)$, for some $i=1,2,\dots ,n$.
${\mathbf{IFAIL}}=3$
 On entry, $\Sigma$ is not positive definite, i.e., is not a correct variance-covariance matrix.
${\mathbf{IFAIL}}=4$
The requested accuracy has not been achieved, a larger value of TOL should be tried or the length of the workspace should be increased. The returned value will be an approximation to the required result.
${\mathbf{IFAIL}}=5$
Round-off error prevents the requested accuracy from being achieved; a larger value of TOL should be tried. The returned value will be an approximation to the required result. This error will only occur if $n=3$.

## 7  Accuracy

The accuracy should be as specified by TOL. When on exit ${\mathbf{IFAIL}}={\mathbf{4}}$ the approximate accuracy achieved is given in the error message. For the upper and lower tail probabilities the infinite limits are approximated by cut-off points for the $n-2$ dimensions over which the numerical integration takes place; these cut-off points are given by ${\Phi }^{-1}\left({\mathbf{TOL}}/\left(10×n\right)\right)$, where ${\Phi }^{-1}$ is the inverse univariate Normal distribution function.

The time taken is related to the number of dimensions, the range over which the integration takes place (${b}_{i}-{a}_{i}$, for $\mathit{i}=1,2,\dots ,n$) and the value of $\Sigma$ as well as the accuracy required. As the numerical integration does not take place over the last two dimensions speed may be improved by arranging $X$ so that the largest ranges of integration are for ${X}_{n-1}$ and ${X}_{n}$.

## 9  Example

This example reads in the mean and covariance matrix for a multivariate Normal distribution and computes and prints the associated central probability.

### 9.1  Program Text

Program Text (g01hbfe.f90)

### 9.2  Program Data

Program Data (g01hbfe.d)

### 9.3  Program Results

Program Results (g01hbfe.r)