NAG Library Function Document
nag_robust_m_regsn_user_fn (g02hdc)
1 Purpose
nag_robust_m_regsn_user_fn (g02hdc) performs bounded influence regression (-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
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_robust_m_regsn_user_fn (g02hdc) 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_robust_m_regsn_wts (g02hbc), |
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
a least squares solver.
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_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
. See
Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint:
or .
- 2:
chi – function, supplied by the userExternal Function
If
,
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.
- user – double *
- iuser – Integer *
- p – Pointer
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 3.2.1.1 in the Essential Introduction).
chi is required only if
, otherwise it can be specified as a pointer with
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.
- user – double *
- iuser – Integer *
- p – Pointer
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 3.2.1.1 in the Essential Introduction).
- 4:
psip0 – doubleInput
On entry: the value of .
- 5:
beta – doubleInput
On entry: if
,
beta must specify the value of
.
For Huber and Schweppe type regressions,
is the
th percentile of the standard Normal distribution (see
nag_deviates_normal (g01fac)). For Mallows type regression
is the solution to
where
is the standard Normal cumulative distribution function (see
nag_cumul_normal (s15abc)).
If
,
beta must specify the value of
.
where
is the standard normal density, i.e.,
.
If
,
beta is not referenced.
Constraint:
if , .
- 6:
regtype – Nag_RegTypeInput
On entry: determines the type of regression to be performed.
- Huber type regression.
- Mallows type regression.
- Schweppe type regression.
Constraint:
, or .
- 7:
sigma_est – Nag_SigmaEstInput
On entry: 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.
Constraint:
, or .
- 8:
n – IntegerInput
On entry: , the number of observations.
Constraint:
.
- 9:
m – IntegerInput
On entry: , the number of independent variables.
Constraint:
.
- 10:
x[] – doubleInput/Output
-
Note: the dimension,
dim, of the array
x
must be at least
- when ;
- when .
Where
appears in this document, it refers to the array element
- when ;
- when .
On entry: 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
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 ,
;
- if , .
- 12:
y[n] – doubleInput/Output
On entry: 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
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
th observation, for
.
If
, 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 , the th observation is not included in the analysis.
If
,
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
and
or if
and
sigma approximately equals the standard deviation of the dependent variable,
, then
, for
may provide reasonable starting values.
On exit: the M-estimate of
, for .
- 15:
k – Integer *Output
On exit: the column rank of the matrix .
- 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:
.
On exit: the final estimate of if or the value assigned on entry if .
- 17:
rs[n] – doubleOutput
On exit: the residuals from the model evaluated at final value of
theta, i.e.,
rs contains the vector
.
- 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
.
Constraint:
.
- 19:
eps – doubleInput
On entry: a relative tolerance to be used to determine the rank of
.
If
or
then
machine precision will be used in place of
tol.
A reasonable value for
eps is
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 should be adequate for most uses.
Constraint:
.
- 21:
nitmon – IntegerInput
On entry: 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.
- 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 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 *Communication Structure
-
The NAG communication argument (see
Section 3.2.1.1 in the Essential Introduction).
- 25:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_CHI
-
Value given by
chi function
:
.
- 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:
.
- NE_FULL_RANK
-
Weighted least squares equations not of full rank: rank .
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_2
-
On entry, and .
Constraint: .
On entry, and .
Constraint: .
- 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.
- NE_NOT_CLOSE_FILE
-
Cannot close file .
- NE_NOT_WRITE_FILE
-
Cannot open file for writing.
- NE_REAL
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_ZERO_DF
-
On entry, and .
Constraint: .
- 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
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, which will lead to convergence problems and may trigger the
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 , and the weights, a Schweppe type regression is performed using Huber's function. The function BETCAL calculates the appropriate value of .
10.1 Program Text
Program Text (g02hdce.c)
10.2 Program Data
Program Data (g02hdce.d)
10.3 Program Results
Program Results (g02hdce.r)