hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_correg_robustm_corr_huber (g02hk)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_correg_robustm_corr_huber (g02hk) computes a robust estimate of the covariance matrix for an expected fraction of gross errors.


[covar, theta, nit, ifail] = g02hk(x, eps, 'n', n, 'm', m, 'maxit', maxit, 'nitmon', nitmon, 'tol', tol)
[covar, theta, nit, ifail] = nag_correg_robustm_corr_huber(x, eps, 'n', n, 'm', m, 'maxit', maxit, 'nitmon', nitmon, 'tol', tol)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: nitmon and tol were made optional
At Mark 22: n was made optional


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
where τ2 is a correction factor and A is a lower triangular matrix found as the solution to the following equations:
1n i= 1nwzi2zi=0,  
1ni=1nuzi2zi ziT -I=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.
nag_correg_robustm_corr_huber (g02hk) uses weight functions:
ut= aut2, if ​t<au2 ut=1, if ​au2tbu2 ut= but2, if ​t>bu2  
wt= 1, if ​tcw wt= cwt, if ​t>cw  
for constants au, bu and cw.
These functions solve a minimax problem considered by Huber (see Huber (1981)). The values of au, bu and cw 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)).
The matrix C is calculated using nag_correg_robustm_corr_user_deriv (g02hl). Initial estimates of θj, for j=1,2,,m, are given by the median of the jth column of X and the initial value of A is based on the median absolute deviation (see Marazzi (1987)). nag_correg_robustm_corr_huber (g02hk) is based on routines in ROBETH; see Marazzi (1987).


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


Compulsory Input Parameters

1:     xldxm – double array
ldx, the first dimension of the array, must satisfy the constraint ldxn.
xij must contain the ith observation for the jth variable, for i=1,2,,n and j=1,2,,m.
2:     eps – double scalar
ε, the expected fraction of gross errors expected in the sample.
Constraint: 0.0eps<1.0.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the first dimension of the array x.
n, the number of observations.
Constraint: n>1.
2:     m int64int32nag_int scalar
Default: the second dimension of the array x.
m, the number of columns of the matrix X, i.e., number of independent variables.
Constraint: 1mn.
3:     maxit int64int32nag_int scalar
Default: 150.
The maximum number of iterations that will be used during the calculation of the covariance matrix.
Constraint: maxit>0.
4:     nitmon int64int32nag_int scalar
Default: 0
Indicates the amount of information on the iteration that is printed.
The value of A, θ and δ (see Accuracy) will be printed at the first and every nitmon iterations.
No iteration monitoring is printed.
When printing occurs the output is directed to the current advisory message unit (see nag_file_set_unit_advisory (x04ab)).
5:     tol – double scalar
Default: 5e-5
The relative precision for the final estimates of the covariance matrix.
Constraint: tol>0.0.

Output Parameters

1:     covarm×m+1/2 – double array
A robust estimate of the covariance matrix, C. The upper triangular part of the matrix C is stored packed by columns. Cij is returned in covarj×j-1/2+i, ij.
2:     thetam – double array
The robust estimate of the location arguments θj, for j=1,2,,m.
3:     nit int64int32nag_int scalar
The number of iterations performed.
4:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
On entry,n1,
On entry,a variable has a constant value, i.e., all elements in a column of X are identical.
The iterative procedure to find C has failed to converge in maxit iterations.
The iterative procedure to find C has become unstable. This may happen if the value of eps is too large for the sample.
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


On successful exit the accuracy of the results is related to the value of tol; see Arguments. At an iteration let
(i) d1= the maximum value of the absolute relative change in A
(ii) d2= the maximum absolute change in uzi2
(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

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.


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.
function g02hk_example

fprintf('g02hk example results\n\n');

x = [3.4, 6.9, 12.2;
     6.4, 2.5, 15.1;
     4.9, 5.5, 14.2;
     7.3, 1.9, 18.2;
     8.8, 3.6, 11.7;
     8.4, 1.3, 17.9;
     5.3, 3.1, 15.0;
     2.7, 8.1,  7.7;
     6.1, 3.0, 21.9;
     5.3, 2.2, 13.9];
epsilon = 0.1;

% Compute robust estimate of variance / covariance matrix
[covar, theta, nit, ifail] = g02hk( ...
                                    x, epsilon);

fprintf(' iterations to convergence = %4d\n\n', nit);
mtitle = 'Covariance matrix';
n = int64(size(x,2));
uplo   = 'Upper';
diag   = 'Non-unit';
[ifail] = x04cc( ...
                 uplo, diag, n, covar, mtitle);

g02hk example results

 iterations to convergence =   23

 Covariance matrix
             1          2          3
 1      3.4611    -3.6806     4.6818
 2                 5.3477    -6.6445
 3                           14.4389


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015