# NAG C Library Function Document

## 1Purpose

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

## 2Specification

 #include #include
 double nag_multi_normal (Nag_TailProbability tail, Integer n, const double a[], const double b[], const double mean[], const double sigma[], Integer tdsig, double tol, Integer maxpts, NagError *fail)

## 3Description

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 nag_bivariate_normal_dist (g01hac) and numerical integration is then used over the remaining $n-2$ dimensions. In the case of $n=3$, nag_1d_quad_gen_1 (d01sjc) is used and for $n>3$ nag_multid_quad_adapt_1 (d01wcc) is used.
To evaluate the probability for $n=1$ a direct call to nag_prob_normal (g01eac) is made and for $n=2$ calls to nag_bivariate_normal_dist (g01hac) are made.

## 4References

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

## 5Arguments

1:    $\mathbf{tail}$Nag_TailProbabilityInput
On entry: indicates which probability is to be returned.
${\mathbf{tail}}=\mathrm{Nag_LowerTail}$
The lower tail probability is returned.
${\mathbf{tail}}=\mathrm{Nag_UpperTail}$
The upper tail probability is returned.
${\mathbf{tail}}=\mathrm{Nag_Central}$
The central probability is returned.
Constraint: ${\mathbf{tail}}=\mathrm{Nag_LowerTail}$, $\mathrm{Nag_UpperTail}$ or $\mathrm{Nag_Central}$.
2:    $\mathbf{n}$IntegerInput
On entry: $n$, the number of dimensions.
Constraint: $1\le {\mathbf{n}}\le 10$.
3:    $\mathbf{a}\left[{\mathbf{n}}\right]$const doubleInput
On entry: if ${\mathbf{tail}}=\mathrm{Nag_Central}$ or $\mathrm{Nag_UpperTail}$, the lower bounds, ${a}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
If ${\mathbf{tail}}=\mathrm{Nag_LowerTail}$, a is not referenced.
4:    $\mathbf{b}\left[{\mathbf{n}}\right]$const doubleInput
On entry: if ${\mathbf{tail}}=\mathrm{Nag_Central}$ or $\mathrm{Nag_LowerTail}$, the upper bounds, ${b}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
If ${\mathbf{tail}}=\mathrm{Nag_UpperTail}$, b is not referenced.
Constraint: if ${\mathbf{tail}}=\mathrm{Nag_Central}$, ${\mathbf{a}}\left[\mathit{i}-1\right]<{\mathbf{b}}\left[\mathit{i}-1\right]$, for $\mathit{i}=1,2,\dots ,n$.
5:    $\mathbf{mean}\left[{\mathbf{n}}\right]$const doubleInput
On entry: $\mu$, the mean vector of the multivariate Normal distribution.
6:    $\mathbf{sigma}\left[{\mathbf{n}}×{\mathbf{tdsig}}\right]$const doubleInput
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{sigma}}\left[\left(i-1\right)×{\mathbf{tdsig}}+j-1\right]$.
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:    $\mathbf{tdsig}$IntegerInput
On entry: the stride separating matrix column elements in the array sigma.
Constraint: ${\mathbf{tdsig}}\ge {\mathbf{n}}$.
8:    $\mathbf{tol}$doubleInput
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:    $\mathbf{maxpts}$IntegerInput
On entry: this argument is no longer referenced, but is included for backwards compatability.
10:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ${\mathbf{tdsig}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{tdsig}}\ge {\mathbf{n}}$.
NE_2_REAL_ARRAYS_CONS
On entry, the $〈\mathit{\text{value}}〉$ value in b is less than or equal to the corresponding value in a.
NE_ACC
Full accuracy not achieved, relative accuracy $\text{}=〈\mathit{\text{value}}〉$. A larger value of tol can be tried or the length of the workspace increased. The returned value is an approximation to the required result.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_BAD_PARAM
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT_ARG_CONS
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: $1\le {\mathbf{n}}\le 10$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_POS_DEF
On entry, sigma is not positive definite.
NE_REAL_ARG_CONS
On entry, ${\mathbf{tol}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{tol}}>0.0$.
NE_ROUND_OFF
Accuracy requested by tol is too strict: ${\mathbf{tol}}=〈\mathit{\text{value}}〉$. Round-off error has prevented the requested accuracy from being achieved; a larger value of tol can be tried. The returned value will be an approximation to the required result.

## 7Accuracy

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

## 8Parallelism and Performance

nag_multi_normal (g01hbc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_multi_normal (g01hbc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

## 9Further Comments

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

## 10Example

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

### 10.1Program Text

Program Text (g01hbce.c)

### 10.2Program Data

Program Data (g01hbce.d)

### 10.3Program Results

Program Results (g01hbce.r)