PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_correg_robustm_user (g02hd)
Purpose
nag_correg_robustm_user (g02hd) performs bounded influence regression (-estimates) using an iterative weighted least squares algorithm.
Syntax
[
x,
y,
wgt,
theta,
k,
sigma,
rs,
nit,
ifail] = g02hd(
chi,
psi,
psip0,
beta,
indw,
isigma,
x,
y,
wgt,
theta,
sigma, 'n',
n, 'm',
m, 'tol',
tol, 'eps',
eps, 'maxit',
maxit, 'nitmon',
nitmon)
[
x,
y,
wgt,
theta,
k,
sigma,
rs,
nit,
ifail] = nag_correg_robustm_user(
chi,
psi,
psip0,
beta,
indw,
isigma,
x,
y,
wgt,
theta,
sigma, 'n',
n, 'm',
m, 'tol',
tol, 'eps',
eps, '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 var , |
nag_correg_robustm_user (g02hd) calculates the M-estimates given by the solution,
, to the equation
where |
is the th residual, i.e., the th element of the vector , |
|
is a suitable weight function, |
|
are suitable weights such as those that can be calculated by using output from nag_correg_robustm_wts (g02hb), |
and |
may be estimated at each iteration by the median absolute deviation of the residuals |
or as the solution to
for a 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
Marazzi (1987)).
The calculation of the estimates of
can be formulated as an iterative weighted least squares problem with a diagonal weight matrix
given by
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.
Observations with zero or negative weights are not included in the solution.
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_user (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
Parameters
Compulsory Input Parameters
- 1:
– function handle or string containing name of m-file
-
If
,
chi must return the value of the weight function
for a given value of its argument. The value of
must be non-negative.
[result] = chi(t)
Input Parameters
- 1:
– double scalar
-
The argument for which
chi must be evaluated.
Output Parameters
- 1:
– double scalar
-
The value of the weight function
evaluated at
t.
If
, the actual argument
chi may be the string
nag_correg_robustm_user_dummy_chi (g02hdz). (
nag_correg_robustm_user_dummy_chi (g02hdz) is included in the NAG Toolbox.)
- 2:
– function handle or string containing name of m-file
-
psi must return the value of the weight function
for a given value of its argument.
[result] = psi(t)
Input Parameters
- 1:
– double scalar
-
The argument for which
psi must be evaluated.
Output Parameters
- 1:
– double scalar
-
The value of the weight function
evaluated at
t.
- 3:
– double scalar
-
The value of .
- 4:
– double scalar
-
If
,
beta must specify the value of
.
For Huber and Schweppe type regressions,
is the
th percentile of the standard Normal distribution (see
nag_stat_inv_cdf_normal (g01fa)). For Mallows type regression
is the solution to
where
is the standard Normal cumulative distribution function (see
nag_specfun_cdf_normal (s15ab)).
If
,
beta must specify the value of
.
where
is the standard normal density, i.e.,
.
If
,
beta is not referenced.
Constraint:
if , .
- 5:
– int64int32nag_int scalar
-
Determines the type of regression to be performed.
- Huber type regression.
- Mallows type regression.
- Schweppe type regression.
- 6:
– int64int32nag_int scalar
-
Determines how
is to be estimated.
- is held constant at its initial value.
- is estimated by median absolute deviation of residuals.
- is estimated using the function.
- 7:
– 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
, 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.
- 8:
– double array
-
The data values of the dependent variable.
must contain the value of for the th observation, for .
If
, 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.
- 9:
– double array
-
The weight for the
th observation, for
.
If
, 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 , the th observation is not included in the analysis.
If
,
wgt is not referenced.
- 10:
– 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.
- 11:
– 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 arrays
y,
wgt 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 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
.
Constraint:
.
- 4:
– double scalar
Default:
A relative tolerance to be used to determine the rank of
. See
nag_linsys_real_gen_solve (f04jg) for further details.
If
or
then
machine precision will be used in place of
tol.
A reasonable value for
eps is
where this value is possible.
- 5:
– int64int32nag_int scalar
Default:
The maximum number of iterations that should be used during the estimation.
A value of should be adequate for most uses.
Constraint:
.
- 6:
– int64int32nag_int scalar
Default:
Determines the amount of information that is printed on each iteration.
- No information is printed.
- 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
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
-
Unchanged, except as described above.
- 4:
– double array
-
The M-estimate of
, for .
- 5:
– int64int32nag_int scalar
-
The column rank of the matrix .
- 6:
– double scalar
-
The final estimate of if or the value assigned on entry if .
- 7:
– double array
-
The residuals from the model evaluated at final value of
theta, i.e.,
rs contains the vector
.
- 8:
– int64int32nag_int scalar
-
The number of iterations that were used during the estimation.
- 9:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Note: nag_correg_robustm_user (g02hd) 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 | . |
-
-
On entry, | , and , |
or | . |
-
-
On entry, | , |
or | . |
-
-
A value returned by the
chi function is negative.
-
-
During iterations a value of was encountered.
-
-
A failure occurred in
nag_linsys_real_gen_solve (f04jg) . This is an extremely unlikely error. If it occurs, please contact
NAG.
- W
-
The weighted least squares equations are not of full rank. This may be due to the
matrix not being of full rank, in which case the results will be valid. It may also occur if some of the
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
and
is possible (see
nag_linsys_real_gen_solve (f04jg)).
-
-
The function has failed to converge in
maxit iterations.
-
-
Having removed cases with zero weight, the value of , i.e., no degree of freedom for error. This error will only occur if .
-
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 accuracy of the results is controlled by
tol.
For the accuracy of the weighted least squares see
nag_linsys_real_gen_solve (f04jg).
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, which will lead to convergence problems and may trigger the
error.
By suitable choice of the functions
chi and
psi this function may be used for other applications of iterative weighted least squares.
For the variance-covariance matrix of
see
nag_correg_robustm_user_varmat (g02hf).
Example
Having input , and the weights, a Schweppe type regression is performed using Huber's function. The function BETCAL calculates the appropriate value of .
Open in the MATLAB editor:
g02hd_example
function g02hd_example
fprintf('g02hd example results\n\n');
global dchi
dchi = 1.5;
x = [1, -1, -1;
1, -1, 1;
1, 1, -1;
1, 1, 1;
1, 0, 3];
y = [10.5; 11.3; 12.6; 13.4; 17.1 ];
wgt = [0.4039; 0.5012; 0.4039; 0.5012; 0.3862];
[n,m] = size(x);
[beta] = betcal(wgt);
psip0 = 1;
indw = int64(1);
isigma = int64(1);
sigma = 1;
theta = zeros(m,1);
[x, y, wgt, theta, k, sigma, rs, nit, ifail] = ...
g02hd( ...
@chi, @psi, psip0, beta, indw, isigma, x, y, wgt, theta, sigma);
fprintf(' iterations to convergence = %4d\n', nit);
fprintf(' k = %4d\n',k);
fprintf(' sigma = %9.4f\n',sigma);
fprintf('Theta:\n');
disp(theta');
fprintf('\n Weights Residuals\n');
fprintf('%9.4f%9.4f\n', [wgt rs]');
function [result] = chi(t)
global dchi
if (abs(t) < dchi)
ps=t;
else
ps=dchi;
end
result = ps*ps/2;
function [result] = psi(t)
global dchi
if t < -dchi
result = -dchi;
elseif abs(t) < dchi
result = t;
else
result = dchi;
end;
function [beta] = betcal(wgt)
global dchi
n = numel(wgt);
amaxex = -log(x02ak);
anormc = sqrt(2*pi);
d2 = dchi*dchi;
beta = 0;
for i = 1:n
w2 = wgt(i)*wgt(i);
dw = wgt(i)*dchi;
[pc, ifail] = s15ab(dw);
dw2 = dw*dw;
if dw2<amaxex
dc = exp(-dw2/2)/anormc;
else
dc = 0;
end
b = (-dw*dc+pc-0.5)/w2 + (1-pc)*d2;
beta = b*w2/n + beta;
end
g02hd example results
iterations to convergence = 5
k = 3
sigma = 2.7783
Theta:
12.2321 1.0500 1.2464
Weights Residuals
0.4039 0.5643
0.5012 -1.1286
0.4039 0.5643
0.5012 -1.1286
0.3862 1.1286
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015