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

NAG Library Routine Document

G02HLF

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

G02HLF calculates a robust estimate of the covariance matrix for user-supplied weight functions and their derivatives.

2  Specification

SUBROUTINE G02HLF ( UCV, RUSER, INDM, N, M, X, LDX, COV, A, WT, THETA, BL, BD, MAXIT, NITMON, TOL, NIT, WK, IFAIL)
INTEGER  INDM, N, M, LDX, MAXIT, NITMON, NIT, IFAIL
REAL (KIND=nag_wp)  RUSER(*), X(LDX,M), COV(M*(M+1)/2), A(M*(M+1)/2), WT(N), THETA(M), BL, BD, TOL, WK(2*M)
EXTERNAL  UCV

3  Description

For a set of n observations on m variables in a matrix X, a robust estimate of the covariance matrix, C, and a robust estimate of location, θ, are given by:
C=τ2ATA-1,
where τ2 is a correction factor and A is a lower triangular matrix found as the solution to the following equations.
zi=Axi-θ
1n i= 1nwzi2zi=0
and
1ni=1nuzi2zi ziT -vzi2I=0,
where xi is a vector of length m containing the elements of the ith row of X,
zi is a vector of length m,
I is the identity matrix and 0 is the zero matrix,
and w and u are suitable functions.
G02HLF covers two situations:
(i) vt=1 for all t,
(ii) vt=ut.
The robust covariance matrix may be calculated from a weighted sum of squares and cross-products matrix about θ using weights wti=uzi. In case (i) a divisor of n is used and in case (ii) a divisor of i=1nwti is used. If w.=u., then the robust covariance matrix can be calculated by scaling each row of X by wti and calculating an unweighted covariance matrix about θ.
In order to make the estimate asymptotically unbiased under a Normal model a correction factor, τ2, is needed. The value of the correction factor will depend on the functions employed (see Huber (1981) and Marazzi (1987)).
G02HLF finds A using the iterative procedure as given by Huber.
Ak=Sk+IAk-1
and
θjk=bjD1+θjk- 1,
where Sk=sjl, for j=1,2,,m and l=1,2,,m, is a lower triangular matrix such that:
sjl= -minmaxhjl/D3,-BL,BL, j>l -minmaxhjj/2D3-D4/D2,-BD,BD, j=l ,
where G02HLF is based on routines in ROBETH; see Marazzi (1987).

4  References

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

5  Parameters

