NAG Library Routine Document

g02hmf (robustm_corr_user)

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

Fortran Interface
Subroutine g02hmf ( ucv, ruser, indm, n, m, x, ldx, cov, a, wt, theta, bl, bd, maxit, nitmon, tol, nit, wk, ifail)
Integer, Intent (In):: indm, n, m, ldx, maxit, nitmon
Integer, Intent (Inout):: ifail
Integer, Intent (Out):: nit
Real (Kind=nag_wp), Intent (In):: x(ldx,m), bl, bd, tol
Real (Kind=nag_wp), Intent (Inout):: ruser(*), a(m*(m+1)/2), theta(m)
Real (Kind=nag_wp), Intent (Out):: cov(m*(m+1)/2), wt(n), wk(2*m)
External:: ucv
C Header Interface
#include <nagmk26.h>
void  g02hmf_ (
void (NAG_CALL *ucv)(const double *t, double ruser[], double *u, double *w),
double ruser[], const Integer *indm, const Integer *n, const Integer *m, const double x[], const Integer *ldx, double cov[], double a[], double wt[], double theta[], const double *bl, const double *bd, const Integer *maxit, const Integer *nitmon, const double *tol, Integer *nit, double wk[], Integer *ifail)

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
Arguments

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:
Fortran Interface
Subroutine ucv ( t, ruser, u, w)
Real (Kind=nag_wp), Intent (In):: t
Real (Kind=nag_wp), Intent (Inout):: ruser(*)
Real (Kind=nag_wp), Intent (Out):: u, w
C Header Interface
#include <nagmk26.h>
void  ucv (const double *t, double ruser[], double *u, double *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 argument ruser as supplied to g02hmf. You should use the array ruser to supply information to ucv.
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. Arguments denoted as Input must not be changed by this procedure.
Note: ucv should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by g02hmf. If your code inadvertently does return any NaNs or infinities, g02hmf is likely to produce unexpected results.
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.
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:     xldxm – 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:     covm×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:     am×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:   wtn – Real (Kind=nag_wp) arrayOutput
On exit: wti contains the weights, wti=uzi2, for i=1,2,,n.
11:   thetam – 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:   wk2×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 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, if you are not familiar with this argument, 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, ldx=value and n=value.
Constraint: ldxn.
On entry, m=value.
Constraint: m1.
On entry, n=value.
Constraint: n2.
On entry, n=value and m=value.
Constraint: nm.
ifail=2
On entry, bd=value.
Constraint: bd>0.0.
On entry, bl=value.
Constraint: bl>0.0.
On entry, i=value and the ith diagonal element of A is 0.
Constraint: all diagonal elements of A must be non-zero.
On entry, maxit=value.
Constraint: maxit>0.
On entry, tol=value.
Constraint: tol>0.0.
ifail=3
On entry, a variable has a constant value, i.e., all elements in column value of x are identical.
ifail=4
u value returned by ucv<0.0: uvalue=value.
Constraint: u0.0.
w value returned by ucv<0.0: wvalue=value.
Constraint: w0.0.
ifail=5
Iterations to calculate weights failed to converge.
ifail=6
The sum D1 is zero. Try either a larger initial estimate of A or make u and w less strict.
The sum D2 is zero. Try either a larger initial estimate of A or make u and w less strict.
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

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
Parallelism and Performance

g02hmf 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

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.

10
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.  

10.1
Program Text

Program Text (g02hmfe.f90)

10.2
Program Data

Program Data (g02hmfe.d)

10.3
Program Results

Program Results (g02hmfe.r)