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

# Syntax

C#
```public static double g01hb(
string tail,
int n,
double[] a,
double[] b,
double[] xmu,
double[,] sig,
double tol,
out int ifail
)```
Visual Basic
```Public Shared Function g01hb ( _
tail As String, _
n As Integer, _
a As Double(), _
b As Double(), _
xmu As Double(), _
sig As Double(,), _
tol As Double, _
<OutAttribute> ByRef ifail As Integer _
) As Double```
Visual C++
```public:
static double g01hb(
String^ tail,
int n,
array<double>^ a,
array<double>^ b,
array<double>^ xmu,
array<double,2>^ sig,
double tol,
[OutAttribute] int% ifail
)```
F#
```static member g01hb :
tail : string *
n : int *
a : float[] *
b : float[] *
xmu : float[] *
sig : float[,] *
tol : float *
ifail : int byref -> float
```

#### Parameters

tail
Type: System..::..String
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"}$.
n
Type: System..::..Int32
On entry: $n$, the number of dimensions.
Constraint: $1\le {\mathbf{n}}\le 10$.
a
Type: array<System..::..Double>[]()[][]
An array of size [n]
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.
b
Type: array<System..::..Double>[]()[][]
An array of size [n]
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}-1\right]<{\mathbf{b}}\left[\mathit{i}-1\right]$, for $\mathit{i}=1,2,\dots ,n$.
xmu
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: $\mu$, the mean vector of the multivariate Normal distribution.
sig
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
On entry: $\Sigma$, the variance-covariance matrix of the multivariate Normal distribution. Only the lower triangle is referenced.
Constraint: $\Sigma$ must be positive definite.
tol
Type: System..::..Double
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 [Accuracy].
If $n=1$, tol is not referenced.
Suggested value: ${\mathbf{tol}}=0.0001$.
Constraint: if ${\mathbf{n}}>1$, ${\mathbf{tol}}>0.0$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

#### Return Value

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

# 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/2nΣ-1/2exp-12X-μTΣ-1X-μ.$
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 g01ha and numerical integration is then used over the remaining $n-2$ dimensions. In the case of $n=3$, d01aj is used and for $n>3$ d01fc is used.
To evaluate the probability for $n=1$ a direct call to g01ea is made and for $n=2$ calls to g01ha are made.

# References

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

# Error Indicators and Warnings

Note: g01hb may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
If on exit ${\mathbf{ifail}}={1}$${2}$ or ${3}$, then g01hb returns zero.
Some error messages may refer to parameters that are dropped from this interface (LDSIG) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}<1$, or ${\mathbf{n}}>10$, 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-1\right]\ge {\mathbf{b}}\left[i-1\right]$, for some $i=0,1,\dots ,n-1$.
${\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$.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

The accuracy should be as specified by tol. When on exit ${\mathbf{ifail}}={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.

# Parallelism and Performance

None.

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}$.

# Example

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

Example program (C#): g01hbe.cs

Example program data: g01hbe.d

Example program results: g01hbe.r