1:     UCV – SUBROUTINE, supplied by the user.External Procedure
UCV must return the values of the functions u and w and their derivatives for a given value of its argument.
The specification of UCV is:
SUBROUTINE UCV ( T, RUSER, U, UD, W, WD)
REAL (KIND=nag_wp)  T, RUSER(*), U, UD, W, WD
1:     T – REAL (KIND=nag_wp)Input
On entry: the argument for which the functions u and w must be evaluated.
2:     RUSER(*) – REAL (KIND=nag_wp) arrayUser Workspace
UCV is called with the parameter RUSER as supplied to G02HLF. You are free to use the array RUSER to supply information to UCV as an alternative to using COMMON global variables.
3:     U – REAL (KIND=nag_wp)Output
On exit: the value of the u function at the point T.
Constraint: U0.0.
4:     UD – REAL (KIND=nag_wp)Output
On exit: the value of the derivative of the u function at the point T.
5:     W – REAL (KIND=nag_wp)Output
On exit: the value of the w function at the point T.
Constraint: W0.0.
6:     WD – REAL (KIND=nag_wp)Output
On exit: the value of the derivative of the w function at the point T.
UCV must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which G02HLF is called. Parameters denoted as Input must not be changed by this procedure.
2:     RUSER(*) – REAL (KIND=nag_wp) arrayUser Workspace
RUSER is not used by G02HLF, but is passed directly to UCV and may be used to pass information to this routine as an alternative to using COMMON global variables.
3:     INDM – INTEGERInput
On entry: indicates which form of the function v will be used.
INDM=1
v=1.
INDM1
v=u.
4:     N – INTEGERInput
On entry: n, the number of observations.
Constraint: N>1.
5:     M – INTEGERInput
On entry: m, the number of columns of the matrix X, i.e., number of independent variables.
Constraint: 1MN.
6:     X(LDX,M) – REAL (KIND=nag_wp) arrayInput
On entry: Xij must contain the ith observation on the jth variable, for i=1,2,,n and j=1,2,,m.
7:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G02HLF is called.
Constraint: LDXN.
8:     COV(M×M+1/2) – REAL (KIND=nag_wp) arrayOutput
On exit: contains a robust estimate of the covariance matrix, C. The upper triangular part of the matrix C is stored packed by columns (lower triangular stored by rows), Cij is returned in COVj×j-1/2+i, ij.
9:     A(M×M+1/2) – REAL (KIND=nag_wp) arrayInput/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 0, and in practice will usually be >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.
Constraint: Aj×j-1/2+j0.0, for j=1,2,,m.
On exit: the lower triangular elements of the inverse of the matrix A, stored row-wise.
10:   WT(N) – REAL (KIND=nag_wp) arrayOutput
On exit: WTi contains the weights, wti=uzi2, for i=1,2,,n.
11:   THETA(M) – REAL (KIND=nag_wp) arrayInput/Output
On entry: an initial estimate of the location parameter, θj, for j=1,2,,m.
In many cases an initial estimate of θj=0, for j=1,2,,m, will be adequate. Alternatively medians may be used as given by G07DAF.
On exit: contains the robust estimate of the location parameter, θj, for j=1,2,,m.
12:   BL – REAL (KIND=nag_wp)Input
On entry: the magnitude of the bound for the off-diagonal elements of Sk, BL.
Suggested value: BL=0.9.
Constraint: BL>0.0.
13:   BD – REAL (KIND=nag_wp)Input
On entry: the magnitude of the bound for the diagonal elements of Sk, BD.
Suggested value: BD=0.9.
Constraint: BD>0.0.
14:   MAXIT – INTEGERInput
On entry: the maximum number of iterations that will be used during the calculation of A.
Suggested value: MAXIT=150.
Constraint: MAXIT>0.
15:   NITMON – INTEGERInput
On entry: indicates the amount of information on the iteration that is printed.
NITMON>0
The value of A, θ and δ (see Section 7) will be printed at the first and every NITMON iterations.
NITMON0
No iteration monitoring is printed.
When printing occurs the output is directed to the current advisory message unit (see X04ABF).
16:   TOL – REAL (KIND=nag_wp)Input
On entry: the relative precision for the final estimates of the covariance matrix. Iteration will stop when maximum δ (see Section 7) is less than TOL.
Constraint: TOL>0.0.
17:   NIT – INTEGEROutput
On exit: the number of iterations performed.
18:   WK(2×M) – REAL (KIND=nag_wp) arrayWorkspace
19:   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, if you are not familiar with this parameter, the recommended value is 0. 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).
Errors or warnings detected by the routine:
IFAIL=1
On entry,N1,
orM<1,
orN<M,
orLDX<N.
IFAIL=2
On entry,TOL0.0,
orMAXIT0,
ordiagonal element of A=0.0,
orBL0.0,
orBD0.0.
IFAIL=3
A column of X has a constant value.
IFAIL=4
Value of U or W returned by UCV<0.
IFAIL=5
The routine has failed to converge in MAXIT iterations.
IFAIL=6
One of the following is zero: D1, D2 or D3.
This may be caused by the functions u or w being too strict for the current estimate of A (or C). You should try either a larger initial estimate of A or make u and w less strict.

7  Accuracy

On successful exit the accuracy of the results is related to the value of TOL; see Section 5. At an iteration let
(i) d1= the maximum value of sjl
(ii) d2= the maximum absolute change in wti
(iii) d3= the maximum absolute relative change in θj
and let δ=maxd1,d2,d3. Then the iterative procedure is assumed to have converged when δ<TOL.

8  Further Comments

The existence of A will depend upon the function u (see 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.

9  Example

A sample of 10 observations on three variables is read in along with initial values for A and THETA and parameter values for the u and w functions, cu and cw. The covariance matrix computed by G02HLF is printed along with the robust estimate of θ. UCV computes the Huber's weight functions:
ut=1, if  tcu2 ut= cut2, if  t>cu2
and
wt= 1, if   tcw wt= cwt, if   t>cw
and their derivatives.

9.1  Program Text

Program Text (g02hlfe.f90)

9.2  Program Data

Program Data (g02hlfe.d)

9.3  Program Results

Program Results (g02hlfe.r)


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

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