NAG Library Routine Document
g02haf (robustm)
1
Purpose
g02haf performs bounded influence regression (-estimates). Several standard methods are available.
2
Specification
Fortran Interface
Subroutine g02haf ( |
indw, ipsi, isigma, indc, n, m, x, ldx, y, cpsi, h1, h2, h3, cucv, dchi, theta, sigma, c, ldc, rs, wgt, tol, maxit, nitmon, stat, ifail) |
Integer, Intent (In) | :: | indw, ipsi, isigma, indc, n, m, ldx, ldc, maxit, nitmon | Integer, Intent (Inout) | :: | ifail | Real (Kind=nag_wp), Intent (In) | :: | cpsi, h1, h2, h3, cucv, dchi, tol | Real (Kind=nag_wp), Intent (Inout) | :: | x(ldx,m), y(n), theta(m), sigma, c(ldc,m) | Real (Kind=nag_wp), Intent (Out) | :: | rs(n), wgt(n), stat(4) |
|
C Header Interface
#include <nagmk26.h>
void |
g02haf_ (const Integer *indw, const Integer *ipsi, const Integer *isigma, const Integer *indc, const Integer *n, const Integer *m, double x[], const Integer *ldx, double y[], const double *cpsi, const double *h1, const double *h2, const double *h3, const double *cucv, const double *dchi, double theta[], double *sigma, double c[], const Integer *ldc, double rs[], double wgt[], const double *tol, const Integer *maxit, const Integer *nitmon, double stat[], Integer *ifail) |
|
3
Description
For the linear regression model
where |
is a vector of length of the dependent variable, |
|
is a by matrix of independent variables of column rank , |
|
is a vector of length of unknown parameters, |
and |
is a vector of length of unknown errors with , |
g02haf calculates the M-estimates given by the solution,
, to the equation
where |
is the th residual, i.e., the th element of , |
|
is a suitable weight function, |
|
are suitable weights, |
and |
may be estimated at each iteration by the median absolute deviation of the residuals
|
or as the solution to
for suitable weight function
, where
and
are constants, chosen so that the estimator of
is asymptotically unbiased if the errors,
, have a Normal distribution. Alternatively
may be held at a constant value.
The above describes the Schweppe type regression. If the
are assumed to equal
for all
then Huber type regression is obtained. A third type, due to Mallows, replaces
(1) by
This may be obtained by use of the transformations
(see Section 3 of
Marazzi (1987a)).
For Huber and Schweppe type regressions,
is the 75th percentile of the standard Normal distribution. For Mallows type regression
is the solution to
where
is the standard Normal cumulative distribution function (see
s15abf).
is given by
where
is the standard Normal density, i.e.,
The calculation of the estimates of
can be formulated as an iterative weighted least squares problem with a diagonal weight matrix
given by
where
is the derivative of
at the point
.
The value of
at each iteration is given by the weighted least squares regression of
on
. This is carried out by first transforming the
and
by
and then solving the associated least squares problem.
If
is of full column rank then an orthogonal-triangular (
) decomposition is used; if not, a singular value decomposition is used.
The following functions are available for
and
in
g02haf.
(a) |
Unit Weights
This gives least squares regression. |
(b) |
Huber's Function
|
(c) |
Hampel's Piecewise Linear Function
|
(d) |
Andrew's Sine Wave Function
|
(e) |
Tukey's Bi-weight
|
where
,
,
,
, and
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
has to be found such that:
and
where |
is a vector of length containing the th row of , |
|
is an by lower triangular matrix, |
and |
is a suitable function. |
The weights are then calculated as
for a suitable function
.
g02haf finds
using the iterative procedure
where
,
and
and
and
are bounds set at
.
Two weights are available in
g02haf:
(i) |
Krasker–Welsch Weights
where |
, |
|
is the standard Normal cumulative distribution function, |
|
is the standard Normal probability density function, |
and |
.
|
These are for use with Schweppe type regression. |
(ii) |
Maronna's Proposed Weights
These are for use with Mallows type regression. |
Finally the asymptotic variance-covariance matrix, , of the estimates is calculated.
For Huber type regression
where
See
Huber (1981) and
Marazzi (1987b).
For Mallows and Schweppe type regressions
is of the form
where
and
.
is a diagonal matrix such that the th element approximates in the Schweppe case and in the Mallows case.
is a diagonal matrix such that the th element approximates in the Schweppe case and in the Mallows case.
Two approximations are available in
g02haf:
1. |
Average over the
|
2. |
Replace expected value by observed
|
Note: there is no explicit provision in the routine for a constant term in the regression model. However, the addition of a dummy variable whose value is for all observations will produce a value of corresponding to the usual constant term.
g02haf is based on routines in ROBETH; see
Marazzi (1987a).
4
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
5
Arguments
- 1: – IntegerInput
-
On entry: specifies the type of regression to be performed.
- Mallows type regression with Maronna's proposed weights.
- Huber type regression.
- Schweppe type regression with Krasker–Welsch weights.
- 2: – IntegerInput
-
On entry: specifies which
function is to be used.
- , i.e., least squares.
- Huber's function.
- Hampel's piecewise linear function.
- Andrew's sine wave.
- Tukey's bi-weight.
Constraint:
, , , or .
- 3: – IntegerInput
-
On entry: specifies how
is to be estimated.
- is estimated by median absolute deviation of residuals.
- is held constant at its initial value.
- is estimated using the function.
- 4: – IntegerInput
-
On entry: if
,
indc specifies the approximations used in estimating the covariance matrix of
.
- Averaging over residuals.
- Replacing expected by observed.
- indc is not referenced.
- 5: – IntegerInput
-
On entry: , the number of observations.
Constraint:
.
- 6: – IntegerInput
-
On entry: , the number of independent variables.
Constraint:
.
- 7: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: the values of the
matrix, i.e., the independent variables.
must contain the
th element of
, for
and
.
If
, then during calculations the elements of
x will be transformed as described in
Section 3. 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.
- 8: – IntegerInput
-
On entry: the first dimension of the array
x as declared in the (sub)program from which
g02haf is called.
Constraint:
.
- 9: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: the data values of the dependent variable.
must contain the value of for the th observation, for .
If
, then during calculations the elements of
y will be transformed as described in
Section 3. 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.
- 10: – Real (Kind=nag_wp)Input
-
On entry: if
,
cpsi must specify the parameter,
, of Huber's
function.
If
on entry,
cpsi is not referenced.
Constraint:
if , .
- 11: – Real (Kind=nag_wp)Input
- 12: – Real (Kind=nag_wp)Input
- 13: – Real (Kind=nag_wp)Input
-
On entry: if
,
h1,
h2, and
h3 must specify the parameters
,
, and
, of Hampel's piecewise linear
function.
h1,
h2, and
h3 are not referenced if
.
Constraint:
if , and .
- 14: – Real (Kind=nag_wp)Input
-
On entry: if
, must specify the value of the constant,
, of the function
for Maronna's proposed weights.
If , must specify the value of the function for the Krasker–Welsch weights.
If , is not referenced.
Constraints:
- if , ;
- if , .
- 15: – Real (Kind=nag_wp)Input
-
On entry:
, the constant of the
function.
dchi is not referenced if
, or if
.
Constraint:
if and , .
- 16: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: starting values of the parameter vector
. These may be obtained from least squares regression. Alternatively if
and
or if
and
sigma approximately equals the standard deviation of the dependent variable,
, then
, for
may provide reasonable starting values.
On exit: contains the M-estimate of , for .
- 17: – Real (Kind=nag_wp)Input/Output
-
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:
.
On exit: contains the final estimate of if or the value assigned on entry if .
- 18: – Real (Kind=nag_wp) arrayOutput
-
On exit: the diagonal elements of
c contain the estimated asymptotic standard errors of the estimates of
, i.e.,
contains the estimated asymptotic standard error of the estimate contained in
.
The elements above the diagonal contain the estimated asymptotic correlation between the estimates of , i.e., , contains the asymptotic correlation between the estimates contained in and .
The elements below the diagonal contain the estimated asymptotic covariance between the estimates of , i.e., , contains the estimated asymptotic covariance between the estimates contained in and .
- 19: – IntegerInput
-
On entry: the first dimension of the array
c as declared in the (sub)program from which
g02haf is called.
Constraint:
.
- 20: – Real (Kind=nag_wp) arrayOutput
-
On exit: the residuals from the model evaluated at final value of
theta, i.e.,
rs contains the vector
.
- 21: – Real (Kind=nag_wp) arrayOutput
-
On exit: the vector of weights.
contains the weight for the th observation, for .
- 22: – Real (Kind=nag_wp)Input
-
On entry: the relative precision for the calculation of
(if
), the estimates of
and the estimate of
(if
). Convergence is assumed when the relative change in all elements being considered is less than
tol.
If
and
,
tol is also used to determine the precision of
.
It is advisable for
tol to be greater than
.
Constraint:
.
- 23: – IntegerInput
-
On entry: the maximum number of iterations that should be used in the calculation of
(if
), and of the estimates of
and
, and of
(if
and
).
A value of should be adequate for most uses.
Constraint:
.
- 24: – IntegerInput
-
On entry: the amount of information that is printed on each iteration.
- No information is printed.
- The current estimate of , the change in during the current iteration and the current value of are printed on the first and every iterations.
Also, if
and
then information on the iterations to calculate
is printed. This is the current estimate of
and the maximum value of
(see
Section 3).
When printing occurs the output is directed to the current advisory message unit (see
x04abf).
- 25: – Real (Kind=nag_wp) arrayOutput
-
On exit: the following values are assigned to
stat:
- if , or if .
- number of iterations used to calculate .
- number of iterations used to calculate final estimates of and .
- , the rank of the weighted least squares equations.
- 26: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Note: g02haf may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
-
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
-
On entry: .
Constraint: , , , or .
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry: .
Constraint: .
On entry:
h1,
h2,
h3 incorrectly set.
Constraint:
and
.
-
On entry, .
Constraint: .
On entry, .
Constraint: .
-
The number of iterations required to calculate the weights exceeds
maxit.
(Only if
.)
-
The number of iterations required to calculate
exceeds
maxit.
(Only if
and
.)
-
Iterations to calculate estimates of
theta failed to converge in
maxit iterations:
.
The number of iterations required to calculate
and
exceeds
maxit.
-
Weighted least squares equations not of full rank: rank .
-
Failure to invert matrix while calculating covariance.
If then is almost singular.
If
then
is singular or almost singular. This may be due to too many diagonal elements of the matrix being zero, see
Section 9.
-
Factor for covariance matrix , uncorrected given.
In calculating the correlation factor for the asymptotic variance-covariance matrix either the value of
See
Section 9. In this case
c is returned as
.
(Only if .)
-
Variance of an element of , correlations set to .
The estimated variance for an element of .
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
being zero, where
is defined in
Section 3. See
Section 9.
-
Error degrees of freedom
, where
and the rank of
x,
.
Estimated value of
sigma is zero.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
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
matrix to be too nearly singular to be inverted.
8
Parallelism and Performance
g02haf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g02haf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
In cases when
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.,
, to be zero or a value of
, used to estimate the asymptotic covariance matrix, to be zero. This can lead to errors
or
(if
),
(if
) and
.
g02hbf,
g02hdf and
g02hff together carry out the same calculations as
g02haf but for user-supplied functions for
,
,
and
.
10
Example
The number of observations and the number of 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 g02haf, , its standard error and are printed. In addition the weight and residual for each observation is printed.
10.1
Program Text
Program Text (g02hafe.f90)
10.2
Program Data
Program Data (g02hafe.d)
10.3
Program Results
Program Results (g02hafe.r)