nag_robust_m_regsn_user_fn (g02hdc) (PDF version)
g02 Chapter Contents
g02 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_robust_m_regsn_user_fn (g02hdc)

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_robust_m_regsn_user_fn (g02hdc) performs bounded influence regression (M-estimates) using an iterative weighted least squares algorithm.

2  Specification

#include <nag.h>
#include <nagg02.h>
void  nag_robust_m_regsn_user_fn (Nag_OrderType order,
double (*chi)(double t, Nag_Comm *comm),
double (*psi)(double t, Nag_Comm *comm),
double psip0, double beta, Nag_RegType regtype, Nag_SigmaEst sigma_est, Integer n, Integer m, double x[], Integer pdx, double y[], double wgt[], double theta[], Integer *k, double *sigma, double rs[], double tol, double eps, Integer maxit, Integer nitmon, const char *outfile, Integer *nit, Nag_Comm *comm, NagError *fail)

3  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,
θ is a vector of length m of unknown arguments,
and ε is a vector of length n of unknown errors with var εi=σ2,
nag_robust_m_regsn_user_fn (g02hdc) calculates the M-estimates given by the solution, θ^, to the equation
i=1nψri/σwiwixij=0,  j=1,2,,m, (1)
where ri is the ith residual, i.e., the ith element of the vector r=y-Xθ^,
ψ is a suitable weight function,
wi are suitable weights such as those that can be calculated by using output from nag_robust_m_regsn_wts (g02hbc),
and σ may be estimated at each iteration by the median absolute deviation of the residuals σ^=mediri/β1
or as the solution to
i=1nχri/σ^wiwi2=n-kβ2  
for a suitable weight function χ, where β1 and β2 are constants, chosen so that the estimator of σ is asymptotically unbiased if the errors, εi, have a Normal distribution. Alternatively σ may be held at a constant value.
The above describes the Schweppe type regression. If the wi 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* 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 G given by
Gii= ψri/σwi ri/σwi , ri0 ψ0, ri=0. .  
The value of θ 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 =yiGii x~ij =xijGii,  j=1,2,,m  
and then using a least squares solver. If X is of full column rank then an orthogonal-triangular (QR) 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.0 for all observations will produce a value of θ^ corresponding to the usual constant term.
nag_robust_m_regsn_user_fn (g02hdc) is based on routines in ROBETH, see Marazzi (1987).

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 (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

5  Arguments

1:     order Nag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by order=Nag_RowMajor. See Section 2.3.1.3 in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2:     chi function, supplied by the userExternal Function
If sigma_est=Nag_SigmaChi, chi must return the value of the weight function χ for a given value of its argument. The value of χ must be non-negative.
The specification of chi is:
double  chi (double t, Nag_Comm *comm)
1:     t doubleInput
On entry: the argument for which chi must be evaluated.
2:     comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to chi.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling nag_robust_m_regsn_user_fn (g02hdc) you may allocate memory and initialize these pointers with various quantities for use by chi when called from nag_robust_m_regsn_user_fn (g02hdc) (see Section 2.3.1.1 in How to Use the NAG Library and its Documentation).
chi is required only if sigma_est=Nag_SigmaConst, otherwise it can be specified as a pointer with 0 value.
3:     psi function, supplied by the userExternal Function
psi must return the value of the weight function ψ for a given value of its argument.
The specification of psi is:
double  psi (double t, Nag_Comm *comm)
1:     t doubleInput
On entry: the argument for which psi must be evaluated.
2:     comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to psi.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling nag_robust_m_regsn_user_fn (g02hdc) you may allocate memory and initialize these pointers with various quantities for use by psi when called from nag_robust_m_regsn_user_fn (g02hdc) (see Section 2.3.1.1 in How to Use the NAG Library and its Documentation).
4:     psip0 doubleInput
On entry: the value of ψ0.
5:     beta doubleInput
On entry: if sigma_est=Nag_SigmaRes, beta must specify the value of β1.
For Huber and Schweppe type regressions, β1 is the 75th percentile of the standard Normal distribution (see nag_deviates_normal (g01fac)). For Mallows type regression β1 is the solution to
1ni=1nΦβ1/wi=0.75,  
where Φ is the standard Normal cumulative distribution function (see nag_cumul_normal (s15abc)).
If sigma_est=Nag_SigmaChi, beta must specify the value of β2.
β2= -χzϕzdz, in the Huber case; β2= 1ni=1nwi-χzϕzdz, in the Mallows case; β2= 1ni=1nwi2-χz/wiϕzdz, in the Schweppe case;  
where ϕ is the standard normal density, i.e., 12πexp-12x2 .
If sigma_est=Nag_SigmaConst, beta is not referenced.
Constraint: if sigma_estNag_SigmaConst, beta>0.0.
6:     regtype Nag_RegTypeInput
On entry: determines the type of regression to be performed.
regtype=Nag_HuberReg
Huber type regression.
regtype=Nag_MallowsReg
Mallows type regression.
regtype=Nag_SchweppeReg
Schweppe type regression.
Constraint: regtype=Nag_MallowsReg, Nag_HuberReg or Nag_SchweppeReg.
7:     sigma_est Nag_SigmaEstInput
On entry: determines how σ is to be estimated.
sigma_est=Nag_SigmaConst
σ is held constant at its initial value.
sigma_est=Nag_SigmaRes
σ is estimated by median absolute deviation of residuals.
sigma_est=Nag_SigmaChi
σ is estimated using the χ function.
Constraint: sigma_est=Nag_SigmaRes, Nag_SigmaConst or Nag_SigmaChi.
8:     n IntegerInput
On entry: n, the number of observations.
Constraint: n>1.
9:     m IntegerInput
On entry: m, the number of independent variables.
Constraint: 1m<n.
10:   x[dim] doubleInput/Output
Note: the dimension, dim, of the array x must be at least
  • max1,pdx×m when order=Nag_ColMajor;
  • max1,n×pdx when order=Nag_RowMajor.
Where Xi,j appears in this document, it refers to the array element
  • x[j-1×pdx+i-1] when order=Nag_ColMajor;
  • x[i-1×pdx+j-1] when order=Nag_RowMajor.
On entry: the values of the X matrix, i.e., the independent variables. Xi,j must contain the ijth element of x, for i=1,2,,n and j=1,2,,m.
If regtype=Nag_MallowsReg, 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.
11:   pdx IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array x.
Constraints:
  • if order=Nag_ColMajor, pdxn;
  • if order=Nag_RowMajor, pdxm.
12:   y[n] doubleInput/Output
On entry: the data values of the dependent variable.
y[i-1] must contain the value of y for the ith observation, for i=1,2,,n.
If regtype=Nag_MallowsReg, 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.
13:   wgt[n] doubleInput/Output
On entry: the weight for the ith observation, for i=1,2,,n.
If regtype=Nag_MallowsReg, during calculations elements of wgt 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 wgt and the output wgt.
If wgt[i-1]0, the ith observation is not included in the analysis.
If regtype=Nag_HuberReg, wgt is not referenced.
On exit: unchanged, except as described above.
14:   theta[m] doubleInput/Output
On entry: starting values of the argument vector θ. These may be obtained from least squares regression. Alternatively if sigma_est=Nag_SigmaRes and sigma=1 or if sigma_est=Nag_SigmaChi and sigma approximately equals the standard deviation of the dependent variable, y, then theta[i-1]=0.0, for i=1,2,,m may provide reasonable starting values.
On exit: the M-estimate of θi, for i=1,2,,m.
15:   k Integer *Output
On exit: the column rank of the matrix X.
16:   sigma double *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: sigma>0.0.
On exit: the final estimate of σ if sigma_estNag_SigmaConst or the value assigned on entry if sigma_est=Nag_SigmaConst.
17:   rs[n] doubleOutput
On exit: the residuals from the model evaluated at final value of theta, i.e., rs contains the vector y-Xθ^.
18:   tol doubleInput
On entry: 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 precision.
Constraint: tol>0.0.
19:   eps doubleInput
On entry: a relative tolerance to be used to determine the rank of X.
If eps<machine precision or eps>1.0 then machine precision will be used in place of tol.
A reasonable value for eps is 5.0×10-6 where this value is possible.
20:   maxit IntegerInput
On entry: the maximum number of iterations that should be used during the estimation.
A value of maxit=50 should be adequate for most uses.
Constraint: maxit>0.
21:   nitmon IntegerInput
On entry: determines the amount of information that is printed on each iteration.
nitmon0
No information is printed.
nitmon>0
On the first and every nitmon iterations the values of sigma, theta and the change in theta during the iteration are printed.
22:   outfile const char *Input
On entry: a null terminated character string giving the name of the file to which results should be printed. If outfile=NULL or an empty string then the stdout stream is used. Note that the file will be opened in the append mode.
23:   nit Integer *Output
On exit: the number of iterations that were used during the estimation.
24:   comm Nag_Comm *
The NAG communication argument (see Section 2.3.1.1 in How to Use the NAG Library and its Documentation).
25:   fail NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_CHI
Value given by chi function <0: chivalue=value.
NE_CONVERGENCE_SOL
Iterations to solve the weighted least squares equations failed to converge.
NE_CONVERGENCE_THETA
Iterations to calculate estimates of theta failed to converge in maxit iterations: maxit=value.
NE_FULL_RANK
Weighted least squares equations not of full rank: rank =value.
NE_INT
On entry, maxit=value.
Constraint: maxit>0.
On entry, n=value.
Constraint: n>1.
On entry, pdx=value.
Constraint: pdx>0.
NE_INT_2
On entry, m=value and n=value.
Constraint: 1m<n.
On entry, pdx=value and m=value.
Constraint: pdxm.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
An unexpected error has been triggered by this function. Please contact NAG.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_NOT_CLOSE_FILE
Cannot close file value.
NE_NOT_WRITE_FILE
Cannot open file value for writing.
NE_REAL
On entry, beta=value.
Constraint: beta>0.0.
On entry, sigma=value.
Constraint: sigma>0.0.
On entry, tol=value.
Constraint: tol>0.0.
NE_ZERO_DF
On entry, n=value and k=value.
Constraint: n-k>0.
NE_ZERO_VALUE
Estimated value of sigma is zero.

7  Accuracy

The accuracy of the results is controlled by tol.

8  Parallelism and Performance

nag_robust_m_regsn_user_fn (g02hdc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_robust_m_regsn_user_fn (g02hdc) 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments

In cases when sigma_estNag_SigmaConst 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/σ, to be zero, which will lead to convergence problems and may trigger the fail.code= NE_FULL_RANK 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_robust_m_regsn_param_var (g02hfc).

10  Example

Having input X, Y and the weights, a Schweppe type regression is performed using Huber's ψ function. The function BETCAL calculates the appropriate value of β2.

10.1  Program Text

Program Text (g02hdce.c)

10.2  Program Data

Program Data (g02hdce.d)

10.3  Program Results

Program Results (g02hdce.r)


nag_robust_m_regsn_user_fn (g02hdc) (PDF version)
g02 Chapter Contents
g02 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2016