g02hd performs bounded influence regression (M-estimates) using an iterative weighted least squares algorithm.

Syntax

C#
public static void g02hd(
	G02..::..G02HD_CHI chi,
	G02..::..G02HD_PSI psi,
	double psip0,
	double beta,
	int indw,
	int isigma,
	int n,
	int m,
	double[,] x,
	double[] y,
	double[] wgt,
	double[] theta,
	out int k,
	ref double sigma,
	double[] rs,
	double tol,
	double eps,
	int maxit,
	int nitmon,
	out int nit,
	out int ifail
)
Visual Basic
Public Shared Sub g02hd ( _
	chi As G02..::..G02HD_CHI, _
	psi As G02..::..G02HD_PSI, _
	psip0 As Double, _
	beta As Double, _
	indw As Integer, _
	isigma As Integer, _
	n As Integer, _
	m As Integer, _
	x As Double(,), _
	y As Double(), _
	wgt As Double(), _
	theta As Double(), _
	<OutAttribute> ByRef k As Integer, _
	ByRef sigma As Double, _
	rs As Double(), _
	tol As Double, _
	eps As Double, _
	maxit As Integer, _
	nitmon As Integer, _
	<OutAttribute> ByRef nit As Integer, _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g02hd(
	G02..::..G02HD_CHI^ chi, 
	G02..::..G02HD_PSI^ psi, 
	double psip0, 
	double beta, 
	int indw, 
	int isigma, 
	int n, 
	int m, 
	array<double,2>^ x, 
	array<double>^ y, 
	array<double>^ wgt, 
	array<double>^ theta, 
	[OutAttribute] int% k, 
	double% sigma, 
	array<double>^ rs, 
	double tol, 
	double eps, 
	int maxit, 
	int nitmon, 
	[OutAttribute] int% nit, 
	[OutAttribute] int% ifail
)
F#
static member g02hd : 
        chi : G02..::..G02HD_CHI * 
        psi : G02..::..G02HD_PSI * 
        psip0 : float * 
        beta : float * 
        indw : int * 
        isigma : int * 
        n : int * 
        m : int * 
        x : float[,] * 
        y : float[] * 
        wgt : float[] * 
        theta : float[] * 
        k : int byref * 
        sigma : float byref * 
        rs : float[] * 
        tol : float * 
        eps : float * 
        maxit : int * 
        nitmon : int * 
        nit : int byref * 
        ifail : int byref -> unit 

Parameters

chi
Type: NagLibrary..::..G02..::..G02HD_CHI
If isigma>0, chi must return the value of the weight function χ for a given value of its argument. The value of χ must be non-negative.

A delegate of type G02HD_CHI.

If isigma0, the actual parameter chi may be the dummy method G02HDZ. (G02HDZ is included in the NAG Library.)
psi
Type: NagLibrary..::..G02..::..G02HD_PSI
psi must return the value of the weight function ψ for a given value of its argument.

A delegate of type G02HD_PSI.

psip0
Type: System..::..Double
On entry: the value of ψ0.
beta
Type: System..::..Double
On entry: if isigma<0, beta must specify the value of β1.
For Huber and Schweppe type regressions, β1 is the 75th percentile of the standard Normal distribution (see g01fa). 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).
If isigma>0, beta must specify the value of β2.
β2=-χzϕzdz,in the Huber case;β2=1ni=1nwi-χzϕzdz,in the Mallows case;β2=1ni=1nwi2-χz/wiϕzdz,in the Schweppe case;
where ϕ is the standard normal density, i.e., 12πexp-12x2.
If isigma=0, beta is not referenced.
Constraint: if isigma0, beta>0.0.
indw
Type: System..::..Int32
On entry: determines the type of regression to be performed.
indw=0
Huber type regression.
indw<0
Mallows type regression.
indw>0
Schweppe type regression.
Constraint: indw=-1, 0 or 1.
isigma
Type: System..::..Int32
On entry: determines how σ is to be estimated.
isigma=0
σ is held constant at its initial value.
isigma<0
σ is estimated by median absolute deviation of residuals.
isigma>0
σ is estimated using the χ function.
Constraint: isigma=-1, 0 or 1.
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, 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, 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.
wgt
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: the weight for the ith observation, for i=1,2,,n.
If indw<0, during calculations elements of wgt 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 wgt and the output wgt.
If wgt[i-1]0, the ith observation is not included in the analysis.
If indw=0, wgt is not referenced.
On exit: unchanged, except as described above.
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: the M-estimate of θi, for i=1,2,,m.
k
Type: System..::..Int32%
On exit: the column rank of the matrix X.
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: the final estimate of σ if isigma0 or the value assigned on entry if isigma=0.
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θ^.
tol
Type: System..::..Double
On entry: the relative precision for the final estimates. Convergence is assumed when both the relative change in the value of sigma and the relative change in the value of each element of theta are less than tol.
It is advisable for tol to be greater than 100×machine precision.
Constraint: tol>0.0.
eps
Type: System..::..Double
On entry: a relative tolerance to be used to determine the rank of X. See (F04JGF not in this release) for further details.
If eps<machine precision or eps>1.0 then machine precision will be used in place of tol.
A reasonable value for eps is 5.0×10-6 where this value is possible.
maxit
Type: System..::..Int32
On entry: the maximum number of iterations that should be used during the estimation.
A value of maxit=50 should be adequate for most uses.
Constraint: maxit>0.
nitmon
Type: System..::..Int32
On entry: determines the amount of information that is printed on each iteration.
nitmon0
No information is printed.
nitmon>0
On the first and every nitmon iterations the values of sigma, theta and the change in theta during the iteration are printed.
When printing occurs the output is directed to the current advisory message unit (see (X04ABF not in this release)).
nit
Type: System..::..Int32%
On exit: the number of iterations that were used during the estimation.
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,
g02hd 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 the vector r=y-Xθ^,
ψ is a suitable weight function,
wi are suitable weights such as those that can be calculated by using output from g02hb,
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 a 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 Marazzi (1987)).
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..
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.
Observations with zero or negative weights are not included in the solution.
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.
g02hd is based on routines in ROBETH, see Marazzi (1987).

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 (1987) 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: g02hd 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) 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,beta0.0, and isigma0,
orsigma0.0.
ifail=3
On entry,tol0.0,
ormaxit0.
ifail=4
A value returned by the chi function is negative.
ifail=5
During iterations a value of sigma0.0 was encountered.
ifail=6
A failure occurred in (F04JGF not in this release) . This is an extremely unlikely error. If it occurs, please contact NAG.
ifail=7
The weighted least squares equations are not of full rank. This may be due to the X matrix not being of full rank, in which case the results will be valid. It may also occur if some of the Gii values become very small or zero, see [Further Comments]. The rank of the equations is given by k. If the matrix just fails the test for nonsingularity then the result ifail=7 and k=m is possible (see (F04JGF not in this release)).
ifail=8
The method has failed to converge in maxit iterations.
ifail=9
Having removed cases with zero weight, the value of n-k0, i.e., no degree of freedom for error. This error will only occur if isigma>0.
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 accuracy of the results is controlled by tol. For the accuracy of the weighted least squares see (F04JGF not in this release).

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, which will lead to convergence problems and may trigger the ifail=7 error.
By suitable choice of the functions chi and psi this method may be used for other applications of iterative weighted least squares.
For the variance-covariance matrix of θ see g02hf.

Example

Having input X, Y and the weights, a Schweppe type regression is performed using Huber's ψ function. The method BETCAL calculates the appropriate value of β2.

Example program (C#): g02hde.cs

Example program data: g02hde.d

Example program results: g02hde.r

See Also