PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_correg_robustm (g02ha)
Purpose
nag_correg_robustm (g02ha) performs bounded influence regression (-estimates). Several standard methods are available.
Syntax
[
x,
y,
theta,
sigma,
c,
rs,
wgt,
work,
ifail] = g02ha(
indw,
ipsi,
isigma,
indc,
x,
y,
cpsi,
h1,
h2,
h3,
cucv,
dchi,
theta,
sigma, 'n',
n, 'm',
m, 'tol',
tol, 'maxit',
maxit, 'nitmon',
nitmon)
[
x,
y,
theta,
sigma,
c,
rs,
wgt,
work,
ifail] = nag_correg_robustm(
indw,
ipsi,
isigma,
indc,
x,
y,
cpsi,
h1,
h2,
h3,
cucv,
dchi,
theta,
sigma, 'n',
n, 'm',
m, 'tol',
tol, 'maxit',
maxit, 'nitmon',
nitmon)
Note: the interface to this routine has changed since earlier releases of the toolbox:
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 arguments, |
and |
is a vector of length of unknown errors with , |
nag_correg_robustm (g02ha) 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
nag_specfun_cdf_normal (s15ab)).
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
using
nag_linsys_real_gen_solve (f04jg).
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
nag_correg_robustm (g02ha).
(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
.
nag_correg_robustm (g02ha) finds
using the iterative procedure
where
,
and
and
and
are bounds set at
.
Two weights are available in
nag_correg_robustm (g02ha):
(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
nag_correg_robustm (g02ha):
1. |
Average over the
|
2. |
Replace expected value by observed
|
Note: there is no explicit provision in the function 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.
nag_correg_robustm (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
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
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:
– int64int32nag_int scalar
-
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:
.
- 3:
– int64int32nag_int scalar
-
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:
– int64int32nag_int scalar
-
If
,
indc specifies the approximations used in estimating the covariance matrix of
.
- Averaging over residuals.
- Replacing expected by observed.
- indc is not referenced.
- 5:
– double array
-
ldx, the first dimension of the array, must satisfy the constraint
.
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
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.
- 6:
– double array
-
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
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.
- 7:
– double scalar
-
If
,
cpsi must specify the argument,
, of Huber's
function.
If
on entry,
cpsi is not referenced.
Constraint:
if , .
- 8:
– double scalar
- 9:
– double scalar
- 10:
– double scalar
-
If
,
h1,
h2, and
h3 must specify the arguments
,
, and
, of Hampel's piecewise linear
function.
h1,
h2, and
h3 are not referenced if
.
Constraint:
if , and .
- 11:
– double scalar
-
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 , .
- 12:
– double scalar
-
, the constant of the
function.
dchi is not referenced if
, or if
.
Constraint:
if and , .
- 13:
– double array
-
Starting values of the argument 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.
- 14:
– double scalar
-
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:
.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
y and the first dimension of the array
x. (An error is raised if these dimensions are not equal.)
, the number of observations.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the array
theta and the second dimension of the array
x. (An error is raised if these dimensions are not equal.)
, the number of independent variables.
Constraint:
.
- 3:
– double scalar
Default:
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:
.
- 4:
– int64int32nag_int scalar
Default:
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:
.
- 5:
– int64int32nag_int scalar
Default:
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
Description).
When printing occurs the output is directed to the current advisory message unit (see
nag_file_set_unit_advisory (x04ab)).
Output Parameters
- 1:
– double array
-
Unchanged, except as described above.
- 2:
– double array
-
Unchanged, except as described above.
- 3:
– double array
-
contains the M-estimate of , for .
- 4:
– double scalar
-
Contains the final estimate of if or the value assigned on entry if .
- 5:
– double array
-
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 .
- 6:
– double array
-
The residuals from the model evaluated at final value of
theta, i.e.,
rs contains the vector
.
- 7:
– double array
-
The vector of weights.
contains the weight for the th observation, for .
- 8:
– double array
-
The following values are assigned to
work:
- 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.
The rest of the array is used as workspace.
- 9:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Note: nag_correg_robustm (g02ha) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
On entry, | , |
or | , |
or | , |
or | , |
or | . |
-
-
On entry, | , |
or | . |
-
-
On entry, | , |
or | and , |
or | and , |
or | and , |
or | and , |
or | and , |
or | and and , |
or | and , |
or | and . |
-
-
On entry, | , |
or | . |
-
-
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
.)
-
-
Either the number of iterations required to calculate
and
exceeds
maxit (note that, in this case
on exit), or the iterations to solve the weighted least squares equations failed to converge. The latter is an unlikely error exit.
- W
-
The weighted least squares equations are not of full rank.
- W
-
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
Further Comments.
- W
-
In calculating the correlation factor for the asymptotic variance-covariance matrix either the value of
See
Further Comments. In this case
c is returned as
.
(Only if .)
- W
-
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
Description. See
Further Comments.
-
-
The degrees of freedom for error, (this is an unlikely error exit), or the estimated value of was during an iteration.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
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.
Further Comments
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
.
nag_correg_robustm_wts (g02hb),
nag_correg_robustm_user (g02hd) and
nag_correg_robustm_user_varmat (g02hf) together carry out the same calculations as
nag_correg_robustm (g02ha) but for user-supplied functions for
,
,
and
.
Example
The number of observations and the number of variables are read in followed by the data. The option arguments 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 nag_correg_robustm (g02ha), , its standard error and are printed. In addition the weight and residual for each observation is printed.
Open in the MATLAB editor:
g02ha_example
function g02ha_example
fprintf('g02ha example results\n\n');
x = [1, -1, -1;
1, -1, 1;
1, 1, -1;
1, 1, 1;
1, -2, 0;
1, 0, -2;
1, 2, 0;
1, 0, 2];
y = [2.1; 3.6; 4.5; 6.1; 1.3; 1.9; 6.7; 5.5];
[n,m] = size(x);
indw = int64(1);
ipsi = int64(2);
isigma = int64(1);
indc = int64(0);
cpsi = 0;
h1 = 1.5; h2 = 3; h3 = 4.5;
cucv = 3;
dchi = 1.5;
sigma = 1;
theta = zeros(m,1);
[x, y, theta, sigma, c, rs, wgt, work, ifail] = ...
g02ha( ...
indw, ipsi, isigma, indc, x, y, cpsi, h1, h2, h3, ...
cucv, dchi, theta, sigma);
fprintf('Sigma = %10.4f\n', sigma);
fprintf('\n Theta Standard\n');
fprintf(' errors\n');
for j = 1:m
fprintf('%12.4f%13.4f\n',theta(j),c(j,j));
end
fprintf('\n Weights Residuals\n');
fprintf('%12.4f%13.4f\n',[wgt rs]');
g02ha example results
Sigma = 0.2026
Theta Standard
errors
4.0423 0.0384
1.3083 0.0272
0.7519 0.0311
Weights Residuals
0.5783 0.1179
0.5783 0.1141
0.5783 -0.0987
0.5783 -0.0026
0.4603 -0.1256
0.4603 -0.6385
0.4603 0.0410
0.4603 -0.0462
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015