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$X$ of full column rank, a lower triangular matrix A$A$ such that (ATA)1${\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:
Mark 22: n has been made optional
Mark 23: nitmon, tol, maxit now optional
.

## Description

In fitting the linear regression model
 y = Xθ + ε, $y=Xθ+ε,$
 where y$y$ is a vector of length n$n$ of the dependent variable, X$X$ is an n$n$ by m$m$ matrix of independent variables, θ$\theta$ is a vector of length m$m$ of unknown parameters, and ε$\epsilon$ is a vector of length n$n$ of unknown errors,
it may be desirable to bound the influence of rows of the X$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$A$ has to be found such that
 n 1/n ∑ u(‖zi‖2)ziziT = I​  (I​ is the identity matrix) i = 1
$1n∑i=1nu(‖zi‖2)zi ziT =I​ (I​ is the identity matrix)$
and
 zi = Axi, $zi=Axi,$
 where xi${x}_{i}$ is a vector of length m$m$ containing the elements of the i$i$th row of X$X$, A$A$ is an m$m$ by m$m$ lower triangular matrix, zi${z}_{i}$ is a vector of length m$m$, and u$u$ is a suitable function.
The weights for use with nag_correg_robustm_user (g02hd) may then be computed using
 wi = f(‖zi‖2) $wi=f(‖zi‖2)$
for a suitable user-supplied function f$f$.
nag_correg_robustm_wts (g02hb) finds A$A$ using the iterative procedure
 Ak = (Sk + I)Ak − 1, $Ak=(Sk+I)Ak-1,$
where Sk = (sjl)${S}_{k}=\left({s}_{jl}\right)$, for j = 1,2,,m$\mathit{j}=1,2,\dots ,m$ and l = 1,2,,m$\mathit{l}=1,2,\dots ,m$, is a lower triangular matrix such that
• sjl =  { − min [max (hjl / n, − BL),BL], j > l − min [max ((1/2)(hjj / n − 1), − BD),BD], j = l
${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}$
• hjl = i = 1nu(zi2)zijzil${h}_{jl}=\sum _{i=1}^{n}u\left({‖{z}_{i}‖}_{2}\right){z}_{ij}{z}_{il}$
and BD$\mathit{BD}$ and BL$\mathit{BL}$ are suitable bounds.
In addition the values of zi2${‖{z}_{i}‖}_{2}$, for i = 1,2,,n$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:     ucv – function handle or string containing name of m-file
ucv must return the value of the function u$u$ for a given value of its argument. The value of u$u$ must be non-negative.
[result] = ucv(t)

Input Parameters

1:     t – double scalar
The argument for which ucv must be evaluated.

Output Parameters

1:     result – double scalar
The result of the function.
2:     x(ldx,m) – double array
ldx, the first dimension of the array, must satisfy the constraint ldxn$\mathit{ldx}\ge {\mathbf{n}}$.
The real matrix X$X$, i.e., the independent variables. x(i,j)${\mathbf{x}}\left(\mathit{i},\mathit{j}\right)$ must contain the ij$\mathit{i}\mathit{j}$th element of x${\mathbf{x}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$ and j = 1,2,,m$\mathit{j}=1,2,\dots ,m$.
3:     a(m × (m + 1) / 2${\mathbf{m}}×\left({\mathbf{m}}+1\right)/2$) – double array
An initial estimate of the lower triangular real matrix A$A$. Only the lower triangular elements must be given and these should be stored row-wise in the array.
The diagonal elements must be 0$\text{}\ne 0$, although in practice will usually be > 0$\text{}>0$. If the magnitudes of the columns of X$X$ are of the same order the identity matrix will often provide a suitable initial value for A$A$. If the columns of X$X$ are of different magnitudes, the diagonal elements of the initial value of A$A$ should be approximately inversely proportional to the magnitude of the columns of X$X$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the array x.
n$n$, the number of observations.
Constraint: n > 1${\mathbf{n}}>1$.
2:     m – int64int32nag_int scalar
Default: The second dimension of the array x.
m$m$, the number of independent variables.
Constraint: 1mn$1\le {\mathbf{m}}\le {\mathbf{n}}$.
3:     bl – double scalar
The magnitude of the bound for the off-diagonal elements of Sk${S}_{k}$.
Default: 0.9$0.9$
Constraint: bl > 0.0${\mathbf{bl}}>0.0$.
4:     bd – double scalar
The magnitude of the bound for the diagonal elements of Sk${S}_{k}$.
Default: 0.9$0.9$
Constraint: bd > 0.0${\mathbf{bd}}>0.0$.
5:     tol – double scalar
The relative precision for the final value of A$A$. Iteration will stop when the maximum value of |sjl|$|{s}_{jl}|$ is less than tol.
Default: 5e-5$5e-5$
Constraint: tol > 0.0${\mathbf{tol}}>0.0$.
6:     maxit – int64int32nag_int scalar
The maximum number of iterations that will be used during the calculation of A$A$.
A value of maxit = 50${\mathbf{maxit}}=50$ will often be adequate.
Default: 50$50$
Constraint: maxit > 0${\mathbf{maxit}}>0$.
7:     nitmon – int64int32nag_int scalar
Determines the amount of information that is printed on each iteration.
nitmon > 0${\mathbf{nitmon}}>0$
The value of A$A$ and the maximum value of |sjl|$|{s}_{jl}|$ will be printed at the first and every nitmon iterations.
nitmon0${\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)).
Default: 0$0$

ldx wk

### Output Parameters

1:     a(m × (m + 1) / 2${\mathbf{m}}×\left({\mathbf{m}}+1\right)/2$) – double array
The lower triangular elements of the matrix A$A$, stored row-wise.
2:     z(n) – double array
The value zi2${‖{z}_{\mathit{i}}‖}_{2}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
3:     nit – int64int32nag_int scalar
The number of iterations performed.
4:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, n ≤ 1${\mathbf{n}}\le 1$, or m < 1${\mathbf{m}}<1$, or n < m${\mathbf{n}}<{\mathbf{m}}$, or ldx < n$\mathit{ldx}<{\mathbf{n}}$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, tol ≤ 0.0${\mathbf{tol}}\le 0.0$, or maxit ≤ 0${\mathbf{maxit}}\le 0$, or diagonal element of a = 0.0${\mathbf{a}}=0.0$, or bl ≤ 0.0${\mathbf{bl}}\le 0.0$, or bd ≤ 0.0${\mathbf{bd}}\le 0.0$.
ifail = 3${\mathbf{ifail}}=3$
Value returned by ucv < 0${\mathbf{ucv}}<0$.
ifail = 4${\mathbf{ifail}}=4$
The function has failed to converge in maxit iterations.

## Accuracy

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

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

## Example

```function nag_correg_robustm_wts_example
x = [1, -1, -1;
1, -1, 1;
1, 1, -1;
1, 1, 1;
1, 0, 3];
a = [1;
0;
1;
0;
0;
1];
[aOut, z, nit, ifail] = nag_correg_robustm_wts(@ucv, x, a)

function [result] = ucv(t)
ucvc = 2.5;
result = 1;
if (t ~= 0.0)
q = ucvc/t;
q2 = q*q;
[pc, ifail] = nag_specfun_cdf_normal(q);
l = nag_machine_real_smallest;
if (q2 < -log(l))
pd = exp(-q2/2.0)/sqrt(pi*2.0);
else
pd = 0.0;
end
result = (2.0*pc-1.0)*(1.0-q2) + q2 - 2.0*q*pd;
end
```
```

aOut =

1.3208
0.0000
1.4518
-0.5753
0.0000
0.9340

z =

2.4760
1.9953
2.4760
1.9953
2.5890

nit =

16

ifail =

0

```
```function g02hb_example
x = [1, -1, -1;
1, -1, 1;
1, 1, -1;
1, 1, 1;
1, 0, 3];
a = [1;
0;
1;
0;
0;
1];
[aOut, z, nit, ifail] = g02hb(@ucv, x, a)

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

aOut =

1.3208
0.0000
1.4518
-0.5753
0.0000
0.9340

z =

2.4760
1.9953
2.4760
1.9953
2.5890

nit =

16

ifail =

0

```