hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_correg_robustm_user (g02hd)

Purpose

nag_correg_robustm_user (g02hd) performs bounded influence regression (MM-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:
Mark 23: nitmon, tol, maxit, eps now optional
.

Description

For the linear regression model
y = Xθ + ε,
y=Xθ+ε,
where yy is a vector of length nn of the dependent variable,
XX is a nn by mm matrix of independent variables of column rank kk,
θθ is a vector of length mm of unknown parameters,
and εε is a vector of length nn of unknown errors with var (εi) = σ2(εi)=σ2,
nag_correg_robustm_user (g02hd) calculates the M-estimates given by the solution, θ̂θ^, to the equation
n
ψ(ri / (σwi))wixij = 0,  j = 1,2,,m,
i = 1
i=1nψ(ri/(σwi))wixij=0,  j=1,2,,m,
(1)
where riri is the iith residual, i.e., the iith element of the vector r = yXθ̂r=y-Xθ^,
ψψ is a suitable weight function,
wiwi 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 σ̂ = medi[|ri|] / β1σ^=medi[|ri|]/β1
or as the solution to
n
χ(ri / (σ̂wi))wi2 = (nk)β2
i = 1
i=1nχ(ri/(σ^wi))wi2=(n-k)β2
for a suitable weight function χχ, where β1β1 and β2β2 are constants, chosen so that the estimator of σσ is asymptotically unbiased if the errors, εiεi, have a Normal distribution. Alternatively σσ may be held at a constant value.
The above describes the Schweppe type regression. If the wiwi are assumed to equal 11 for all ii, then Huber type regression is obtained. A third type, due to Mallows, replaces (1) by
n
ψ(ri / σ)wixij = 0,  j = 1,2,,m.
i = 1
i=1nψ(ri/σ)wixij=0,  j=1,2,,m.
This may be obtained by use of the transformations
wi * sqrt(wi)
yi * yisqrt(wi)
xij * xijsqrt(wi),   j = 1,2,,m
wi* wi yi* yiwi xij* 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 GG given by
Gii =
{ (ψ(ri / (σwi)))/((ri / (σwi))), ri ≠ 0 ψ(0), ri = 0.
.
Gii={ ψ(ri/(σwi)) (ri/(σwi)) , ri0 ψ(0), ri=0. .
The value of θθ at each iteration is given by the weighted least squares regression of yy on XX. This is carried out by first transforming the yy and XX by
i = yisqrt(Gii)
ij = xijsqrt(Gii),  j = 1,2,,m
y~i =yiGii x~ij =xijGii,  j=1,2,,m
and then using nag_linsys_real_gen_solve (f04jg) . If XX is of full column rank then an orthogonal-triangular (QRQR) 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 1.01.0 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:     chi – function handle or string containing name of m-file
If isigma > 0isigma>0, 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:     t – double scalar
The argument for which chi must be evaluated.

Output Parameters

1:     result – double scalar
The result of the function.
If isigma0isigma0, the actual parameter chi may be the string 'g02hdz'. (nag_correg_robustm_user_dummy_chi (g02hdz) is included in the NAG Toolbox.)
2:     psi – 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:     t – double scalar
The argument for which psi must be evaluated.

Output Parameters

1:     result – double scalar
The result of the function.
3:     psip0 – double scalar
The value of ψ(0)ψ(0).
4:     beta – double scalar
If isigma < 0isigma<0, beta must specify the value of β1β1.
For Huber and Schweppe type regressions, β1β1 is the 7575th percentile of the standard Normal distribution (see nag_stat_inv_cdf_normal (g01fa)). For Mallows type regression β1β1 is the solution to
n
1/nΦ(β1 / sqrt(wi)) = 0.75,
i = 1
1ni=1nΦ(β1/wi)=0.75,
where ΦΦ is the standard Normal cumulative distribution function (see nag_specfun_cdf_normal (s15ab)).
If isigma > 0isigma>0, beta must specify the value of β2β2.
β2 =
χ(z)φ(z)dz,
in the Huber case;
β2 =
n
1/nwiχ(z)φ(z)dz,
i = 1
in the Mallows case;
β2 =
n
1/nwi2χ(z / wi)φ(z)dz,
i = 1
in the Schweppe case;
β2= -χ(z)ϕ(z)dz, in the Huber case; β2= 1ni=1nwi-χ(z)ϕ(z)dz, in the Mallows case; β2= 1ni=1nwi2-χ(z/wi)ϕ(z)dz, in the Schweppe case;
where φϕ is the standard normal density, i.e., 1/(sqrt(2π))exp((1/2)x2) 12πexp(-12x2) .
If isigma = 0isigma=0, beta is not referenced.
Constraint: if isigma0isigma0, beta > 0.0beta>0.0.
5:     indw – int64int32nag_int scalar
Determines the type of regression to be performed.
indw = 0indw=0
Huber type regression.
indw < 0indw<0
Mallows type regression.
indw > 0indw>0
Schweppe type regression.
6:     isigma – int64int32nag_int scalar
Determines how σσ is to be estimated.
isigma = 0isigma=0
σσ is held constant at its initial value.
isigma < 0isigma<0
σσ is estimated by median absolute deviation of residuals.
isigma > 0isigma>0
σσ is estimated using the χχ function.
7:     x(ldx,m) – double array
ldx, the first dimension of the array, must satisfy the constraint ldxnldxn.
The values of the XX matrix, i.e., the independent variables. x(i,j)xij must contain the ijijth element of xx, for i = 1,2,,ni=1,2,,n and j = 1,2,,mj=1,2,,m.
If indw < 0indw<0, during calculations the elements of x will be transformed as described in Section [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:     y(n) – double array
n, the dimension of the array, must satisfy the constraint n > 1n>1.
The data values of the dependent variable.
y(i)yi must contain the value of yy for the iith observation, for i = 1,2,,ni=1,2,,n.
If indw < 0indw<0, during calculations the elements of y will be transformed as described in Section [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:     wgt(n) – double array
n, the dimension of the array, must satisfy the constraint n > 1n>1.
The weight for the iith observation, for i = 1,2,,ni=1,2,,n.
If indw < 0indw<0, during calculations elements of wgt will be transformed as described in Section [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)0wgti0, the iith observation is not included in the analysis.
If indw = 0indw=0, wgt is not referenced.
10:   theta(m) – double array
m, the dimension of the array, must satisfy the constraint 1m < n1m<n.
Starting values of the parameter vector θθ. These may be obtained from least squares regression. Alternatively if isigma < 0isigma<0 and sigma = 1sigma=1 or if isigma > 0isigma>0 and sigma approximately equals the standard deviation of the dependent variable, yy, then theta(i) = 0.0thetai=0.0, for i = 1,2,,mi=1,2,,m may provide reasonable starting values.
11:   sigma – 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: sigma > 0.0sigma>0.0.

Optional Input Parameters

1:     n – 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.)
nn, the number of observations.
Constraint: n > 1n>1.
2:     m – 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.)
mm, the number of independent variables.
Constraint: 1m < n1m<n.
3:     tol – double scalar
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 precision100×machine precision.
Default: 5e-55e-5
Constraint: tol > 0.0tol>0.0.
4:     eps – double scalar
A relative tolerance to be used to determine the rank of XX. See nag_linsys_real_gen_solve (f04jg) for further details.
If eps < machine precisioneps<machine precision or eps > 1.0eps>1.0 then machine precision will be used in place of tol.
A reasonable value for eps is 5.0 × 1065.0×10-6 where this value is possible.
Default: 5e-65e-6
5:     maxit – int64int32nag_int scalar
The maximum number of iterations that should be used during the estimation.
A value of maxit = 50maxit=50 should be adequate for most uses.
Default: 5050
Constraint: maxit > 0maxit>0.
6:     nitmon – int64int32nag_int scalar
Determines the amount of information that is printed on each iteration.
nitmon0nitmon0
No information is printed.
nitmon > 0nitmon>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 nag_file_set_unit_advisory (x04ab)).
Default: 00

Input Parameters Omitted from the MATLAB Interface

ldx wk

Output Parameters

1:     x(ldx,m) – double array
ldxnldxn.
Unchanged, except as described above.
2:     y(n) – double array
Unchanged, except as described above.
3:     wgt(n) – double array
Unchanged, except as described above.
4:     theta(m) – double array
The M-estimate of θiθi, for i = 1,2,,mi=1,2,,m.
5:     k – int64int32nag_int scalar
The column rank of the matrix XX.
6:     sigma – double scalar
The final estimate of σσ if isigma0isigma0 or the value assigned on entry if isigma = 0isigma=0.
7:     rs(n) – double array
The residuals from the model evaluated at final value of theta, i.e., rs contains the vector (yXθ̂)(y-Xθ^).
8:     nit – int64int32nag_int scalar
The number of iterations that were used during the estimation.
9:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 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.

  ifail = 1ifail=1
On entry,n1n1,
orm < 1m<1,
ornmnm,
orldx < nldx<n.
  ifail = 2ifail=2
On entry,beta0.0beta0.0, and isigma0isigma0,
orsigma0.0sigma0.0.
  ifail = 3ifail=3
On entry,tol0.0tol0.0,
ormaxit0maxit0.
  ifail = 4ifail=4
A value returned by the chi function is negative.
  ifail = 5ifail=5
During iterations a value of sigma0.0sigma0.0 was encountered.
  ifail = 6ifail=6
A failure occurred in nag_linsys_real_gen_solve (f04jg) . This is an extremely unlikely error. If it occurs, please contact NAG.
W ifail = 7ifail=7
The weighted least squares equations are not of full rank. This may be due to the XX matrix not being of full rank, in which case the results will be valid. It may also occur if some of the GiiGii values become very small or zero, see Section [Further Comments]. The rank of the equations is given by k. If the matrix just fails the test for nonsingularity then the result ifail = 7ifail=7 and k = mk=m is possible (see nag_linsys_real_gen_solve (f04jg)).
  ifail = 8ifail=8
The function has failed to converge in maxit iterations.
  ifail = 9ifail=9
Having removed cases with zero weight, the value of nk0n-k0, i.e., no degree of freedom for error. This error will only occur if isigma > 0isigma>0.

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 isigma0isigma0 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 / σ)ψ(ri/σ), to be zero, which will lead to convergence problems and may trigger the ifail = 7ifail=7 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

function nag_correg_robustm_user_example
psip0 = 1;
beta = 0.1443849979905463;
indw = int64(1);
isigma = int64(1);
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];
theta = [0;
     0;
     0];
