NAG Library Routine Document

g02hdf  (robustm_user)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

g02hdf performs bounded influence regression (M-estimates) using an iterative weighted least squares algorithm.

2
Specification

Fortran Interface
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, Intent (In):: indw, isigma, n, m, ldx, maxit, nitmon
Integer, Intent (Inout):: ifail
Integer, Intent (Out):: k, nit
Real (Kind=nag_wp), External:: chi, psi
Real (Kind=nag_wp), Intent (In):: psip0, beta, tol, eps
Real (Kind=nag_wp), Intent (Inout):: x(ldx,m), y(n), wgt(n), theta(m), sigma
Real (Kind=nag_wp), Intent (Out):: rs(n), wk((m+4)*n)
C Header Interface
#include nagmk26.h
void  g02hdf_ (
double (NAG_CALL *chi)( const double *t),
double (NAG_CALL *psi)( const double *t),
const double *psip0, const double *beta, const Integer *indw, const Integer *isigma, const Integer *n, const Integer *m, double x[], const Integer *ldx, double y[], double wgt[], double theta[], Integer *k, double *sigma, double rs[], const double *tol, const double *eps, const Integer *maxit, const Integer *nitmon, Integer *nit, double wk[], Integer *ifail)

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 arguments,
and ε is a vector of length n of unknown errors with var εi=σ2,
g02hdf calculates the M-estimates given by the solution, θ^, to the equation
i=1nψri/σwiwixij=0,  j=1,2,,m, (1)
where ri is the ith residual, i.e., the ith element of the vector r=y-Xθ^,
ψ is a suitable weight function,
wi are suitable weights such as those that can be calculated by using output from g02hbf,
and σ may be estimated at each iteration by the median absolute deviation of the residuals σ^=mediri/β1
or as the solution to
i=1nχri/σ^wiwi2=n-kβ2  
for a 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=1nψri/σwixij=0,  j=1,2,,m.  
This may be obtained by use of the transformations
wi* wi yi* yiwi xij* xijwi,   j= 1,2,,m  
(see Marazzi (1987)).
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. .  
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.
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 θ^ 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:     chi – real (Kind=nag_wp) Function, supplied by the user.External Procedure
If isigma>0, chi must return the value of the weight function χ for a given value of its argument. The value of χ must be non-negative.
The specification of chi is:
Fortran Interface
Function chi ( t)
Real (Kind=nag_wp):: chi
Real (Kind=nag_wp), Intent (In):: t
C Header Interface
#include nagmk26.h
double  chi ( const double *t)
1:     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.
Note: chi should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by g02hdf. If your code inadvertently does return any NaNs or infinities, g02hdf is likely to produce unexpected results.
If isigma0, the actual argument chi may be the dummy routine g02hdz. (g02hdz is included in the NAG Library.)
2:     psi – real (Kind=nag_wp) Function, supplied by the user.External Procedure
psi must return the value of the weight function ψ for a given value of its argument.
The specification of psi is:
Fortran Interface
Function psi ( t)
Real (Kind=nag_wp):: psi
Real (Kind=nag_wp), Intent (In):: t
C Header Interface
#include nagmk26.h
double  psi ( const double *t)
1:     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.
Note: psi should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by g02hdf. If your code inadvertently does return any NaNs or infinities, g02hdf is likely to produce unexpected results.
3:     psip0 – Real (Kind=nag_wp)Input
On entry: the value of ψ0.
4:     beta – Real (Kind=nag_wp)Input
On entry: if isigma<0, beta must specify the value of β1.
For Huber and Schweppe type regressions, β1 is the 75th percentile of the standard Normal distribution (see g01faf). For Mallows type regression β1 is the solution to
1ni=1nΦβ1/wi=0.75,  
where Φ is the standard Normal cumulative distribution function (see s15abf).
If isigma>0, beta must specify the value of β2.
β2= -χzϕzdz, in the Huber case; β2= 1ni=1nwi-χzϕzdz, in the Mallows case; β2= 1ni=1nwi2-χz/wiϕzdz, in the Schweppe case;  
where ϕ is the standard normal density, i.e., 12πexp-12x2 .
If isigma=0, beta is not referenced.
Constraint: if isigma0, beta>0.0.
5:     indw – IntegerInput
On entry: determines the type of regression to be performed.
indw=0
Huber type regression.
indw<0
Mallows type regression.
indw>0
Schweppe type regression.
6:     isigma – IntegerInput
On entry: determines how σ is to be estimated.
isigma=0
σ is held constant at its initial value.
isigma<0
σ is estimated by median absolute deviation of residuals.
isigma>0
σ is estimated using the χ function.
7:     n – IntegerInput
On entry: n, the number of observations.
Constraint: n>1.
8:     m – IntegerInput
On entry: m, the number of independent variables.
Constraint: 1m<n.
9:     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, 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:   ldx – IntegerInput
On entry: the first dimension of the array x as declared in the (sub)program from which g02hdf is called.
Constraint: ldxn.
11:   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, 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:   wgtn – Real (Kind=nag_wp) arrayInput/Output
On entry: the weight for the ith observation, for i=1,2,,n.
If 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 wgti0, the ith observation is not included in the analysis.
If indw=0, wgt is not referenced.
On exit: unchanged, except as described above.
13:   thetam – Real (Kind=nag_wp) arrayInput/Output
On entry: starting values of the argument 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: the M-estimate of θi, for i=1,2,,m.
14:   k – IntegerOutput
On exit: the column rank of the matrix X.
15:   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: the final estimate of σ if isigma0 or the value assigned on entry if isigma=0.
16:   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θ^.
17:   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×machine precision.
Constraint: tol>0.0.
18:   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 eps<machine precision or eps>1.0 then machine precision will be used in place of tol.
A reasonable value for eps is 5.0×10-6 where this value is possible.
19:   maxit – IntegerInput
On entry: the maximum number of iterations that should be used during the estimation.
A value of maxit=50 should be adequate for most uses.
Constraint: maxit>0.
20:   nitmon – IntegerInput
On entry: determines the amount of information that is printed on each iteration.
nitmon0
No information is printed.
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:   nit – IntegerOutput
On exit: the number of iterations that were used during the estimation.
22:   wkm+4×n – Real (Kind=nag_wp) arrayWorkspace
23:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ 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​ 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 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: g02hdf 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, m=value.
Constraint: m1.
On entry, n=value.
Constraint: n2.
On entry, n=value and ldx=value.
Constraint: ldxn.
On entry, n=value and m=value.
Constraint: n>m.
ifail=2
On entry, beta=value.
Constraint: beta>0.0.
On entry, sigma=value.
Constraint: sigma>0.0.
ifail=3
On entry, maxit=value.
Constraint: maxit>0.
On entry, tol=value.
Constraint: tol>0.0.
ifail=4
Value given by chi function <0: chivalue=value.
ifail=5
Estimated value of sigma is zero.
ifail=6
Iterations to solve the weighted least squares equations failed to converge.
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 Gii 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 ifail=7 and k=m is possible (see f04jgf).
ifail=8
The routine has failed to converge in maxit iterations.
ifail=9
Having removed cases with zero weight, the value of n-k0, i.e., no degree of freedom for error. This error will only occur if isigma>0.
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.
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.
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 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, which will lead to convergence problems and may trigger the ifail=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 variance-covariance matrix of θ see g02hff.

10
Example

Having input X, Y and the weights, a Schweppe type regression is performed using Huber's ψ function. The subroutine BETCAL calculates the appropriate value of β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)

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