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

NAG Library Routine Document

G02HMF

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

G02HMF computes a robust estimate of the covariance matrix for user-supplied weight functions. The derivatives of the weight functions are not required.

2  Specification

SUBROUTINE G02HMF ( 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.
G02HMF 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)).
G02HMF finds A using the iterative procedure as given by Huber; see Huber (1981).
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/D2,-BL,BL, j>l -minmax12hjj/D2-1,-BD,BD, j=l ,
where and BD and BL are suitable bounds.
The value of τ may be chosen so that C is unbiased if the observations are from a given distribution.
G02HMF 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 for a given value of its argument.
The specification of UCV is:
SUBROUTINE UCV ( T, RUSER, U, W)
REAL (KIND=nag_wp)  T, RUSER(*), U, W
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 G02HMF. 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:     W – REAL (KIND=nag_wp)Output
On exit: the value of the w function at the point T.
Constraint: W0.0.
UCV must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which G02HMF 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 G02HMF, 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 G02HMF is called.
Constraint: LDXN.
8:     COV(M×M+1/2) – REAL (KIND=nag_wp) arrayOutput
On exit: 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), that is 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 channel (See X04ABF.)
16:   TOL – REAL (KIND=nag_wp)Input
On entry: the relative precision for the final estimate 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
Either the sum D1 or the sum D2 is zero. This may be caused by the functions u or w being too strict for the current estimate of A (or C). You should either try a larger initial estimate of A or make the u and w functions 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.
If derivatives of the u and w functions are available then the method used in G02HLF will usually give much faster convergence.

9  Example

A sample of 10 observations on three variables is read in along with initial values for A and θ and parameter values for the u and w functions, cu and cw. The covariance matrix computed by G02HMF 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.

9.1  Program Text

Program Text (g02hmfe.f90)

9.2  Program Data

Program Data (g02hmfe.d)

9.3  Program Results

Program Results (g02hmfe.r)


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

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