Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_correg_robustm_wts (g02hb)

## Purpose

nag_correg_robustm_wts (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. nag_correg_robustm_wts (g02hb) is intended for the calculation of weights of bounded influence regression using nag_correg_robustm_user (g02hd).

## Syntax

[a, z, nit, ifail] = g02hb(ucv, x, a, 'n', n, 'm', m, 'bl', bl, 'bd', bd, 'tol', tol, 'maxit', maxit, 'nitmon', nitmon)
[a, z, nit, ifail] = nag_correg_robustm_wts(ucv, x, a, 'n', n, 'm', m, 'bl', bl, 'bd', bd, 'tol', tol, 'maxit', maxit, 'nitmon', nitmon)
Note: the interface to this routine has changed since earlier releases of the toolbox:
 At Mark 23: nitmon, tol and maxit were made optional At Mark 22: n was made optional

## 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 arguments, 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 nag_correg_robustm_user (g02hd) may then be computed using
 $wi=fzi2$
for a suitable user-supplied function $f$.
nag_correg_robustm_wts (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.
nag_correg_robustm_wts (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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{ucv}$ – function handle or string containing name of m-file
ucv must return the value of the function $u$ for a given value of its argument. The value of $u$ must be non-negative.
[result] = ucv(t)

Input Parameters

1:     $\mathrm{t}$ – double scalar
The argument for which ucv must be evaluated.

Output Parameters

1:     $\mathrm{result}$ – double scalar
The value of $u\left(t\right)$ evaluated at t.
2:     $\mathrm{x}\left(\mathit{ldx},{\mathbf{m}}\right)$ – double array
ldx, the first dimension of the array, must satisfy the constraint $\mathit{ldx}\ge {\mathbf{n}}$.
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$.
3:     $\mathrm{a}\left({\mathbf{m}}×\left({\mathbf{m}}+1\right)/2\right)$ – double array
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$.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the first dimension of the array x.
$n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.
2:     $\mathrm{m}$int64int32nag_int scalar
Default: the second dimension of the array x.
$m$, the number of independent variables.
Constraint: $1\le {\mathbf{m}}\le {\mathbf{n}}$.
3:     $\mathrm{bl}$ – double scalar
Default: $0.9$
The magnitude of the bound for the off-diagonal elements of ${S}_{k}$.
Constraint: ${\mathbf{bl}}>0.0$.
4:     $\mathrm{bd}$ – double scalar
Default: $0.9$
The magnitude of the bound for the diagonal elements of ${S}_{k}$.
Constraint: ${\mathbf{bd}}>0.0$.
5:     $\mathrm{tol}$ – double scalar
Default: $5e-5$
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$.
6:     $\mathrm{maxit}$int64int32nag_int scalar
Default: $50$
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$.
7:     $\mathrm{nitmon}$int64int32nag_int scalar
Default: $0$
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 nag_file_set_unit_advisory (x04ab)).

### Output Parameters

1:     $\mathrm{a}\left({\mathbf{m}}×\left({\mathbf{m}}+1\right)/2\right)$ – double array
The lower triangular elements of the matrix $A$, stored row-wise.
2:     $\mathrm{z}\left({\mathbf{n}}\right)$ – double array
The value ${‖{z}_{\mathit{i}}‖}_{2}$, for $\mathit{i}=1,2,\dots ,n$.
3:     $\mathrm{nit}$int64int32nag_int scalar
The number of iterations performed.
4:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}\le 1$, or ${\mathbf{m}}<1$, or ${\mathbf{n}}<{\mathbf{m}}$, or $\mathit{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 function has failed to converge in maxit iterations.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

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

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.
```function g02hb_example

fprintf('g02hb example results\n\n');

x = [1, -1, -1;
1, -1,  1;
1,  1, -1;
1,  1,  1;
1,  0,  3];

% Initial values for a
a = [1;
0;     1;
0;     0;     1];

% Calculate a
[a, z, nit, ifail] = g02hb( ...
@ucv, x, a);

fprintf(' iterations to convergence = %4d\n\n', nit);
mtitle = 'Matrix A:';
n = int64(size(x,2));
uplo   = 'Lower';
diag   = 'Non-unit';
[ifail] = x04cc( ...
uplo, diag, n, a, mtitle);
fprintf('\n');
disp('Vector z');
disp(z);
disp((1./z));

function [result] = ucv(t)
ucvc = 2.5;
result = 1;
if (t ~= 0)
q = ucvc/t;
q2 = q^2;
[pc, ifail] = s15ab(q);
l = x02ak;
if (q2 < -log(l))
pd = exp(-q2/2)/sqrt(pi*2);
else
pd = 0;
end
result = (2*pc-1)*(1-q2) + q2 - 2*q*pd;
end
```
```g02hb example results

iterations to convergence =   16

Matrix A:
1            2            3
1    1.3208E+00
2    2.0465E-17  -5.7532E-01
3    1.4518E+00   6.5281E-17   9.3403E-01

Vector z
2.4760
1.9953
2.4760
1.9953
2.5890

0.4039
0.5012
0.4039
0.5012
0.3862

```