# NAG FL Interfaceg02hbf (robustm_​wts)

## 1Purpose

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.

## 2Specification

Fortran Interface
 Subroutine g02hbf ( ucv, n, m, x, ldx, a, z, bl, bd, tol, nit, wk,
 Integer, Intent (In) :: n, m, ldx, maxit, nitmon Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: nit Real (Kind=nag_wp), External :: ucv Real (Kind=nag_wp), Intent (In) :: x(ldx,m), bl, bd, tol Real (Kind=nag_wp), Intent (Inout) :: a(m*(m+1)/2) Real (Kind=nag_wp), Intent (Out) :: z(n), wk(m*(m+1)/2)
C Header Interface
#include <nag.h>
 void g02hbf_ (double (NAG_CALL *ucv)(const double *t),const Integer *n, const Integer *m, const double x[], const Integer *ldx, double a[], double z[], const double *bl, const double *bd, const double *tol, const Integer *maxit, const Integer *nitmon, Integer *nit, double wk[], Integer *ifail)
The routine may be called by the names g02hbf or nagf_correg_robustm_wts.

## 3Description

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

## 4References

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

## 5Arguments

1: $\mathbf{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:
Fortran Interface
 Function ucv ( t)
 Real (Kind=nag_wp) :: ucv Real (Kind=nag_wp), Intent (In) :: t
C Header Interface
 double ucv_ (const double *t)
1: $\mathbf{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. Arguments denoted as Input must not be changed by this procedure.
Note: ucv should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by g02hbf. If your code inadvertently does return any NaNs or infinities, g02hbf is likely to produce unexpected results.
2: $\mathbf{n}$Integer Input
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.
3: $\mathbf{m}$Integer Input
On entry: $m$, the number of independent variables.
Constraint: $1\le {\mathbf{m}}\le {\mathbf{n}}$.
4: $\mathbf{x}\left({\mathbf{ldx}},{\mathbf{m}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{ldx}$Integer Input
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: $\mathbf{a}\left({\mathbf{m}}×\left({\mathbf{m}}+1\right)/2\right)$Real (Kind=nag_wp) array Input/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: $\mathbf{z}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the value ${‖{z}_{\mathit{i}}‖}_{2}$, for $\mathit{i}=1,2,\dots ,n$.
8: $\mathbf{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: $\mathbf{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: $\mathbf{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: $\mathbf{maxit}$Integer Input
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: $\mathbf{nitmon}$Integer Input
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: $\mathbf{nit}$Integer Output
On exit: the number of iterations performed.
14: $\mathbf{wk}\left({\mathbf{m}}×\left({\mathbf{m}}+1\right)/2\right)$Real (Kind=nag_wp) array Workspace
15: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 2$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ldx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldx}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge {\mathbf{m}}$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{bd}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{bd}}>0.0$.
On entry, ${\mathbf{bl}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{bl}}>0.0$.
On entry, $i=〈\mathit{\text{value}}〉$ and the $i$th diagonal element of $A$ is $0$.
Constraint: all diagonal elements of $A$ must be non-zero.
On entry, ${\mathbf{maxit}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{maxit}}>0$.
On entry, ${\mathbf{tol}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{tol}}>0.0$.
${\mathbf{ifail}}=3$
Value returned by ucv function $\text{}<0$: $u\left(〈\mathit{\text{value}}〉\right)=〈\mathit{\text{value}}〉$.
The value of $u$ must be non-negative.
${\mathbf{ifail}}=4$
Iterations to calculate weights failed to converge in maxit iterations: ${\mathbf{maxit}}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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

## 8Parallelism and Performance

g02hbf 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

## 9Further Comments

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.

## 10Example

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.

### 10.1Program Text

Program Text (g02hbfe.f90)

### 10.2Program Data

Program Data (g02hbfe.d)

### 10.3Program Results

Program Results (g02hbfe.r)