NAG Library Routine Document
G02HDF
1 Purpose
G02HDF performs bounded influence regression ($M$estimates) using an iterative weighted least squares algorithm.
2 Specification
SUBROUTINE G02HDF ( 
CHI, PSI, PSIP0, BETA, INDW, ISIGMA, N, M, X, LDX, Y, WGT, THETA, K, SIGMA, RS, TOL, EPS, MAXIT, NITMON, NIT, WK, IFAIL) 
INTEGER 
INDW, ISIGMA, N, M, LDX, K, MAXIT, NITMON, NIT, IFAIL 
REAL (KIND=nag_wp) 
CHI, PSI, PSIP0, BETA, X(LDX,M), Y(N), WGT(N), THETA(M), SIGMA, RS(N), TOL, EPS, WK((M+4)*N) 
EXTERNAL 
CHI, PSI 

3 Description
For the linear regression model
where 
$y$ is a vector of length $n$ of the dependent variable, 

$X$ is a $n$ by $m$ matrix of independent variables of column rank $k$, 

$\theta $ is a vector of length $m$ of unknown arguments, 
and 
$\epsilon $ is a vector of length $n$ of unknown errors with var $\left({\epsilon}_{i}\right)={\sigma}^{2}$, 
G02HDF calculates the Mestimates given by the solution,
$\hat{\theta}$, to the equation
where 
${r}_{i}$ is the $i$th residual, i.e., the $i$th element of the vector $r=yX\hat{\theta}$, 

$\psi $ is a suitable weight function, 

${w}_{i}$ are suitable weights such as those that can be calculated by using output from G02HBF, 
and 
$\sigma $ may be estimated at each iteration by the median absolute deviation of the residuals $\hat{\sigma}={\mathrm{med}}_{i}\left[\left{r}_{i}\right\right]/{\beta}_{1}$ 
or as the solution to
for a suitable weight function
$\chi $, where
${\beta}_{1}$ and
${\beta}_{2}$ are constants, chosen so that the estimator of
$\sigma $ is asymptotically unbiased if the errors,
${\epsilon}_{i}$, have a Normal distribution. Alternatively
$\sigma $ may be held at a constant value.
The above describes the Schweppe type regression. If the
${w}_{i}$ are assumed to equal
$1$ for all
$i$, then Huber type regression is obtained. A third type, due to Mallows, replaces
(1) by
This may be obtained by use of the transformations
(see
Marazzi (1987)).
The calculation of the estimates of
$\theta $ can be formulated as an iterative weighted least squares problem with a diagonal weight matrix
$G$ given by
The value of
$\theta $ at each iteration is given by the weighted least squares regression of
$y$ on
$X$. This is carried out by first transforming the
$y$ and
$X$ by
and then using
F04JGF
.
If
$X$ is of full column rank then an orthogonaltriangular (
$QR$) decomposition is used; if not, a singular value decomposition is used.
Observations with zero or negative weights are not included in the solution.
Note: there is no explicit provision in the routine for a constant term in the regression model. However, the addition of a dummy variable whose value is $1.0$ for all observations will produce a value of $\hat{\theta}$ corresponding to the usual constant term.
G02HDF 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) Subroutines for robust and bounded influence regression in ROBETH Cah. Rech. Doc. IUMSP, No. 3 ROB 2 Institut Universitaire de Médecine Sociale et Préventive, Lausanne
5 Arguments
 1: $\mathrm{CHI}$ – REAL (KIND=nag_wp) FUNCTION, supplied by the user.External Procedure

If
${\mathbf{ISIGMA}}>0$,
CHI must return the value of the weight function
$\chi $ for a given value of its argument. The value of
$\chi $ must be nonnegative.
The specification of
CHI is:
 1: $\mathrm{T}$ – REAL (KIND=nag_wp)Input

On entry: the argument for which
CHI must be evaluated.
CHI must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which G02HDF is called. Arguments denoted as
Input must
not be changed by this procedure.
If
${\mathbf{ISIGMA}}\le 0$, the actual argument
CHI may be the dummy routine G02HDZ. (G02HDZ is included in the NAG Library.)
 2: $\mathrm{PSI}$ – REAL (KIND=nag_wp) FUNCTION, supplied by the user.External Procedure

PSI must return the value of the weight function
$\psi $ for a given value of its argument.
The specification of
PSI is:
 1: $\mathrm{T}$ – REAL (KIND=nag_wp)Input

On entry: the argument for which
PSI must be evaluated.
PSI must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which G02HDF is called. Arguments denoted as
Input must
not be changed by this procedure.
 3: $\mathrm{PSIP0}$ – REAL (KIND=nag_wp)Input

On entry: the value of $\psi \prime \left(0\right)$.
 4: $\mathrm{BETA}$ – REAL (KIND=nag_wp)Input

