g02hb finds, for a real matrix $X$ of full column rank, a lower triangular matrix $A$ such that ${\left({A}^{\mathrm{T}}A\right)}^{-1}$ is proportional to a robust estimate of the covariance of the variables. g02hb is intended for the calculation of weights of bounded influence regression using g02hd.

# Syntax

C#
```public static void g02hb(
G02..::..G02HB_UCV ucv,
int n,
int m,
double[,] x,
double[] a,
double[] z,
double bl,
double bd,
double tol,
int maxit,
int nitmon,
out int nit,
out int ifail
)```
Visual Basic
```Public Shared Sub g02hb ( _
ucv As G02..::..G02HB_UCV, _
n As Integer, _
m As Integer, _
x As Double(,), _
a As Double(), _
z As Double(), _
bl As Double, _
bd As Double, _
tol As Double, _
maxit As Integer, _
nitmon As Integer, _
<OutAttribute> ByRef nit As Integer, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g02hb(
G02..::..G02HB_UCV^ ucv,
int n,
int m,
array<double,2>^ x,
array<double>^ a,
array<double>^ z,
double bl,
double bd,
double tol,
int maxit,
int nitmon,
[OutAttribute] int% nit,
[OutAttribute] int% ifail
)```
F#
```static member g02hb :
ucv : G02..::..G02HB_UCV *
n : int *
m : int *
x : float[,] *
a : float[] *
z : float[] *
bl : float *
bd : float *
tol : float *
maxit : int *
nitmon : int *
nit : int byref *
ifail : int byref -> unit
```

#### Parameters

ucv
Type: NagLibrary..::..G02..::..G02HB_UCV
ucv must return the value of the function $u$ for a given value of its argument. The value of $u$ must be non-negative.

A delegate of type G02HB_UCV.

n
Type: System..::..Int32
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.
m
Type: System..::..Int32
On entry: $m$, the number of independent variables.
Constraint: $1\le {\mathbf{m}}\le {\mathbf{n}}$.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, m]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
On entry: the real matrix $X$, i.e., the independent variables. ${\mathbf{x}}\left[\mathit{i}-1,\mathit{j}-1\right]$ must contain the $\mathit{i}\mathit{j}$th element of ${\mathbf{x}}$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,m$.
a
Type: array<System..::..Double>[]()[][]
An array of size [${\mathbf{m}}×\left({\mathbf{m}}+1\right)/2$]
On entry: an initial estimate of the lower triangular real matrix $A$. Only the lower triangular elements must be given and these should be stored row-wise in the array.
The diagonal elements must be $\text{}\ne 0$, although in practice will usually be $\text{}>0$. If the magnitudes of the columns of $X$ are of the same order the identity matrix will often provide a suitable initial value for $A$. If the columns of $X$ are of different magnitudes, the diagonal elements of the initial value of $A$ should be approximately inversely proportional to the magnitude of the columns of $X$.
On exit: the lower triangular elements of the matrix $A$, stored row-wise.
z
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the value ${‖{z}_{\mathit{i}}‖}_{2}$, for $\mathit{i}=1,2,\dots ,n$.
bl
Type: System..::..Double
On entry: the magnitude of the bound for the off-diagonal elements of ${S}_{k}$.
Suggested value: ${\mathbf{bl}}=0.9$.
Constraint: ${\mathbf{bl}}>0.0$.
bd
Type: System..::..Double
On entry: the magnitude of the bound for the diagonal elements of ${S}_{k}$.
Suggested value: ${\mathbf{bd}}=0.9$.
Constraint: ${\mathbf{bd}}>0.0$.
tol
Type: System..::..Double
On entry: the relative precision for the final value of $A$. Iteration will stop when the maximum value of $\left|{s}_{jl}\right|$ is less than tol.
Constraint: ${\mathbf{tol}}>0.0$.
maxit
Type: System..::..Int32
On entry: the maximum number of iterations that will be used during the calculation of $A$.
A value of ${\mathbf{maxit}}=50$ will often be adequate.
Constraint: ${\mathbf{maxit}}>0$.
nitmon
Type: System..::..Int32
On entry: determines the amount of information that is printed on each iteration.
${\mathbf{nitmon}}>0$
The value of $A$ and the maximum value of $\left|{s}_{jl}\right|$ will be printed at the first and every nitmon iterations.
${\mathbf{nitmon}}\le 0$
No iteration monitoring is printed.
When printing occurs the output is directed to the current advisory message unit (see (X04ABF not in this release)).
nit
Type: System..::..Int32%
On exit: the number of iterations performed.
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]).

