G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG02HBF

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

G02HBF 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. G02HBF is intended for the calculation of weights of bounded influence regression using G02HDF.

## 2  Specification

 SUBROUTINE G02HBF ( UCV, N, M, X, LDX, A, Z, BL, BD, TOL, MAXIT, NITMON, NIT, WK, IFAIL)
 INTEGER N, M, LDX, MAXIT, NITMON, NIT, IFAIL REAL (KIND=nag_wp) UCV, X(LDX,M), A(M*(M+1)/2), Z(N), BL, BD, TOL, WK(M*(M+1)/2) EXTERNAL UCV

## 3  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=1nuzi2zi ziT =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 G02HDF may then be computed using
 $wi=fzi2$
for a suitable user-supplied function $f$.
G02HBF 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.
G02HBF is based on routines in ROBETH; see Marazzi (1987).

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

## 5  Parameters

1:     UCV – REAL (KIND=nag_wp) FUNCTION, supplied by the user.External Procedure
UCV must return the value of the function $u$ for a given value of its argument. The value of $u$ must be non-negative.
The specification of UCV is:
 FUNCTION UCV ( T)
 REAL (KIND=nag_wp) UCV
 REAL (KIND=nag_wp) T
1:     T – REAL (KIND=nag_wp)Input
On entry: the argument for which UCV must be evaluated.
UCV must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which G02HBF is called. Parameters denoted as Input must not be changed by this procedure.
2:     N – INTEGERInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{N}}>1$.
3:     M – INTEGERInput
On entry: $m$, the number of independent variables.
Constraint: $1\le {\mathbf{M}}\le {\mathbf{N}}$.
4:     X(LDX,M) – REAL (KIND=nag_wp) arrayInput
On entry: the real matrix $X$, i.e., the independent variables. ${\mathbf{X}}\left(\mathit{i},\mathit{j}\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$.
5:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G02HBF is called.
Constraint: ${\mathbf{LDX}}\ge {\mathbf{N}}$.
6:     A(${\mathbf{M}}×\left({\mathbf{M}}+1\right)/2$) – REAL (KIND=nag_wp) arrayInput/Output
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.
7:     Z(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the value ${‖{z}_{\mathit{i}}‖}_{2}$, for $\mathit{i}=1,2,\dots ,n$.
8:     BL – REAL (KIND=nag_wp)Input
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$.
9:     BD – REAL (KIND=nag_wp)Input
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$.
10:   TOL – REAL (KIND=nag_wp)Input
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$.
11:   MAXIT – INTEGERInput
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$.
12:   NITMON – INTEGERInput
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).
13:   NIT – INTEGEROutput
On exit: the number of iterations performed.
14:   WK(${\mathbf{M}}×\left({\mathbf{M}}+1\right)/2$) – REAL (KIND=nag_wp) arrayWorkspace
15:   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, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{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).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{N}}\le 1$, or ${\mathbf{M}}<1$, or ${\mathbf{N}}<{\mathbf{M}}$, or ${\mathbf{LDX}}<{\mathbf{N}}$.
${\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 routine has failed to converge in MAXIT iterations.

## 7  Accuracy

On successful exit the accuracy of the results is related to the value of TOL; see Section 5.

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.

## 9  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.

### 9.1  Program Text

Program Text (g02hbfe.f90)

### 9.2  Program Data

Program Data (g02hbfe.d)

### 9.3  Program Results

Program Results (g02hbfe.r)