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

Syntax

C#
public static void g02hm(
	G02..::..G02HM_UCV ucv,
	int indm,
	int n,
	int m,
	double[,] x,
	double[] cov,
	double[] a,
	double[] wt,
	double[] theta,
	double bl,
	double bd,
	int maxit,
	int nitmon,
	double tol,
	out int nit,
	out int ifail
)
Visual Basic
Public Shared Sub g02hm ( _
	ucv As G02..::..G02HM_UCV, _
	indm As Integer, _
	n As Integer, _
	m As Integer, _
	x As Double(,), _
	cov As Double(), _
	a As Double(), _
	wt As Double(), _
	theta As Double(), _
	bl As Double, _
	bd As Double, _
	maxit As Integer, _
	nitmon As Integer, _
	tol As Double, _
	<OutAttribute> ByRef nit As Integer, _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g02hm(
	G02..::..G02HM_UCV^ ucv, 
	int indm, 
	int n, 
	int m, 
	array<double,2>^ x, 
	array<double>^ cov, 
	array<double>^ a, 
	array<double>^ wt, 
	array<double>^ theta, 
	double bl, 
	double bd, 
	int maxit, 
	int nitmon, 
	double tol, 
	[OutAttribute] int% nit, 
	[OutAttribute] int% ifail
)
F#
static member g02hm : 
        ucv : G02..::..G02HM_UCV * 
        indm : int * 
        n : int * 
        m : int * 
        x : float[,] * 
        cov : float[] * 
        a : float[] * 
        wt : float[] * 
        theta : float[] * 
        bl : float * 
        bd : float * 
        maxit : int * 
        nitmon : int * 
        tol : float * 
        nit : int byref * 
        ifail : int byref -> unit 

Parameters

ucv
Type: NagLibrary..::..G02..::..G02HM_UCV
ucv must return the values of the functions u and w for a given value of its argument.

A delegate of type G02HM_UCV.

indm
Type: System..::..Int32
On entry: indicates which form of the function v will be used.
indm=1
v=1.
indm1
v=u.
n
Type: System..::..Int32
On entry: n, the number of observations.
Constraint: n>1.
m
Type: System..::..Int32
On entry: m, the number of columns of the matrix X, i.e., number of independent variables.
Constraint: 1mn.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, m]
Note: dim1 must satisfy the constraint: dim1n
On entry: x[i-1,j-1] must contain the ith observation on the jth variable, for i=1,2,,n and j=1,2,,m.
cov
Type: array<System..::..Double>[]()[][]
An array of size [m×m+1/2]
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 cov[j×j-1/2+i-1], ij.
a
Type: array<System..::..Double>[]()[][]
An array of size [m×m+1/2]
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: a[j×j-1/2+j]0.0, for j=0,1,,m-1.
On exit: the lower triangular elements of the inverse of the matrix A, stored row-wise.
wt
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: wt[i-1] contains the weights, wti=uzi2, for i=1,2,,n.
theta
Type: array<System..::..Double>[]()[][]
An array of size [m]
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 not in this release).
On exit: contains the robust estimate of the location parameter, θj, for j=1,2,,m.
bl
Type: System..::..Double
On entry: the magnitude of the bound for the off-diagonal elements of Sk, BL.
Suggested value: bl=0.9.
Constraint: bl>0.0.
bd
Type: System..::..Double
On entry: the magnitude of the bound for the diagonal elements of Sk, BD.
Suggested value: bd=0.9.
Constraint: bd>0.0.
maxit
Type: System..::..Int32
On entry: the maximum number of iterations that will be used during the calculation of A.
Suggested value: maxit=150.
Constraint: maxit>0.
nitmon
Type: System..::..Int32
On entry: indicates the amount of information on the iteration that is printed.
nitmon>0
The value of A, θ and δ (see [Accuracy]) will be printed at the first and every nitmon iterations.
nitmon0
No iteration monitoring is printed.
tol
Type: System..::..Double
On entry: the relative precision for the final estimate of the covariance matrix. Iteration will stop when maximum δ (see [Accuracy]) is less than tol.
Constraint: tol>0.0.
nit
Type: System..::..Int32%
On exit: the number of iterations performed.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

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-θ
1ni=1nwzi2zi=0
and
1ni=1nuzi2ziziT-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.
g02hm 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)).
g02hm 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
  • D1=i=1nwzi2
  • D2=i=1nuzi2
  • hjl=i=1nuzi2zijzil, for jl
  • bj=i=1nwzi2xij-bj
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.
g02hm is based on routines in ROBETH; see Marazzi (1987).

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

Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDX) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
ifail=1
On entry,n1,
orm<1,
orn<m,
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 method 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.
ifail=-9000
An error occured, see message report.
ifail=-6000
Invalid Parameters value
ifail=-4000
Invalid dimension for array value
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

On successful exit the accuracy of the results is related to the value of tol; see [Parameters]. 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.

Parallelism and Performance

None.

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 g02hl will usually give much faster convergence.

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 g02hm is printed along with the robust estimate of θ.
ucv computes the Huber's weight functions:
ut=1,if  tcu2ut=cut2,if  t>cu2
and
wt=1,if  tcwwt=cwt,if  t>cw.

Example program (C#): g02hme.cs

Example program data: g02hme.d

Example program results: g02hme.r

See Also