# NAG CL Interfaceg02hbc (robustm_​wts)

Settings help

CL Name Style:

## 1Purpose

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

## 2Specification

 #include
void  g02hbc (Nag_OrderType order,
 double (*ucv)(double t, Nag_Comm *comm),
Integer n, Integer m, const double x[], Integer pdx, double a[], double z[], double bl, double bd, double tol, Integer maxit, Integer nitmon, const char *outfile, Integer *nit, Nag_Comm *comm, NagError *fail)
The function may be called by the names: g02hbc, nag_correg_robustm_wts or nag_robust_m_regsn_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×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=1nu(‖zi‖2)zi 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×m$ lower triangular matrix, ${z}_{i}$ is a vector of length $m$, and $u$ is a suitable function.
The weights for use with g02hdc may then be computed using
 $wi=f(‖zi‖2)$
for a suitable user-supplied function $f$.
g02hbc finds $A$ using the iterative procedure
 $Ak=(Sk+I)Ak-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}$
• ${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.
g02hbc 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{order}$Nag_OrderType Input
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.1.3 in the Introduction to the NAG Library CL Interface for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2: $\mathbf{ucv}$function, supplied by the user External Function
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:
 double ucv (double t, Nag_Comm *comm)
1: $\mathbf{t}$double Input
On entry: the argument for which ucv must be evaluated.
2: $\mathbf{comm}$Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to ucv.
userdouble *
iuserInteger *
pPointer
The type Pointer will be void *. Before calling g02hbc you may allocate memory and initialize these pointers with various quantities for use by ucv when called from g02hbc (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
Note: ucv should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by g02hbc. If your code inadvertently does return any NaNs or infinities, g02hbc is likely to produce unexpected results.
3: $\mathbf{n}$Integer Input
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.
4: $\mathbf{m}$Integer Input
On entry: $m$, the number of independent variables.
Constraint: $1\le {\mathbf{m}}\le {\mathbf{n}}$.
5: $\mathbf{x}\left[\mathit{dim}\right]$const double Input
Note: the dimension, dim, of the array x must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdx}}×{\mathbf{m}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×{\mathbf{pdx}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
where ${\mathbf{X}}\left(i,j\right)$ appears in this document, it refers to the array element
• ${\mathbf{x}}\left[\left(j-1\right)×{\mathbf{pdx}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{x}}\left[\left(i-1\right)×{\mathbf{pdx}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
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$.
6: $\mathbf{pdx}$Integer Input
On entry: the stride separating row or column elements (depending on the value of order) in the array x.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdx}}\ge {\mathbf{n}}$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdx}}\ge {\mathbf{m}}$.
7: $\mathbf{a}\left[{\mathbf{m}}×\left({\mathbf{m}}+1\right)/2\right]$double 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.
8: $\mathbf{z}\left[{\mathbf{n}}\right]$double Output
On exit: the value ${‖{z}_{\mathit{i}}‖}_{2}$, for $\mathit{i}=1,2,\dots ,n$.
9: $\mathbf{bl}$double 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$.
10: $\mathbf{bd}$double 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$.
11: $\mathbf{tol}$double Input
On entry: the relative precision for the final value of $A$. Iteration will stop when the maximum value of $|{s}_{jl}|$ is less than tol.
Constraint: ${\mathbf{tol}}>0.0$.
12: $\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$.
13: $\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 $|{s}_{jl}|$ will be printed at the first and every nitmon iterations.
${\mathbf{nitmon}}\le 0$
No iteration monitoring is printed.
14: $\mathbf{outfile}$const char * Input
On entry: a null terminated character string giving the name of the file to which results should be printed. If ${\mathbf{outfile}}=\mathbf{NULL}$ or an empty string then the stdout stream is used. Note that the file will be opened in the append mode.
15: $\mathbf{nit}$Integer * Output
On exit: the number of iterations performed.
16: $\mathbf{comm}$Nag_Comm *
The NAG communication argument (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
17: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_CONVERGENCE
Iterations to calculate weights failed to converge in maxit iterations: ${\mathbf{maxit}}=⟨\mathit{\text{value}}⟩$.
NE_FUN_RET_VAL
Value returned by ucv function $\text{}<0$: $u\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$.
The value of $u$ must be non-negative.
NE_INT
On entry, ${\mathbf{maxit}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{maxit}}>0$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}>1$.
On entry, ${\mathbf{pdx}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdx}}>0$.
NE_INT_2
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{m}}\le {\mathbf{n}}$.
On entry, ${\mathbf{pdx}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdx}}\ge {\mathbf{m}}$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_CLOSE_FILE
Cannot close file $⟨\mathit{\text{value}}⟩$.
NE_NOT_WRITE_FILE
Cannot open file $⟨\mathit{\text{value}}⟩$ for writing.
NE_REAL
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, ${\mathbf{tol}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{tol}}>0.0$.
NE_ZERO_DIAGONAL
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.

## 7Accuracy

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

## 8Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g02hbc 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

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 (g02hbce.c)

### 10.2Program Data

Program Data (g02hbce.d)

### 10.3Program Results

Program Results (g02hbce.r)