g01 Chapter Contents
g01 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_multi_normal (g01hbc)

## 1  Purpose

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

## 2  Specification

 #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)

## 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 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.
Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin

## 5  Arguments

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: the maximum number of sub-intervals or integrand evaluations.
If $n=3$, then the maximum number of sub-intervals used by nag_1d_quad_gen_1 (d01sjc) is maxpts/4. Note however increasing maxpts above 1000 will not increase the maximum number of sub-intervals above 250.
If $n>3$ the maximum number of integrand evaluations used by nag_multid_quad_adapt_1 (d01wcc) is $\alpha$(maxpts/$n-1$), where $\alpha ={2}^{n-2}+2{\left(n-2\right)}^{2}+2\left(n-2\right)+1$.
If $n=1$ or 2, then maxpts will not be used.
Suggested value: 2000 if $n>3$ and 1000 if $n=3$.
Constraint: if ${\mathbf{n}}\ge 3$, ${\mathbf{maxpts}}\ge 4×{\mathbf{n}}$.
10:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error 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 3.2.1.2 in the Essential Introduction for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT_ARG_CONS
On entry, ${\mathbf{maxpts}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{n}}\ge 3$, ${\mathbf{maxpts}}\ge 4×{\mathbf{n}}$.
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 3.6.6 in the Essential Introduction for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 3.6.5 in the Essential Introduction 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.

## 7  Accuracy

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.

## 8  Parallelism 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.

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

## 10  Example

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

### 10.1  Program Text

Program Text (g01hbce.c)

### 10.2  Program Data

Program Data (g01hbce.d)

### 10.3  Program Results

Program Results (g01hbce.r)