G02HAF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G02HAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

G02HAF performs bounded influence regression (M-estimates). Several standard methods are available.

2  Specification

SUBROUTINE G02HAF ( INDW, IPSI, ISIGMA, INDC, N, M, X, LDX, Y, CPSI, H1, H2, H3, CUCV, DCHI, THETA, SIGMA, C, LDC, RS, WGT, TOL, MAXIT, NITMON, WORK, IFAIL)
INTEGER  INDW, IPSI, ISIGMA, INDC, N, M, LDX, LDC, MAXIT, NITMON, IFAIL
REAL (KIND=nag_wp)  X(LDX,M), Y(N), CPSI, H1, H2, H3, CUCV, DCHI, THETA(M), SIGMA, C(LDC,M), RS(N), WGT(N), TOL, WORK(4*N+M*(N+M))

3  Description

For the linear regression model
y = Xθ+ε ,  
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,
θ is a vector of length m of unknown parameters,
and ε is a vector of length n of unknown errors with varεi=σ2,
G02HAF calculates the M-estimates given by the solution, θ^, to the equation
i=1 n ψ ri / σwi wi xij = 0 ,   j=1,2,,m , (1)
where ri is the ith residual, i.e., the ith element of r=y-Xθ^,
ψ is a suitable weight function,
wi are suitable weights,
and σ may be estimated at each iteration by the median absolute deviation of the residuals
σ^ = medi ri / β1  
or as the solution to
i= 1 n χ ri / σ ^ wi wi2 = n-k β2  
for suitable weight function χ, where β1 and β2 are constants, chosen so that the estimator of σ is asymptotically unbiased if the errors, εi, have a Normal distribution. Alternatively σ may be held at a constant value.
The above describes the Schweppe type regression. If the wi are assumed to equal 1 for all i then Huber type regression is obtained. A third type, due to Mallows, replaces (1) by
i=1 n ψ ri / σ wi xij = 0 ,   j=1,2,,m .  
This may be obtained by use of the transformations
wi*wi yi*yi wi xij*xij wi, j= 1,2,,m  
(see Section 3 of Marazzi (1987a)).
For Huber and Schweppe type regressions, β1 is the 75th percentile of the standard Normal distribution. For Mallows type regression β1 is the solution to
1n i=1 n Φ β1 / wi = 0.75 ,  
where Φ is the standard Normal cumulative distribution function (see S15ABF).
β2 is given by
β2 = - χz ϕz dz in the Huber case; β2 = 1 n i=1 n wi - χz ϕz dz in the Mallows case; β2 = 1n i=1 n wi2 - χ z/wi ϕz dz in the Schweppe case;  
where ϕ is the standard Normal density, i.e., 12πexp-12x2 .
The calculation of the estimates of θ can be formulated as an iterative weighted least squares problem with a diagonal weight matrix G given by
Gii = ψ ri / σwi ri / σwi , ri0 ψ 0 , ri=0 ,  
where ψt is the derivative of ψ at the point t.
The value of θ 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
y~i=yiGii x~ij=xijGii, j=1,2,,m  
and then using F04JGF. If X is of full column rank then an orthogonal-triangular (QR) decomposition is used; if not, a singular value decomposition is used.
The following functions are available for ψ and χ in G02HAF.
(a) Unit Weights
ψt = t ,   χt = t22 .  
This gives least squares regression.
(b) Huber's Function
ψt = max-c,minc,t ,   χt = t2 2 , td d2 2 , t>d  
(c) Hampel's Piecewise Linear Function
ψ h1 , h2 , h3 t = - ψ h1 , h2 , h3 -t = t, 0t h1 h1, h1 t h2 h1 h3 - t / h3 - h2 , h2 t h3 0, h3<t  
χt = t2 2 , td d2 2 , t>d  
(d) Andrew's Sine Wave Function
ψt = sint, -πtπ 0, t>π χt = t2 2 , td d2 2 , t>d  
(e) Tukey's Bi-weight
ψt = t 1 - t2 2 , t 1 0, t> 1 χt = t2 2 , td d2 2 , t>d  
where c, h1, h2, h3, and d are given constants.
Several schemes for calculating weights have been proposed, see Hampel et al. (1986) and Marazzi (1987a). 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=1 n u zi2 zi ziT = I  
and
zi = Axi ,  
where xi is a vector of length m containing the ith row of X,
A is an m by m lower triangular matrix,
and u is a suitable function.
The weights are then calculated as
wi = f zi2  
for a suitable function f.
G02HAF finds A using the iterative procedure
Ak = Sk+I Ak-1 ,  
where Sk = sjl ,
sjl = - minmax h jl / n ,-BL,BL , j>l - minmax 12 hjj/n-1 ,-BD,BD , j=l  
and
hjl = i= 1 n u zi2 zij zil  
and BL and BD are bounds set at 0.9.
Two weights are available in G02HAF:
(i) Krasker–Welsch Weights
u t = g1 ct ,  
where g1t=t2+1-t22Φt-1-2tϕt,
Φt is the standard Normal cumulative distribution function,
ϕt is the standard Normal probability density function,
and ft= 1t .
These are for use with Schweppe type regression.
(ii) Maronna's Proposed Weights
ut = c t2 t>c 1 tc ft=ut .  
These are for use with Mallows type regression.
Finally the asymptotic variance-covariance matrix, C, of the estimates θ is calculated.
For Huber type regression
C = fH XTX -1 σ^2 ,  
where
fH = 1 n-m i= 1 n ψ2 ri / σ ^ 1n i= 1 n ψ ri σ^ 2 κ2  
κ2 = 1 + mn 1n i=1 n ψ ri / σ^ - 1n i=1 n ψ ri / σ^ 2 1n i=1 n ψ ri σ^ 2 .  
See Huber (1981) and Marazzi (1987b).
For Mallows and Schweppe type regressions C is of the form
σ^n 2 S1-1 S2 S1-1 ,  
where S1=1nXTDX and S2=1nXTPX.
D is a diagonal matrix such that the ith element approximates Eψri/σwi in the Schweppe case and Eψri/σwi in the Mallows case.
P is a diagonal matrix such that the ith element approximates Eψ2ri/σwiwi2 in the Schweppe case and Eψ2ri/σwi2 in the Mallows case.
Two approximations are available in G02HAF:
1. Average over the ri 
Schweppe Mallows Di = 1n j=1 n ψ rj σ^ wi wi Di = 1n j=1 n ψ rj σ^ wi Pi = 1n j=1 n ψ2 rj σ^ wi wi2 Pi = 1n j=1 n ψ2 rj σ^ wi2  
2. Replace expected value by observed
Schweppe Mallows Di = ψ ri σ^ wi wi Di = ψ ri σ ^ wi Pi = ψ2 ri σ ^ wi wi2 Pi = ψ2 ri σ ^ wi2 .  
See Hampel et al. (1986) and Marazzi (1987b).
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 θ^ corresponding to the usual constant term.
G02HAF is based on routines in ROBETH; see Marazzi (1987a).

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 (1987a) 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
Marazzi A (1987b) 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  Parameters

