g02ha performs bounded influence regression (M-estimates). Several standard methods are available.

Syntax

C#
public static void g02ha(
	int indw,
	int ipsi,
	int isigma,
	int indc,
	int n,
	int m,
	double[,] x,
	double[] y,
	double cpsi,
	double h1,
	double h2,
	double h3,
	double cucv,
	double dchi,
	double[] theta,
	ref double sigma,
	double[,] c,
	double[] rs,
	double[] wgt,
	double tol,
	int maxit,
	int nitmon,
	double[] stat,
	out int ifail
)
Visual Basic
Public Shared Sub g02ha ( _
	indw As Integer, _
	ipsi As Integer, _
	isigma As Integer, _
	indc As Integer, _
	n As Integer, _
	m As Integer, _
	x As Double(,), _
	y As Double(), _
	cpsi As Double, _
	h1 As Double, _
	h2 As Double, _
	h3 As Double, _
	cucv As Double, _
	dchi As Double, _
	theta As Double(), _
	ByRef sigma As Double, _
	c As Double(,), _
	rs As Double(), _
	wgt As Double(), _
	tol As Double, _
	maxit As Integer, _
	nitmon As Integer, _
	stat As Double(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g02ha(
	int indw, 
	int ipsi, 
	int isigma, 
	int indc, 
	int n, 
	int m, 
	array<double,2>^ x, 
	array<double>^ y, 
	double cpsi, 
	double h1, 
	double h2, 
	double h3, 
	double cucv, 
	double dchi, 
	array<double>^ theta, 
	double% sigma, 
	array<double,2>^ c, 
	array<double>^ rs, 
	array<double>^ wgt, 
	double tol, 
	int maxit, 
	int nitmon, 
	array<double>^ stat, 
	[OutAttribute] int% ifail
)
F#
static member g02ha : 
        indw : int * 
        ipsi : int * 
        isigma : int * 
        indc : int * 
        n : int * 
        m : int * 
        x : float[,] * 
        y : float[] * 
        cpsi : float * 
        h1 : float * 
        h2 : float * 
        h3 : float * 
        cucv : float * 
        dchi : float * 
        theta : float[] * 
        sigma : float byref * 
        c : float[,] * 
        rs : float[] * 
        wgt : float[] * 
        tol : float * 
        maxit : int * 
        nitmon : int * 
        stat : float[] * 
        ifail : int byref -> unit 

Parameters

indw
Type: System..::..Int32
On entry: specifies the type of regression to be performed.
indw<0
Mallows type regression with Maronna's proposed weights.
indw=0
Huber type regression.
indw>0
Schweppe type regression with Krasker–Welsch weights.
ipsi
Type: System..::..Int32
On entry: specifies which ψ function is to be used.
ipsi=0
ψt=t, i.e., least squares.
ipsi=1
Huber's function.
ipsi=2
Hampel's piecewise linear function.
ipsi=3
Andrew's sine wave.
ipsi=4
Tukey's bi-weight.
Constraint: 0ipsi4.
isigma
Type: System..::..Int32
On entry: specifies how σ is to be estimated.
isigma<0
σ is estimated by median absolute deviation of residuals.
isigma=0
σ is held constant at its initial value.
isigma>0
σ is estimated using the χ function.
indc
Type: System..::..Int32
On entry: if indw0, indc specifies the approximations used in estimating the covariance matrix of θ^.
indc=1
Averaging over residuals.
indc1
Replacing expected by observed.
indw=0
indc is not referenced.
n
Type: System..::..Int32
On entry: n, the number of observations.
Constraint: n>1.
m
Type: System..::..Int32
On entry: m, the number of independent variables.
Constraint: 1m<n.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, m]
Note: dim1 must satisfy the constraint: dim1n
On entry: the values of the X matrix, i.e., the independent variables. x[i-1,j-1] must contain the ijth element of X, for i=1,2,,n and j=1,2,,m.
If indw<0, then during calculations the elements of x will be transformed as described in [Description]. Before exit the inverse transformation will be applied. As a result there may be slight differences between the input x and the output x.
On exit: unchanged, except as described above.
y
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: the data values of the dependent variable.
y[i-1] must contain the value of y for the ith observation, for i=1,2,,n.
If indw<0, then during calculations the elements of y will be transformed as described in [Description]. Before exit the inverse transformation will be applied. As a result there may be slight differences between the input y and the output y.
On exit: unchanged, except as described above.
cpsi
Type: System..::..Double
On entry: if ipsi=1, cpsi must specify the parameter, c, of Huber's ψ function.
If ipsi1 on entry, cpsi is not referenced.
Constraint: if cpsi>0.0, ipsi=1.
h1
Type: System..::..Double
On entry: if ipsi=2, h1, h2, and h3 must specify the parameters h1, h2, and h3, of Hampel's piecewise linear ψ function. h1, h2, and h3 are not referenced if ipsi2.
Constraint: if ipsi=2, 0.0h1h2h3 and h3>0.0.
h2
Type: System..::..Double
On entry: if ipsi=2, h1, h2, and h3 must specify the parameters h1, h2, and h3, of Hampel's piecewise linear ψ function. h1, h2, and h3 are not referenced if ipsi2.
Constraint: if ipsi=2, 0.0h1h2h3 and h3>0.0.
h3
Type: System..::..Double
On entry: if ipsi=2, h1, h2, and h3 must specify the parameters h1, h2, and h3, of Hampel's piecewise linear ψ function. h1, h2, and h3 are not referenced if ipsi2.
Constraint: if ipsi=2, 0.0h1h2h3 and h3>0.0.
cucv
Type: System..::..Double
On entry: if indw<0, must specify the value of the constant, c, of the function u for Maronna's proposed weights.
If indw>0, must specify the value of the function u for the Krasker–Welsch weights.
If indw=0, is not referenced.
Constraints:
  • if indw<0, cucvm;
  • if indw>0, cucvm.
dchi
Type: System..::..Double
On entry: d, the constant of the χ function. dchi is not referenced if ipsi=0, or if isigma0.
Constraint: if ipsi0 and isigma>0, dchi>0.0.
theta
Type: array<System..::..Double>[]()[][]
An array of size [m]
On entry: starting values of the parameter vector θ. These may be obtained from least squares regression. Alternatively if isigma<0 and sigma=1 or if isigma>0 and sigma approximately equals the standard deviation of the dependent variable, y, then theta[i-1]=0.0, for i=1,2,,m may provide reasonable starting values.
On exit: theta[i-1] contains the M-estimate of θi, for i=1,2,,m.
sigma
Type: System..::..Double%
On entry: a starting value for the estimation of σ. sigma should be approximately the standard deviation of the residuals from the model evaluated at the value of θ given by theta on entry.
Constraint: sigma>0.0.
On exit: contains the final estimate of σ if isigma0 or the value assigned on entry if isigma=0.
c
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, m]
Note: dim1 must satisfy the constraint: dim1m
On exit: the diagonal elements of c contain the estimated asymptotic standard errors of the estimates of θ, i.e., c[i-1,i-1] contains the estimated asymptotic standard error of the estimate contained in theta[i-1].
The elements above the diagonal contain the estimated asymptotic correlation between the estimates of θ, i.e., c[i-1,j-1], 1i<jm contains the asymptotic correlation between the estimates contained in theta[i-1] and theta[j-1].
The elements below the diagonal contain the estimated asymptotic covariance between the estimates of θ, i.e., c[i-1,j-1], 1j<im contains the estimated asymptotic covariance between the estimates contained in theta[i-1] and theta[j-1].
rs
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the residuals from the model evaluated at final value of theta, i.e., rs contains the vector y-Xθ^.
wgt
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the vector of weights. wgt[i-1] contains the weight for the ith observation, for i=1,2,,n.
tol
Type: System..::..Double
On entry: the relative precision for the calculation of A (if indw0), the estimates of θ and the estimate of σ (if isigma0). Convergence is assumed when the relative change in all elements being considered is less than tol.
If indw<0 and isigma<0, tol is also used to determine the precision of β1.
It is advisable for tol to be greater than 100×machine precision.
Constraint: tol>0.0.
maxit
Type: System..::..Int32
On entry: the maximum number of iterations that should be used in the calculation of A (if indw0), and of the estimates of θ and σ, and of β1 (if indw<0 and isigma<0).
A value of maxit=50 should be adequate for most uses.
Constraint: maxit>0.
nitmon
Type: System..::..Int32
On entry: the amount of information that is printed on each iteration.
nitmon=0
No information is printed.
nitmon0
The current estimate of θ, the change in θ during the current iteration and the current value of σ are printed on the first and every absnitmon iterations.
Also, if indw0 and nitmon>0 then information on the iterations to calculate A is printed. This is the current estimate of A and the maximum value of Sij (see [Description]).
When printing occurs the output is directed to the current advisory message unit (see (X04ABF not in this release)).
stat
Type: array<System..::..Double>[]()[][]
An array of size [4]
On exit: the following values are assigned to stat:
  • stat[0]=β1 if isigma<0, or stat[0]=β2 if isigma>0.
  • stat[1]= number of iterations used to calculate A.
  • stat[2]= number of iterations used to calculate final estimates of θ and σ.
  • stat[3]=k, the rank of the weighted least-squares equations.
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 the linear regression model
y=Xθ+ε,
where y is a vector of length n of the dependent variable,
X is a n by m matrix of independent variables of column rank k,
θ is a vector of length m of unknown parameters,
and ε is a vector of length n of unknown errors with varεi=σ2,
g02ha calculates the M-estimates given by the solution, θ^, to the equation
i=1nψri/σwiwixij=0,  j=1,2,,m, (1)
where ri is the ith residual, i.e., the ith element of r=y-Xθ^,
ψ is a suitable weight function,
wi are suitable weights,
and σ may be estimated at each iteration by the median absolute deviation of the residuals
σ^=mediri/β1
or as the solution to
i=1nχri/σ^wiwi2=n-kβ2
for suitable weight function χ, where β1 and β2 are constants, chosen so that the estimator of σ is asymptotically unbiased if the errors, εi, have a Normal distribution. Alternatively σ may be held at a constant value.
The above describes the Schweppe type regression. If the wi are assumed to equal 1 for all i then Huber type regression is obtained. A third type, due to Mallows, replaces (1) by
i=1nψri/σwixij=0,  j=1,2,,m.
This may be obtained by use of the transformations
wi*wiyi*yiwixij*xijwi,j=1,2,,m
(see Section 3 of Marazzi (1987a)).
For Huber and Schweppe type regressions, β1 is the 75th percentile of the standard Normal distribution. For Mallows type regression β1 is the solution to
1ni=1nΦβ1/wi=0.75,
where Φ is the standard Normal cumulative distribution function (see s15ab).
β2 is given by
β2=-χzϕzdzin the Huber case;β2=1ni=1nwi-χzϕzdzin the Mallows case;β2=1ni=1nwi2-χz/wiϕzdzin the Schweppe case;
where ϕ is the standard Normal density, i.e., 12πexp-12x2.
The calculation of the estimates of θ can be formulated as an iterative weighted least squares problem with a diagonal weight matrix G given by
Gii=ψri/σwiri/σwi,ri0ψ0,ri=0,
where ψt is the derivative of ψ at the point t.
The value of θ at each iteration is given by the weighted least squares regression of y on X. This is carried out by first transforming the y and X by
y~i=yiGiix~ij=xijGii,j=1,2,,m
and then using (F04JGF not in this release). If X is of full column rank then an orthogonal-triangular (QR) decomposition is used; if not, a singular value decomposition is used.
The following functions are available for ψ and χ in g02ha.
(a) Unit Weights
ψt=t,  χt=t22.
This gives least squares regression.
(b) Huber's Function
ψt=max-c,minc,t,  χt=t22,tdd22,t>d
(c) Hampel's Piecewise Linear Function
ψh1,h2,h3t=-ψh1,h2,h3-t=t,0th1h1,h1th2h1h3-t/h3-h2,h2th30,h3<t
χt=t22,tdd22,t>d
(d) Andrew's Sine Wave Function
ψt=sint,-πtπ0,t>πχt=t22,tdd22,t>d
(e) Tukey's Bi-weight
ψt=t1-t22,t10,t>1χt=t22,tdd22,t>d
where c, h1, h2, h3, and d are given constants.
Several schemes for calculating weights have been proposed, see Hampel et al. (1986) and Marazzi (1987a). As the different independent variables may be measured on different scales, one group of proposed weights aims to bound a standardized measure of influence. To obtain such weights the matrix A has to be found such that:
1ni=1nuzi2ziziT=I
and
zi=Axi,
where xi is a vector of length m containing the ith row of X,
A is an m by m lower triangular matrix,
and u is a suitable function.
The weights are then calculated as
wi=fzi2
for a suitable function f.
g02ha finds A using the iterative procedure
Ak=Sk+IAk-1,
where Sk=sjl,
sjl=-minmaxhjl/n,-BL,BL,j>l-minmax12hjj/n-1,-BD,BD,j=l
and
hjl=i=1nuzi2zijzil
and BL and BD are bounds set at 0.9.
Two weights are available in g02ha:
(i) Krasker–Welsch Weights
ut=g1ct,
where g1t=t2+1-t22Φt-1-2tϕt,
Φt is the standard Normal cumulative distribution function,
ϕt is the standard Normal probability density function,
and ft=1t.
These are for use with Schweppe type regression.
(ii) Maronna's Proposed Weights
ut=ct2t>c1tcft=ut.
These are for use with Mallows type regression.
Finally the asymptotic variance-covariance matrix, C, of the estimates θ is calculated.
For Huber type regression
C=fHXTX-1σ^2,
where
fH=1n-mi=1nψ2ri/σ^1ni=1nψriσ^2κ2
κ2=1+mn1ni=1nψri/σ^-1ni=1nψri/σ^21ni=1nψriσ^2.
See Huber (1981) and Marazzi (1987b).
For Mallows and Schweppe type regressions C is of the form
σ^n2S1-1S2S1-1,
where S1=1nXTDX and S2=1nXTPX.
D is a diagonal matrix such that the ith element approximates Eψri/σwi in the Schweppe case and Eψri/σwi in the Mallows case.
P is a diagonal matrix such that the ith element approximates Eψ2ri/σwiwi2 in the Schweppe case and Eψ2ri/σwi2 in the Mallows case.
Two approximations are available in g02ha:
1. Average over the ri 
SchweppeMallowsDi=1nj=1nψrjσ^wiwiDi=1nj=1nψrjσ^wiPi=1nj=1nψ2rjσ^wiwi2Pi=1nj=1nψ2rjσ^wi2
2. Replace expected value by observed
SchweppeMallowsDi=ψriσ^wiwiDi=ψriσ^wiPi=ψ2riσ^wiwi2Pi=ψ2riσ^wi2.
Note:  there is no explicit provision in the method for a constant term in the regression model. However, the addition of a dummy variable whose value is 1.0 for all observations will produce a value of θ^ corresponding to the usual constant term.
g02ha is based on routines in ROBETH; see Marazzi (1987a).