# Description

In fitting the linear regression model
 $y=Xθ+ε,$
 where $y$ is a vector of length $n$ of the dependent variable, $X$ is an $n$ by $m$ matrix of independent variables, $\theta$ is a vector of length $m$ of unknown parameters, and $\epsilon$ is a vector of length $n$ of unknown errors,
it may be desirable to bound the influence of rows of the $X$ matrix. This can be achieved by calculating a weight for each observation. Several schemes for calculating weights have been proposed (see Hampel et al. (1986) and Marazzi (1987)). As the different independent variables may be measured on different scales one group of proposed weights aims to bound a standardized measure of influence. To obtain such weights the matrix $A$ has to be found such that
 $1n∑i=1nuzi2ziziT=I​ I​ is the identity matrix$
and
 $zi=Axi,$
 where ${x}_{i}$ is a vector of length $m$ containing the elements of the $i$th row of $X$, $A$ is an $m$ by $m$ lower triangular matrix, ${z}_{i}$ is a vector of length $m$, and $u$ is a suitable function.
The weights for use with g02hd may then be computed using
 $wi=fzi2$
for a suitable user-supplied function $f$.
g02hb finds $A$ using the iterative procedure
 $Ak=Sk+IAk-1,$
where ${S}_{k}=\left({s}_{jl}\right)$, for $\mathit{j}=1,2,\dots ,m$ and $\mathit{l}=1,2,\dots ,m$, is a lower triangular matrix such that
• ${s}_{jl}=\left\{\begin{array}{ll}-\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left[\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({h}_{jl}/n,-\mathit{BL}\right),\mathit{BL}\right]\text{,}& j>l\\ & \\ -\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left[\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\frac{1}{2}\left({h}_{jj}/n-1\right),-\mathit{BD}\right),\mathit{BD}\right]\text{,}& j=l\end{array}\right\$
• ${h}_{jl}=\sum _{i=1}^{n}u\left({‖{z}_{i}‖}_{2}\right){z}_{ij}{z}_{il}$
and $\mathit{BD}$ and $\mathit{BL}$ are suitable bounds.
In addition the values of ${‖{z}_{i}‖}_{2}$, for $i=1,2,\dots ,n$, are calculated.
g02hb is based on routines in ROBETH; see Marazzi (1987).

# References

Hampel F R, Ronchetti E M, Rousseeuw P J and Stahel W A (1986) Robust Statistics. The Approach Based on Influence Functions Wiley
Huber P J (1981) Robust Statistics Wiley
Marazzi A (1987) Weights for bounded influence regression in ROBETH Cah. Rech. Doc. IUMSP, No. 3 ROB 3 Institut Universitaire de Médecine Sociale et Préventive, Lausanne

# Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDX) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}\le 1$, or ${\mathbf{m}}<1$, or ${\mathbf{n}}<{\mathbf{m}}$,
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{tol}}\le 0.0$, or ${\mathbf{maxit}}\le 0$, or diagonal element of ${\mathbf{a}}=0.0$, or ${\mathbf{bl}}\le 0.0$, or ${\mathbf{bd}}\le 0.0$.
${\mathbf{ifail}}=3$
Value returned by ${\mathbf{ucv}}<0$.
${\mathbf{ifail}}=4$
The method has failed to converge in maxit iterations.
${\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

On successful exit the accuracy of the results is related to the value of tol; see [Parameters].

# Parallelism and Performance

None.

The existence of $A$ will depend upon the function $u$; (see Hampel et al. (1986) and Marazzi (1987)), also if $X$ is not of full rank a value of $A$ will not be found. If the columns of $X$ are almost linearly related then convergence will be slow.

# Example

This example reads in a matrix of real numbers and computes the Krasker–Welsch weights (see Marazzi (1987)). The matrix $A$ and the weights are then printed.

Example program (C#): g02hbe.cs

Example program data: g02hbe.d

Example program results: g02hbe.r