1:     INDW – INTEGERInput
On entry: specifies the type of regression to be performed.
INDW<0
Mallows type regression with Maronna's proposed weights.
INDW=0
Huber type regression.
INDW>0
Schweppe type regression with Krasker–Welsch weights.
2:     IPSI – INTEGERInput
On entry: specifies which ψ function is to be used.
IPSI=0
ψt=t, i.e., least squares.
IPSI=1
Huber's function.
IPSI=2
Hampel's piecewise linear function.
IPSI=3
Andrew's sine wave.
IPSI=4
Tukey's bi-weight.
Constraint: 0IPSI4.
3:     ISIGMA – INTEGERInput
On entry: specifies how σ is to be estimated.
ISIGMA<0
σ is estimated by median absolute deviation of residuals.
ISIGMA=0
σ is held constant at its initial value.
ISIGMA>0
σ is estimated using the χ function.
4:     INDC – INTEGERInput
On entry: if INDW0, INDC specifies the approximations used in estimating the covariance matrix of θ^.
INDC=1
Averaging over residuals.
INDC1
Replacing expected by observed.
INDW=0
INDC is not referenced.
5:     N – INTEGERInput
On entry: n, the number of observations.
Constraint: N>1.
6:     M – INTEGERInput
On entry: m, the number of independent variables.
Constraint: 1M<N.
7:     XLDXM – REAL (KIND=nag_wp) arrayInput/Output
On entry: the values of the X matrix, i.e., the independent variables. Xij must contain the ijth element of X, for i=1,2,,n and j=1,2,,m.
If INDW<0, then 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.
8:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G02HAF is called.
Constraint: LDXN.
9:     YN – REAL (KIND=nag_wp) arrayInput/Output
On entry: the data values of the dependent variable.
Yi must contain the value of y for the ith observation, for i=1,2,,n.
If INDW<0, then 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.
10:   CPSI – REAL (KIND=nag_wp)Input
On entry: if IPSI=1, CPSI must specify the parameter, c, of Huber's ψ function.
If IPSI1 on entry, CPSI is not referenced.
Constraint: if CPSI>0.0, IPSI=1.
11:   H1 – REAL (KIND=nag_wp)Input
12:   H2 – REAL (KIND=nag_wp)Input
13:   H3 – REAL (KIND=nag_wp)Input
On entry: if IPSI=2, H1, H2, and H3 must specify the parameters h1, h2, and h3, of Hampel's piecewise linear ψ function. H1, H2, and H3 are not referenced if IPSI2.
Constraint: if IPSI=2, 0.0H1H2H3 and H3>0.0.
14:   CUCV – REAL (KIND=nag_wp)Input
On entry: if INDW<0, must specify the value of the constant, c, of the function u for Maronna's proposed weights.
If INDW>0, must specify the value of the function u for the Krasker–Welsch weights.
If INDW=0, is not referenced.
Constraints:
  • if INDW<0, CUCVM;
  • if INDW>0, CUCVM.