sigma = 1;
[xOut, yOut, wgtOut, thetaOut, k, sigmaOut, rs, nit, ifail] = ...
     nag_correg_robustm_user(@chi, @psi, psip0, beta, indw, isigma, x, y, wgt, ...
           theta, sigma)

function [result] = chi(t)
  if (abs(t) < 1.5)
    ps=t;
  else
    ps=1.5;
  end
  result = ps*ps/2;

function [result] = psi(t)
  if t < -1.5
    result = -1.5;
  elseif abs(t) < 1.5
    result = t;
  else
    result = 1.5;
  end;
 

xOut =

     1    -1    -1
     1    -1     1
     1     1    -1
     1     1     1
     1     0     3


yOut =

   10.5000
   11.3000
   12.6000
   13.4000
   17.1000


wgtOut =

    0.4039
    0.5012
    0.4039
    0.5012
    0.3862


thetaOut =

   12.2321
    1.0500
    1.2464


k =

                    3


sigmaOut =

    2.7783


rs =

    0.5643
   -1.1286
    0.5643
   -1.1286
    1.1286


nit =

                    5


ifail =

                    0


function g02hd_example
psip0 = 1;
beta = 0.1443849979905463;
indw = int64(1);
isigma = int64(1);
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];
theta = [0;
     0;
     0];
sigma = 1;
[xOut, yOut, wgtOut, thetaOut, k, sigmaOut, rs, nit, ifail] = ...
     g02hd(@chi, @psi, psip0, beta, indw, isigma, x, y, wgt, ...
           theta, sigma)

function [result] = chi(t)
  if (abs(t) < 1.5)
    ps=t;
  else
    ps=1.5;
  end
  result = ps*ps/2;

function [result] = psi(t)
  if t < -1.5
    result = -1.5;
  elseif abs(t) < 1.5
    result = t;
  else
    result = 1.5;
  end;
 

xOut =

     1    -1    -1
     1    -1     1
     1     1    -1
     1     1     1
     1     0     3


yOut =

   10.5000
   11.3000
   12.6000
   13.4000
   17.1000


wgtOut =

    0.4039
    0.5012
    0.4039
    0.5012
    0.3862


thetaOut =

   12.2321
    1.0500
    1.2464


k =

                    3


sigmaOut =

    2.7783


rs =

    0.5643
   -1.1286
    0.5643
   -1.1286
    1.1286


nit =

                    5


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013