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.
${\mathbf{indw}}<0$
Mallows type regression with Maronna's proposed weights.
${\mathbf{indw}}=0$
Huber type regression.
${\mathbf{indw}}>0$
Schweppe type regression with Krasker–Welsch weights.
ipsi
Type: System..::..Int32
On entry: specifies which $\psi$ function is to be used.
${\mathbf{ipsi}}=0$
$\psi \left(t\right)=t$, i.e., least squares.
${\mathbf{ipsi}}=1$
Huber's function.
${\mathbf{ipsi}}=2$
Hampel's piecewise linear function.
${\mathbf{ipsi}}=3$
Andrew's sine wave.
${\mathbf{ipsi}}=4$
Tukey's bi-weight.
Constraint: $0\le {\mathbf{ipsi}}\le 4$.
isigma
Type: System..::..Int32
On entry: specifies how $\sigma$ is to be estimated.
${\mathbf{isigma}}<0$
$\sigma$ is estimated by median absolute deviation of residuals.
${\mathbf{isigma}}=0$
$\sigma$ is held constant at its initial value.
${\mathbf{isigma}}>0$
$\sigma$ is estimated using the $\chi$ function.
indc
Type: System..::..Int32
On entry: if ${\mathbf{indw}}\ne 0$, indc specifies the approximations used in estimating the covariance matrix of $\stackrel{^}{\theta }$.
${\mathbf{indc}}=1$
Averaging over residuals.
${\mathbf{indc}}\ne 1$
Replacing expected by observed.
${\mathbf{indw}}=0$
indc is not referenced.
n
Type: System..::..Int32
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.
m
Type: System..::..Int32
On entry: $m$, the number of independent variables.
Constraint: $1\le {\mathbf{m}}<{\mathbf{n}}$.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, m]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
On entry: the values of the $X$ matrix, i.e., the independent variables. ${\mathbf{x}}\left[\mathit{i}-1,\mathit{j}-1\right]$ must contain the $\mathit{i}\mathit{j}$th element of $X$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,m$.
If ${\mathbf{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.
${\mathbf{y}}\left[\mathit{i}-1\right]$ must contain the value of $y$ for the $\mathit{i}$th observation, for $\mathit{i}=1,2,\dots ,n$.
If ${\mathbf{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 ${\mathbf{ipsi}}=1$, cpsi must specify the parameter, $c$, of Huber's $\psi$ function.
If ${\mathbf{ipsi}}\ne 1$ on entry, cpsi is not referenced.
Constraint: if ${\mathbf{cpsi}}>0.0$, ${\mathbf{ipsi}}=1$.
h1
Type: System..::..Double
On entry: if ${\mathbf{ipsi}}=2$, h1, h2, and h3 must specify the parameters ${h}_{1}$, ${h}_{2}$, and ${h}_{3}$, of Hampel's piecewise linear $\psi$ function. h1, h2, and h3 are not referenced if ${\mathbf{ipsi}}\ne 2$.
Constraint: if ${\mathbf{ipsi}}=2$, $0.0\le {\mathbf{h1}}\le {\mathbf{h2}}\le {\mathbf{h3}}$ and ${\mathbf{h3}}>0.0$.
h2
Type: System..::..Double
On entry: if ${\mathbf{ipsi}}=2$, h1, h2, and h3 must specify the parameters ${h}_{1}$, ${h}_{2}$, and ${h}_{3}$, of Hampel's piecewise linear $\psi$ function. h1, h2, and h3 are not referenced if ${\mathbf{ipsi}}\ne 2$.
Constraint: if ${\mathbf{ipsi}}=2$, $0.0\le {\mathbf{h1}}\le {\mathbf{h2}}\le {\mathbf{h3}}$ and ${\mathbf{h3}}>0.0$.
h3
Type: System..::..Double
On entry: if ${\mathbf{ipsi}}=2$, h1, h2, and h3 must specify the parameters ${h}_{1}$, ${h}_{2}$, and ${h}_{3}$, of Hampel's piecewise linear $\psi$ function. h1, h2, and h3 are not referenced if ${\mathbf{ipsi}}\ne 2$.
Constraint: if ${\mathbf{ipsi}}=2$, $0.0\le {\mathbf{h1}}\le {\mathbf{h2}}\le {\mathbf{h3}}$ and ${\mathbf{h3}}>0.0$.
cucv
Type: System..::..Double
On entry: if ${\mathbf{indw}}<0$, must specify the value of the constant, $c$, of the function $u$ for Maronna's proposed weights.
If ${\mathbf{indw}}>0$, must specify the value of the function $u$ for the Krasker–Welsch weights.
If ${\mathbf{indw}}=0$, is not referenced.
Constraints:
• if ${\mathbf{indw}}<0$, ${\mathbf{cucv}}\ge {\mathbf{m}}$;
• if ${\mathbf{indw}}>0$, ${\mathbf{cucv}}\ge \sqrt{{\mathbf{m}}}$.
dchi
Type: System..::..Double
On entry: $d$, the constant of the $\chi$ function. dchi is not referenced if ${\mathbf{ipsi}}=0$, or if ${\mathbf{isigma}}\le 0$.
Constraint: if ${\mathbf{ipsi}}\ne 0$ and ${\mathbf{isigma}}>0$, ${\mathbf{dchi}}>0.0$.
theta
Type: array<System..::..Double>[]()[][]
An array of size [m]
On entry: starting values of the parameter vector $\theta$. These may be obtained from least squares regression. Alternatively if ${\mathbf{isigma}}<0$ and ${\mathbf{sigma}}=1$ or if ${\mathbf{isigma}}>0$ and sigma approximately equals the standard deviation of the dependent variable, $y$, then ${\mathbf{theta}}\left[\mathit{i}-1\right]=0.0$, for $\mathit{i}=1,2,\dots ,m$ may provide reasonable starting values.
On exit: ${\mathbf{theta}}\left[\mathit{i}-1\right]$ contains the M-estimate of ${\theta }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,m$.
sigma
Type: System..::..Double%
On entry: a starting value for the estimation of $\sigma$. sigma should be approximately the standard deviation of the residuals from the model evaluated at the value of $\theta$ given by theta on entry.
Constraint: ${\mathbf{sigma}}>0.0$.
On exit: contains the final estimate of $\sigma$ if ${\mathbf{isigma}}\ne 0$ or the value assigned on entry if ${\mathbf{isigma}}=0$.
c
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, m]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{m}}$
On exit: the diagonal elements of c contain the estimated asymptotic standard errors of the estimates of $\theta$, i.e., ${\mathbf{c}}\left[i-1,i-1\right]$ contains the estimated asymptotic standard error of the estimate contained in ${\mathbf{theta}}\left[i-1\right]$.
The elements above the diagonal contain the estimated asymptotic correlation between the estimates of $\theta$, i.e., ${\mathbf{c}}\left[i-1,j-1\right]$, $1\le i contains the asymptotic correlation between the estimates contained in ${\mathbf{theta}}\left[i-1\right]$ and ${\mathbf{theta}}\left[j-1\right]$.
The elements below the diagonal contain the estimated asymptotic covariance between the estimates of $\theta$, i.e., ${\mathbf{c}}\left[i-1,j-1\right]$, $1\le j contains the estimated asymptotic covariance between the estimates contained in ${\mathbf{theta}}\left[i-1\right]$ and ${\mathbf{theta}}\left[j-1\right]$.
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 $\left(y-X\stackrel{^}{\theta }\right)$.
wgt
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the vector of weights. ${\mathbf{wgt}}\left[\mathit{i}-1\right]$ contains the weight for the $\mathit{i}$th observation, for $\mathit{i}=1,2,\dots ,n$.
tol
Type: System..::..Double
On entry: the relative precision for the calculation of $A$ (if ${\mathbf{indw}}\ne 0$), the estimates of $\theta$ and the estimate of $\sigma$ (if ${\mathbf{isigma}}\ne 0$). Convergence is assumed when the relative change in all elements being considered is less than tol.
If ${\mathbf{indw}}<0$ and ${\mathbf{isigma}}<0$, tol is also used to determine the precision of ${\beta }_{1}$.
It is advisable for tol to be greater than .
Constraint: ${\mathbf{tol}}>0.0$.
maxit
Type: System..::..Int32
On entry: the maximum number of iterations that should be used in the calculation of $A$ (if ${\mathbf{indw}}\ne 0$), and of the estimates of $\theta$ and $\sigma$, and of ${\beta }_{1}$ (if ${\mathbf{indw}}<0$ and ${\mathbf{isigma}}<0$).
A value of ${\mathbf{maxit}}=50$ should be adequate for most uses.
Constraint: ${\mathbf{maxit}}>0$.
nitmon
Type: System..::..Int32
On entry: the amount of information that is printed on each iteration.
${\mathbf{nitmon}}=0$
No information is printed.
${\mathbf{nitmon}}\ne 0$
The current estimate of $\theta$, the change in $\theta$ during the current iteration and the current value of $\sigma$ are printed on the first and every $\mathrm{abs}\left({\mathbf{nitmon}}\right)$ iterations.
Also, if ${\mathbf{indw}}\ne 0$ and ${\mathbf{nitmon}}>0$ then information on the iterations to calculate $A$ is printed. This is the current estimate of $A$ and the maximum value of ${S}_{ij}$ (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:
• ${\mathbf{stat}}\left[0\right]={\beta }_{1}$ if ${\mathbf{isigma}}<0$, or ${\mathbf{stat}}\left[0\right]={\beta }_{2}$ if ${\mathbf{isigma}}>0$.
• ${\mathbf{stat}}\left[1\right]=\text{}$ number of iterations used to calculate $A$.
• ${\mathbf{stat}}\left[2\right]=\text{}$ number of iterations used to calculate final estimates of $\theta$ and $\sigma$.
• ${\mathbf{stat}}\left[3\right]=k$, the rank of the weighted least-squares equations.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{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$, $\theta$ is a vector of length $m$ of unknown parameters, and $\epsilon$ is a vector of length $n$ of unknown errors with $\mathrm{var}\left({\epsilon }_{i}\right)={\sigma }^{2}$,
g02ha calculates the M-estimates given by the solution, $\stackrel{^}{\theta }$, to the equation
 $∑i=1nψri/σwiwixij=0, j=1,2,…,m,$ (1)
where ${r}_{i}$ is the $i$th residual, i.e., the $i$th element of $r=y-X\stackrel{^}{\theta }$,
$\psi$ is a suitable weight function,
${w}_{i}$ are suitable weights,
and $\sigma$ may be estimated at each iteration by the median absolute deviation of the residuals
 $σ^=medi ri/β1$
or as the solution to
 $∑i=1nχri/σ^wiwi2=n-kβ2$
for suitable weight function $\chi$, where ${\beta }_{1}$ and ${\beta }_{2}$ are constants, chosen so that the estimator of $\sigma$ is asymptotically unbiased if the errors, ${\epsilon }_{i}$, have a Normal distribution. Alternatively $\sigma$ may be held at a constant value.
The above describes the Schweppe type regression. If the ${w}_{i}$ 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, ${\beta }_{1}$ is the 75th percentile of the standard Normal distribution. For Mallows type regression ${\beta }_{1}$ is the solution to
 $1n∑i=1nΦβ1/wi=0.75,$
where $\Phi$ is the standard Normal cumulative distribution function (see s15ab).
${\beta }_{2}$ is given by
 $β2=∫-∞∞χzϕzdzin the Huber case;β2=1n∑i=1nwi∫-∞∞χzϕzdzin the Mallows case;β2=1n∑i=1nwi2∫-∞∞χz/wiϕzdzin the Schweppe case;$
where $\varphi$ is the standard Normal density, i.e., $\frac{1}{\sqrt{2\pi }}\mathrm{exp}\left(-\frac{1}{2}{x}^{2}\right)\text{.}$
The calculation of the estimates of $\theta$ can be formulated as an iterative weighted least squares problem with a diagonal weight matrix $G$ given by
 $Gii=ψri/σwiri/σwi,ri≠0ψ′0,ri=0,$
where ${\psi }^{\prime }\left(t\right)$ is the derivative of $\psi$ at the point $t$.
The value of $\theta$ 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 $\psi$ and $\chi$ 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,t≤dd22,t>d$
(c) Hampel's Piecewise Linear Function
 $ψh1,h2,h3t=-ψh1,h2,h3-t=t,0≤t≤h1h1,h1≤t≤h2h1h3-t/h3-h2,h2≤t≤h30,h3
 $χt=t22,t≤dd22,t>d$
(d) Andrew's Sine Wave Function
 $ψt=sin t,-π≤t≤π0,t>π χt=t22,t≤dd22,t>d$
(e) Tukey's Bi-weight
 $ψt=t1-t22,t≤10,t>1 χt=t22,t≤dd22,t>d$
where $c$, ${h}_{1}$, ${h}_{2}$, ${h}_{3}$, 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:
 $1n∑i=1nuzi2ziziT=I$
and
 $zi=Axi,$
 where ${x}_{i}$ is a vector of length $m$ containing the $i$th 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 ${S}_{k}=\left({s}_{jl}\right)$,
 $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:
 $ut=g1ct,$
 where ${g}_{1}\left(t\right)={t}^{2}+\left(1-{t}^{2}\right)\left(2\Phi \left(t\right)-1\right)-2t\varphi \left(t\right)$, $\Phi \left(t\right)$ is the standard Normal cumulative distribution function, $\varphi \left(t\right)$ is the standard Normal probability density function, and $f\left(t\right)=\frac{1}{t}$.
These are for use with Schweppe type regression.
(ii) Maronna's Proposed Weights
 $ut=ct2t>c1t≤cft=ut.$
These are for use with Mallows type regression.
Finally the asymptotic variance-covariance matrix, $C$, of the estimates $\theta$ is calculated.
For Huber type regression
 $C=fHXTX-1σ^2,$
where
 $fH=1n-m∑i=1nψ2ri/σ^1n∑i=1nψ′riσ^2κ2$
 $κ2=1+mn1n∑i=1nψ′ri/σ^-1n∑i=1nψ′ri/σ^21n∑i=1nψ′riσ^2.$
See Huber (1981) and Marazzi (1987b).
For Mallows and Schweppe type regressions $C$ is of the form
 $σ^n2S1-1S2S1-1,$
where ${S}_{1}=\frac{1}{n}{X}^{\mathrm{T}}DX$ and ${S}_{2}=\frac{1}{n}{X}^{\mathrm{T}}PX$.
$D$ is a diagonal matrix such that the $i$th element approximates $E\left({\psi }^{\prime }\left({r}_{i}/\left(\sigma {w}_{i}\right)\right)\right)$ in the Schweppe case and $E\left({\psi }^{\prime }\left({r}_{i}/\sigma \right){w}_{i}\right)$ in the Mallows case.
$P$ is a diagonal matrix such that the $i$th element approximates $E\left({\psi }^{2}\left({r}_{i}/\left(\sigma {w}_{i}\right)\right){w}_{i}^{2}\right)$ in the Schweppe case and $E\left({\psi }^{2}\left({r}_{i}/\sigma \right){w}_{i}^{2}\right)$ in the Mallows case.
Two approximations are available in g02ha:
1. Average over the ${r}_{i}$
 $SchweppeMallowsDi=1n∑j=1nψ′rjσ^wiwi Di=1n∑j=1nψ′rjσ^wiPi=1n∑j=1nψ2rjσ^wiwi2 Pi=1n∑j=1nψ2rjσ^wi2$
2. Replace expected value by observed
 $SchweppeMallowsDi=ψ′riσ^wiwi Di=ψ′riσ^wiPi=ψ2riσ^wiwi2 Pi=ψ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 $\stackrel{^}{\theta }$ 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.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}\le 1$, or ${\mathbf{m}}<1$, or ${\mathbf{n}}\le {\mathbf{m}}$,
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{ipsi}}<0$, or ${\mathbf{ipsi}}>4$.
${\mathbf{ifail}}=3$
 On entry, ${\mathbf{sigma}}\le 0.0$, or ${\mathbf{ipsi}}=1$ and ${\mathbf{cpsi}}\le 0.0$, or ${\mathbf{ipsi}}=2$ and ${\mathbf{h1}}<0.0$, or ${\mathbf{ipsi}}=2$ and ${\mathbf{h1}}>{\mathbf{h2}}$, or ${\mathbf{ipsi}}=2$ and ${\mathbf{h2}}>{\mathbf{h3}}$, or ${\mathbf{ipsi}}=2$ and ${\mathbf{h1}}={\mathbf{h2}}={\mathbf{h3}}=0.0$, or ${\mathbf{ipsi}}\ne 0$ and ${\mathbf{isigma}}>0$ and ${\mathbf{dchi}}\le 0.0$, or ${\mathbf{indw}}>0$ and ${\mathbf{cucv}}<\sqrt{{\mathbf{m}}}$, or ${\mathbf{indw}}<0$ and ${\mathbf{cucv}}<{\mathbf{m}}$.
${\mathbf{ifail}}=4$
 On entry, ${\mathbf{tol}}\le 0.0$, or ${\mathbf{maxit}}\le 0$.
${\mathbf{ifail}}=5$
The number of iterations required to calculate the weights exceeds maxit. (Only if ${\mathbf{indw}}\ne 0$.)
${\mathbf{ifail}}=6$
The number of iterations required to calculate ${\beta }_{1}$ exceeds maxit. (Only if ${\mathbf{indw}}<0$ and ${\mathbf{isigma}}<0$.)
${\mathbf{ifail}}=7$
Either the number of iterations required to calculate $\theta$ and $\sigma$ exceeds maxit (note that, in this case $\mathbf{_work}\left[2\right]={\mathbf{maxit}}$ on exit), or the iterations to solve the weighted least squares equations failed to converge. The latter is an unlikely error exit.
${\mathbf{ifail}}=8$
The weighted least squares equations are not of full rank.
${\mathbf{ifail}}=9$
If ${\mathbf{indw}}=0$ then $\left({X}^{\mathrm{T}}X\right)$ is almost singular.
If ${\mathbf{indw}}\ne 0$ then ${S}_{1}$ is singular or almost singular. This may be due to too many diagonal elements of the matrix being zero, see [Further Comments].
${\mathbf{ifail}}=10$
In calculating the correlation factor for the asymptotic variance-covariance matrix either the value of
 $1n∑i=1nψ′ri/σ^=0, or κ=0, or ∑i=1nψ2ri/σ^=0.$
See [Further Comments]. In this case c is returned as ${X}^{\mathrm{T}}X$.
(Only if ${\mathbf{indw}}=0$.)
${\mathbf{ifail}}=11$
The estimated variance for an element of $\theta \le 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].
${\mathbf{ifail}}=12$
The degrees of freedom for error, $n-k\le 0$ (this is an unlikely error exit), or the estimated value of $\sigma$ was $0$ during an iteration.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

The precision of the estimates is determined by tol. As a more stable method is used to calculate the estimates of $\theta$ than is used to calculate the covariance matrix, it is possible for the least squares equations to be of full rank but the $\left({X}^{\mathrm{T}}X\right)$ matrix to be too nearly singular to be inverted.

# Parallelism and Performance

None.

In cases when ${\mathbf{isigma}}\ge 0$ 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., $\psi \left({r}_{i}/\sigma \right)$, to be zero or a value of ${\psi }^{\prime }\left({r}_{i}/\sigma \right)$, used to estimate the asymptotic covariance matrix, to be zero. This can lead to errors ${\mathbf{ifail}}={8}$ or ${9}$ (if ${\mathbf{indw}}\ne 0$), ${\mathbf{ifail}}={10}$ (if ${\mathbf{indw}}=0$) and ${\mathbf{ifail}}={11}$.
g02hbg02hd and g02hf together carry out the same calculations as g02ha but for user-supplied functions for $\psi$, $\chi$, ${\psi }^{\prime }\text{}$ 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 $\psi$ function and Huber's $\chi$ 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, $\stackrel{^}{\theta }$, its standard error and $\stackrel{^}{\sigma }$ 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