15:   DCHI – REAL (KIND=nag_wp)Input
On entry: d, the constant of the χ function. DCHI is not referenced if IPSI=0, or if ISIGMA0.
Constraint: if IPSI0 and ISIGMA>0, DCHI>0.0.
16:   THETAM – REAL (KIND=nag_wp) arrayInput/Output
On entry: starting values of the parameter vector θ. These may be obtained from least squares regression. Alternatively if ISIGMA<0 and SIGMA=1 or if ISIGMA>0 and SIGMA approximately equals the standard deviation of the dependent variable, y, then THETAi=0.0, for i=1,2,,m may provide reasonable starting values.
On exit: THETAi contains the M-estimate of θi, for i=1,2,,m.
17:   SIGMA – REAL (KIND=nag_wp)Input/Output
On entry: a starting value for the estimation of σ. SIGMA should be approximately the standard deviation of the residuals from the model evaluated at the value of θ given by THETA on entry.
Constraint: SIGMA>0.0.
On exit: contains the final estimate of σ if ISIGMA0 or the value assigned on entry if ISIGMA=0.
18:   CLDCM – REAL (KIND=nag_wp) arrayOutput
On exit: the diagonal elements of C contain the estimated asymptotic standard errors of the estimates of θ, i.e., Cii contains the estimated asymptotic standard error of the estimate contained in THETAi.
The elements above the diagonal contain the estimated asymptotic correlation between the estimates of θ, i.e., Cij, 1i<jm contains the asymptotic correlation between the estimates contained in THETAi and THETAj.
The elements below the diagonal contain the estimated asymptotic covariance between the estimates of θ, i.e., Cij, 1j<im contains the estimated asymptotic covariance between the estimates contained in THETAi and THETAj.
19:   LDC – INTEGERInput
On entry: the first dimension of the array C as declared in the (sub)program from which G02HAF is called.
Constraint: LDCM.
20:   RSN – REAL (KIND=nag_wp) arrayOutput
On exit: the residuals from the model evaluated at final value of THETA, i.e., RS contains the vector y-Xθ^.
21:   WGTN – REAL (KIND=nag_wp) arrayOutput
On exit: the vector of weights. WGTi contains the weight for the ith observation, for i=1,2,,n.
22:   TOL – REAL (KIND=nag_wp)Input
On entry: the relative precision for the calculation of A (if INDW0), the estimates of θ and the estimate of σ (if ISIGMA0). Convergence is assumed when the relative change in all elements being considered is less than TOL.
If INDW<0 and ISIGMA<0, TOL is also used to determine the precision of β1.
It is advisable for TOL to be greater than 100×machine precision.
Constraint: TOL>0.0.
23:   MAXIT – INTEGERInput
On entry: the maximum number of iterations that should be used in the calculation of A (if INDW0), and of the estimates of θ and σ, and of β1 (if INDW<0 and ISIGMA<0).
A value of MAXIT=50 should be adequate for most uses.
Constraint: MAXIT>0.
24:   NITMON – INTEGERInput
On entry: the amount of information that is printed on each iteration.
NITMON=0
No information is printed.
NITMON0
The current estimate of θ, the change in θ during the current iteration and the current value of σ are printed on the first and every absNITMON iterations.
Also, if INDW0 and NITMON>0 then information on the iterations to calculate A is printed. This is the current estimate of A and the maximum value of Sij (see Section 3).
When printing occurs the output is directed to the current advisory message unit (see X04ABF).
25:   WORK4×N+M×N+M – REAL (KIND=nag_wp) arrayOutput
On exit: the following values are assigned to WORK:
  • WORK1=β1 if ISIGMA<0, or WORK1=β2 if ISIGMA>0.
  • WORK2= number of iterations used to calculate A.
  • WORK3= number of iterations used to calculate final estimates of θ and σ.
  • WORK4=k, the rank of the weighted least squares equations.