References

Hampel F R, Ronchetti E M, Rousseeuw P J and Stahel W A (1986) Robust Statistics. The Approach Based on Influence Functions Wiley
Huber P J (1981) Robust Statistics Wiley
Marazzi A (1987a) 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
Marazzi A (1987b) Subroutines for robust and bounded influence regression in ROBETH Cah. Rech. Doc. IUMSP, No. 3 ROB 2 Institut Universitaire de Médecine Sociale et Préventive, Lausanne

Error Indicators and Warnings

Note: g02ha may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDX, LDC, WORK) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
ifail=1
On entry,n1,
orm<1,
ornm,
ifail=2
On entry,ipsi<0,
oripsi>4.
ifail=3
On entry,sigma0.0,
oripsi=1 and cpsi0.0,
oripsi=2 and h1<0.0,
oripsi=2 and h1>h2,
oripsi=2 and h2>h3,
oripsi=2 and h1=h2=h3=0.0,
oripsi0 and isigma>0 and dchi0.0,
orindw>0 and cucv<m,
orindw<0 and cucv<m.
ifail=4
On entry,tol0.0,
ormaxit0.
ifail=5
The number of iterations required to calculate the weights exceeds maxit. (Only if indw0.)
ifail=6
The number of iterations required to calculate β1 exceeds maxit. (Only if indw<0 and isigma<0.)
ifail=7
Either the number of iterations required to calculate θ and σ exceeds maxit (note that, in this case _work[2]=maxit on exit), or the iterations to solve the weighted least squares equations failed to converge. The latter is an unlikely error exit.
ifail=8
The weighted least squares equations are not of full rank.
ifail=9
If indw=0 then XTX is almost singular.
If indw0 then S1 is singular or almost singular. This may be due to too many diagonal elements of the matrix being zero, see [Further Comments].
ifail=10
In calculating the correlation factor for the asymptotic variance-covariance matrix either the value of
1ni=1nψri/σ^=0,   or  κ=0,   or  i=1nψ2ri/σ^=0.
See [Further Comments]. In this case c is returned as XTX.
(Only if indw=0.)
ifail=11
The estimated variance for an element of θ0.
In this case the diagonal element of c will contain the negative variance and the above diagonal elements in the row and column corresponding to the element will be returned as zero.
This error may be caused by rounding errors or too many of the diagonal elements of P being zero, where P is defined in [Description]. See [Further Comments].
ifail=12
The degrees of freedom for error, n-k0 (this is an unlikely error exit), or the estimated value of σ was 0 during an iteration.
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

The precision of the estimates is determined by tol. As a more stable method is used to calculate the estimates of θ than is used to calculate the covariance matrix, it is possible for the least squares equations to be of full rank but the XTX matrix to be too nearly singular to be inverted.

Parallelism and Performance

None.

Further Comments

In cases when isigma0 it is important for the value of sigma to be of a reasonable magnitude. Too small a value may cause too many of the winsorized residuals, i.e., ψri/σ, to be zero or a value of ψri/σ, used to estimate the asymptotic covariance matrix, to be zero. This can lead to errors ifail=8 or 9 (if indw0), ifail=10 (if indw=0) and ifail=11.
g02hbg02hd and g02hf together carry out the same calculations as g02ha but for user-supplied functions for ψ, χ, ψ and u.

Example

The number of observations and the number of x variables are read in followed by the data. The option parameters are then read in (in this case giving Schweppe type regression with Hampel's ψ function and Huber's χ function and then using the ‘replace expected by observed’ option in calculating the covariances). Finally a set of values for the constants are read in.
After a call to g02ha, θ^, its standard error and σ^ are printed. In addition the weight and residual for each observation is printed.

Example program (C#): g02hae.cs

Example program data: g02hae.d

Example program results: g02hae.r

See Also