On entry: if
${\mathbf{ISIGMA}}<0$,
BETA must specify the value of
${\beta}_{1}$.
For Huber and Schweppe type regressions,
${\beta}_{1}$ is the
$75$th percentile of the standard Normal distribution (see
G01FAF). For Mallows type regression
${\beta}_{1}$ is the solution to
where
$\Phi $ is the standard Normal cumulative distribution function (see
S15ABF).
If
${\mathbf{ISIGMA}}>0$,
BETA must specify the value of
${\beta}_{2}$.
where
$\varphi $ is the standard normal density, i.e.,
$\frac{1}{\sqrt{2\pi}}\mathrm{exp}\left(\frac{1}{2}{x}^{2}\right)$.
If
${\mathbf{ISIGMA}}=0$,
BETA is not referenced.
Constraint:
if ${\mathbf{ISIGMA}}\ne 0$, ${\mathbf{BETA}}>0.0$.
 5: $\mathrm{INDW}$ – INTEGERInput

On entry: determines the type of regression to be performed.
 ${\mathbf{INDW}}=0$
 Huber type regression.
 ${\mathbf{INDW}}<0$
 Mallows type regression.
 ${\mathbf{INDW}}>0$
 Schweppe type regression.
 6: $\mathrm{ISIGMA}$ – INTEGERInput

On entry: determines how
$\sigma $ is to be estimated.
 ${\mathbf{ISIGMA}}=0$
 $\sigma $ is held constant at its initial value.
 ${\mathbf{ISIGMA}}<0$
 $\sigma $ is estimated by median absolute deviation of residuals.
 ${\mathbf{ISIGMA}}>0$
 $\sigma $ is estimated using the $\chi $ function.
 7: $\mathrm{N}$ – INTEGERInput

On entry: $n$, the number of observations.
Constraint:
${\mathbf{N}}>1$.
 8: $\mathrm{M}$ – INTEGERInput