The rest of the array is used as workspace.
26:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ 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 parameters may be useful even if IFAIL0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: G02HAF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
IFAIL=1
On entry,N1,
orM<1,
orNM,
orLDX<N,
orLDC<M.
IFAIL=2
On entry,IPSI<0,
orIPSI>4.
IFAIL=3
On entry,SIGMA0.0,
orIPSI=1 and CPSI0.0,
orIPSI=2 and H1<0.0,
orIPSI=2 and H1>H2,
orIPSI=2 and H2>H3,
orIPSI=2 and H1=H2=H3=0.0,
orIPSI0 and ISIGMA>0 and DCHI0.0,
orINDW>0 and CUCV<M,
orINDW<0 and CUCV<M.
IFAIL=4
On entry,TOL0.0,
orMAXIT0.
IFAIL=5
The number of iterations required to calculate the weights exceeds MAXIT. (Only if INDW0.)
IFAIL=6
The number of iterations required to calculate β1 exceeds MAXIT. (Only if INDW<0 and ISIGMA<0.)
IFAIL=7
Either the number of iterations required to calculate θ and σ exceeds MAXIT (note that, in this case WORK3=MAXIT on exit), or the iterations to solve the weighted least squares equations failed to converge. The latter is an unlikely error exit.
IFAIL=8
The weighted least squares equations are not of full rank.
IFAIL=9
If INDW=0 then XTX is almost singular.
If INDW0 then S1 is singular or almost singular. This may be due to too many diagonal elements of the matrix being zero, see Section 9.
IFAIL=10
In calculating the correlation factor for the asymptotic variance-covariance matrix either the value of
1n i=1 n ψ ri / σ^ = 0 ,   or   κ = 0 ,   or   i=1 n ψ2 ri / σ^ = 0 .  
See Section 9. In this case C is returned as XTX.
(Only if INDW=0.)
IFAIL=11
The estimated variance for an element of θ0.
In this case the diagonal element of C will contain the negative variance and the above diagonal elements in the row and column corresponding to the element will be returned as zero.
This error may be caused by rounding errors or too many of the diagonal elements of P being zero, where P is defined in Section 3. See Section 9.
IFAIL=12
The degrees of freedom for error, n-k0 (this is an unlikely error exit), or the estimated value of σ was 0 during an iteration.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

The precision of the estimates is determined by TOL. As a more stable method is used to calculate the estimates of θ than is used to calculate the covariance matrix, it is possible for the least squares equations to be of full rank but the XTX matrix to be too nearly singular to be inverted.

8  Parallelism and Performance

G02HAF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02HAF 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.

9  Further Comments

In cases when ISIGMA0 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., ψri/σ, to be zero or a value of ψri/σ, used to estimate the asymptotic covariance matrix, to be zero. This can lead to errors IFAIL=8 or 9 (if INDW0), IFAIL=10 (if INDW=0) and IFAIL=11.
G02HBF, G02HDF and G02HFF together carry out the same calculations as G02HAF but for user-supplied functions for ψ, χ, ψ and u.

10  Example

The number of observations and the number of x variables are read in followed by the data. The option parameters are then read in (in this case giving Schweppe type regression with Hampel's ψ function and Huber's χ function and then using the ‘replace expected by observed’ option in calculating the covariances). Finally a set of values for the constants are read in.
After a call to G02HAF, θ^, its standard error and σ^ are printed. In addition the weight and residual for each observation is printed.

10.1  Program Text

Program Text (g02hafe.f90)

10.2  Program Data

Program Data (g02hafe.d)

10.3  Program Results

Program Results (g02hafe.r)


G02HAF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015