NAG CL Interface
g02hkc (robustm_​corr_​huber)

Settings help

CL Name Style:

1 Purpose

g02hkc computes a robust estimate of the covariance matrix for an expected fraction of gross errors.

2 Specification

#include <nag.h>
void  g02hkc (Integer n, Integer m, const double x[], Integer tdx, double eps, double cov[], double theta[], Integer max_iter, Integer print_iter, const char *outfile, double tol, Integer *iter, NagError *fail)
The function may be called by the names: g02hkc, nag_correg_robustm_corr_huber or nag_robust_corr_estim.

3 Description

For a set 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 = τ 2 (ATA) −1  
where τ 2 is a correction factor and A is a lower triangular matrix found as the solution to the following equations.
z i = A ( x i -θ)  
1 n i=1 n w ( z i 2 ) z i = 0  
1 n i=1 n u ( z i 2 ) z i ziT - I = 0 ,  
where x i is a vector of length m containing the elements of the i th row of X,
z i is a vector of length m ,
I is the identity matrix and 0 is the zero matrix,
and w and u are suitable functions.
g02hkc uses weight functions:
u (t) = a u t 2 , if ​ t < a u 2 u (t) = 1 , if ​ a u 2 t b u 2 u (t) = b u t 2 , if ​ t > b u 2  
w (t) = 1 , if ​ t c w w (t) = c w t , if ​ t > c w  
for constants a u , b u and c w .
These functions solve a minimax problem considered by Huber (1981).
The values of a u , b u and c w are calculated from the expected fraction of gross errors, ε (see Huber (1981) and Marazzi (1987)). The expected fraction of gross errors is the estimated proportion of outliers in the sample.
In order to make the estimate asymptotically unbiased under a Normal model a correction factor, τ 2 , is calculated, (see Huber (1981) and Marazzi (1987)).
Initial estimates of θ j , for j=1,2,,m, are given by the median of the j th column of X and the initial value of A is based on the median absolute deviation (see Marazzi (1987)). g02hkc 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: n Integer Input
On entry: the number of observations, n .
Constraint: n>1 .
2: m Integer Input
On entry: the number of columns of the matrix X , i.e., number of independent variables, m .
Constraint: 1 m n .
3: x[n×tdx] const double Input
On entry: x[(i-1)×tdx+j-1] must contain the i th observation for the j th variable, for i=1,2,,n and j=1,2,,m.
4: tdx Integer Input
On entry: the stride separating matrix column elements in the array x.
Constraint: tdxm .
5: eps double Input
On entry: the expected fraction of gross errors expected in the sample, ε .
Constraint: 0.0 eps < 1.0 .
6: cov[m×(m+1)/2] double Output
On exit: the m × (m+1) /2 elements of cov contain the upper triangular part of the covariance matrix. They are stored packed by column, i.e., C ij , ji , is stored in cov[ j (j+1) / 2 + i ] , for i=0,1,,m - 1 and j=i,,m - 1.
7: theta[m] double Output
On exit: the robust estimate of the location arguments θ j , for j=1,2,,m.
8: max_iter Integer Input
On entry: the maximum number of iterations that will be used during the calculation of the covariance matrix.
Suggested value: max_iter=150 .
Constraint: max_iter>0 .
On entry: indicates if the printing of information on the iterations is required and the rate at which printing is produced.
No iteration monitoring is printed.
The value of A , θ and δ (see Section 9) will be printed at the first and every print_iter iterations.
10: outfile const char * Input
On entry: a null terminated character string giving the name of the file to which results should be printed. If outfile is NULL or an empty string then the stdout stream is used. Note that the file will be opened in the append mode.
11: tol double Input
On entry: the relative precision for the final estimates of the covariance matrix.
Constraint: tol>0.0 .
12: iter Integer * Output
On exit: the number of iterations performed.
13: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

On entry, m=value while n=value . These arguments must satisfy mn .
On entry, tdx=value while m=value . These arguments must satisfy tdxm .
Dynamic memory allocation failed.
The iterative procedure to find C has become unstable. This may happen if the value of eps is too large.
On entry, column value of array x has constant value.
On entry, max_iter must not be less than or equal to 0: max_iter=value .
On entry, m=value.
Constraint: m1.
On entry, n=value.
Constraint: n2.
Cannot open file string for appending.
Cannot close file string .
On entry, eps must be not be greater than or equal to 1.0: eps=value .
On entry, tol must not be less than or equal to 0.0: tol=value .
On entry, eps must not be less than 0.0: eps=value .
Too many iterations(value ).
The iterative procedure to find the co-variance matrix C , has failed to converge in max_iter iterations.

7 Accuracy

On successful exit the accuracy of the results is related to the value of tol, see Section 5. At an iteration let
  1. (i) d1 = the maximum value of the absolute relative change in A
  2. (ii) d2 = the maximum absolute change in u ( z i 2 )
  3. (iii) d3 = the maximum absolute relative change in θ j
and let δ = max(d1,d2,d3) . Then the iterative procedure is assumed to have converged when δ<tol .

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g02hkc 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

The existence of A , and hence c , 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.

10 Example

A sample of 10 observations on three variables is read in and the robust estimate of the covariance matrix is computed assuming 10% gross errors are to be expected. The robust covariance is then printed.

10.1 Program Text

Program Text (g02hkce.c)

10.2 Program Data

Program Data (g02hkce.d)

10.3 Program Results

Program Results (g02hkce.r)