On entry: $m$, the number of independent variables.
Constraint:
$1\le {\mathbf{M}}<{\mathbf{N}}$.
 9: $\mathrm{X}\left({\mathbf{LDX}},{\mathbf{M}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On entry: the values of the
$X$ matrix, 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$.
If
${\mathbf{INDW}}<0$, during calculations the elements of
X will be transformed as described in
Section 3. Before exit the inverse transformation will be applied. As a result there may be slight differences between the input
X and the output
X.
On exit: unchanged, except as described above.
 10: $\mathrm{LDX}$ – INTEGERInput

On entry: the first dimension of the array
X as declared in the (sub)program from which G02HDF is called.
Constraint:
${\mathbf{LDX}}\ge {\mathbf{N}}$.
 11: $\mathrm{Y}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On entry: the data values of the dependent variable.
${\mathbf{Y}}\left(\mathit{i}\right)$ must contain the value of $y$ for the $\mathit{i}$th observation, for $\mathit{i}=1,2,\dots ,n$.
If
${\mathbf{INDW}}<0$, during calculations the elements of
Y will be transformed as described in
Section 3. Before exit the inverse transformation will be applied. As a result there may be slight differences between the input
Y and the output
Y.
On exit: unchanged, except as described above.
 12: $\mathrm{WGT}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On entry: the weight for the
$\mathit{i}$th observation, for
$\mathit{i}=1,2,\dots ,n$.
If
${\mathbf{INDW}}<0$, during calculations elements of
WGT will be transformed as described in
Section 3. Before exit the inverse transformation will be applied. As a result there may be slight differences between the input
WGT and the output
WGT.
If ${\mathbf{WGT}}\left(i\right)\le 0$, the $i$th observation is not included in the analysis.
If
${\mathbf{INDW}}=0$,
WGT is not referenced.
On exit: unchanged, except as described above.
 13: $\mathrm{THETA}\left({\mathbf{M}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On entry: starting values of the argument vector
$\theta $. These may be obtained from least squares regression. Alternatively if
${\mathbf{ISIGMA}}<0$ and
${\mathbf{SIGMA}}=1$ or if
${\mathbf{ISIGMA}}>0$ and
SIGMA approximately equals the standard deviation of the dependent variable,
$y$, then
${\mathbf{THETA}}\left(\mathit{i}\right)=0.0$, for
$\mathit{i}=1,2,\dots ,m$ may provide reasonable starting values.
On exit: the Mestimate of
${\theta}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,m$.
 14: $\mathrm{K}$ – INTEGEROutput

On exit: the column rank of the matrix $X$.
 15: $\mathrm{SIGMA}$ – REAL (KIND=nag_wp)Input/Output

On entry: a starting value for the estimation of
$\sigma $.
SIGMA should be approximately the standard deviation of the residuals from the model evaluated at the value of
$\theta $ given by
THETA on entry.
Constraint:
${\mathbf{SIGMA}}>0.0$.
On exit: the final estimate of $\sigma $ if ${\mathbf{ISIGMA}}\ne 0$ or the value assigned on entry if ${\mathbf{ISIGMA}}=0$.
 16: $\mathrm{RS}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: the residuals from the model evaluated at final value of
THETA, i.e.,
RS contains the vector
$\left(yX\hat{\theta}\right)$.
 17: $\mathrm{TOL}$ – REAL (KIND=nag_wp)Input

On entry: the relative precision for the final estimates. Convergence is assumed when both the relative change in the value of
SIGMA and the relative change in the value of each element of
THETA are less than
TOL.
It is advisable for
TOL to be greater than
$100\times \mathit{machineprecision}$.
Constraint:
${\mathbf{TOL}}>0.0$.
 18: $\mathrm{EPS}$ – REAL (KIND=nag_wp)Input

On entry: a relative tolerance to be used to determine the rank of
$X$. See
F04JGF for further details.
If
${\mathbf{EPS}}<\mathit{machineprecision}$ or
${\mathbf{EPS}}>1.0$ then
machine precision will be used in place of
TOL.
A reasonable value for
EPS is
$5.0\times {10}^{6}$ where this value is possible.
 19: $\mathrm{MAXIT}$ – INTEGERInput

On entry: the maximum number of iterations that should be used during the estimation.
A value of ${\mathbf{MAXIT}}=50$ should be adequate for most uses.
Constraint:
${\mathbf{MAXIT}}>0$.
 20: $\mathrm{NITMON}$ – INTEGERInput

On entry: determines the amount of information that is printed on each iteration.
 ${\mathbf{NITMON}}\le 0$
 No information is printed.
 ${\mathbf{NITMON}}>0$
 On the first and every NITMON iterations the values of SIGMA, THETA and the change in THETA during the iteration are printed.
When printing occurs the output is directed to the current advisory message unit (see
X04ABF).
 21: $\mathrm{NIT}$ – INTEGEROutput

On exit: the number of iterations that were used during the estimation.
 22: $\mathrm{WK}\left(\left({\mathbf{M}}+4\right)\times {\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayWorkspace

 23: $\mathrm{IFAIL}$ – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation 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, because for this routine the values of the output arguments may be useful even if
${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is
$1$.
When the value $\mathbf{1}\text{ or}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}}=0$ or
$1$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Note: G02HDF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$

On entry,  ${\mathbf{N}}\le 1$, 
or  ${\mathbf{M}}<1$, 
or  ${\mathbf{N}}\le {\mathbf{M}}$, 
or  ${\mathbf{LDX}}<{\mathbf{N}}$. 
 ${\mathbf{IFAIL}}=2$

On entry,  ${\mathbf{BETA}}\le 0.0$, and ${\mathbf{ISIGMA}}\ne 0$, 
or  ${\mathbf{SIGMA}}\le 0.0$. 
 ${\mathbf{IFAIL}}=3$

On entry,  ${\mathbf{TOL}}\le 0.0$, 
or  ${\mathbf{MAXIT}}\le 0$. 
 ${\mathbf{IFAIL}}=4$

A value returned by the
CHI function is negative.
 ${\mathbf{IFAIL}}=5$

During iterations a value of ${\mathbf{SIGMA}}\le 0.0$ was encountered.
 ${\mathbf{IFAIL}}=6$

A failure occurred in
F04JGF . This is an extremely unlikely error. If it occurs, please contact
NAG.
 ${\mathbf{IFAIL}}=7$

The weighted least squares equations are not of full rank. This may be due to the
$X$ matrix not being of full rank, in which case the results will be valid. It may also occur if some of the
${G}_{ii}$ values become very small or zero, see
Section 9. The rank of the equations is given by
K. If the matrix just fails the test for nonsingularity then the result
${\mathbf{IFAIL}}={\mathbf{7}}$ and
${\mathbf{K}}={\mathbf{M}}$ is possible (see
F04JGF).
 ${\mathbf{IFAIL}}=8$

The routine has failed to converge in
MAXIT iterations.
 ${\mathbf{IFAIL}}=9$

Having removed cases with zero weight, the value of ${\mathbf{N}}{\mathbf{K}}\le 0$, i.e., no degree of freedom for error. This error will only occur if ${\mathbf{ISIGMA}}>0$.
 ${\mathbf{IFAIL}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{IFAIL}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{IFAIL}}=999$
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7 Accuracy
The accuracy of the results is controlled by
TOL.
For the accuracy of the weighted least squares see
F04JGF.
8 Parallelism and Performance
G02HDF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02HDF 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 implementationspecific information.
In cases when
${\mathbf{ISIGMA}}\ne 0$ it is important for the value of
SIGMA to be of a reasonable magnitude. Too small a value may cause too many of the winsorized residuals, i.e.,
$\psi \left({r}_{i}/\sigma \right)$, to be zero, which will lead to convergence problems and may trigger the
${\mathbf{IFAIL}}={\mathbf{7}}$ error.
By suitable choice of the functions
CHI and
PSI this routine may be used for other applications of iterative weighted least squares.
For the variancecovariance matrix of
$\theta $ see
G02HFF.
10 Example
Having input $X$, $Y$ and the weights, a Schweppe type regression is performed using Huber's $\psi $ function. The subroutine BETCAL calculates the appropriate value of ${\beta}_{2}$.
10.1 Program Text
Program Text (g02hdfe.f90)
10.2 Program Data
Program Data (g02hdfe.d)
10.3 Program Results
Program Results (g02hdfe.r)