NAG Library Function Document
nag_robust_m_regsn_estim (g02hac)
1 Purpose
nag_robust_m_regsn_estim (g02hac) performs bounded influence regression (M-estimates). Several standard methods are available.
2 Specification
#include <nag.h> |
#include <nagg02.h> |
void |
nag_robust_m_regsn_estim (Nag_RegType regtype,
Nag_PsiFun psifun,
Nag_SigmaEst sigma_est,
Nag_CovMatrixEst covmat_est,
Integer n,
Integer m,
double x[],
Integer tdx,
double y[],
double cpsi,
const double hpsi[],
double cucv,
double dchi,
double theta[],
double *sigma,
double c[],
Integer tdc,
double rs[],
double wt[],
double tol,
Integer max_iter,
Integer print_iter,
const char *outfile,
double info[],
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 : |
nag_robust_m_regsn_estim (g02hac) 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 1 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
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.
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 obtaining the solution of the resulting least squares problem. If is of full column rank then an orthogonal-triangular (QR) decomposition is used, if not, a singular value decomposition is used.
The following functions are available for and in nag_robust_m_regsn_estim (g02hac).
(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 a by lower triangular matrix, |
and |
is a suitable function. |
The weights are then calculated as
for a suitable function
.
nag_robust_m_regsn_estim (g02hac) finds
using the iterative procedure
where
,
and
and
and
are bounds set at 0.9.
Two weights are available in nag_robust_m_regsn_estim (g02hac):
(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
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_robust_m_regsn_estim (g02hac):
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 1.0 for all observations will produce a value of corresponding to the usual constant term.
nag_robust_m_regsn_estim (g02hac) is based on routines in ROBETH, see
Marazzi (1987a).
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 (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
5 Arguments
- 1:
– Nag_RegTypeInput
-
On entry: specifies the type of regression to be performed.
- Huber type regression.
- Mallows type regression with Maronna's proposed weights.
- Schweppe type regression with Krasker–Welsch weights.
Constraint:
, or .
- 2:
– Nag_PsiFunInput
-
On entry: 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:
, , , or .
- 3:
– Nag_SigmaEstInput
-
On entry: 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.
Constraint:
, or .
- 4:
– Nag_CovMatrixEstInput
-
On entry: if
,
covmat_est specifies the approximations used in estimating the covariance matrix of
.
, averaging over residuals.
, replacing expected by observed.
If
then
covmat_est is not referenced.
Constraint:
or .
- 5:
– IntegerInput
-
On entry: the number of observations, .
Constraint:
.
- 6:
– IntegerInput
-
On entry: the number , of independent variables.
Constraint:
.
- 7:
– doubleInput/Output
-
Note: the th element of the matrix is stored in .
On entry: the values of the matrix, i.e., the independent variables. must contain the th element of , for and .
On exit: if
, then 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. Otherwise
x is unchanged.
- 8:
– IntegerInput
-
On entry: the stride separating matrix column elements in the array
x.
Constraint:
.
- 9:
– doubleInput/Output
-
On entry: the data values of the dependent variable. must contain the value of for the th observation, for .
On exit: if
, then 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. Otherwise
y is unchanged.
- 10:
– doubleInput
-
On entry: if
,
cpsi must specify the argument,
, of Huber's
function. Otherwise
cpsi is not referenced.
Constraint:
if then .
- 11:
– const doubleInput
-
On entry: if
then
,
and
must specify the arguments
,
, and
, of Hampel's piecewise linear
function. Otherwise the elements of
hpsi are not referenced.
Constraint:
if , and .
- 12:
– doubleInput
-
On entry: if
then
cucv must specify the value of the constant,
, of the function
for Maronna's proposed weights.
If
then
cucv must specify the value of the function
for the Krasker–Welsch weights.
If
then
cucv is not referenced.
Constraints:
- if , ;
- if , .
- 13:
– doubleInput
-
On entry: the constant,
, of the
function.
dchi is referenced only if
and
.
Constraint:
if and , .
- 14:
– 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: contains the M-estimate of , for .
- 15:
– 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.
On exit:
sigma contains the final estimate of
, unless
.
Constraint:
.
- 16:
– doubleOutput
-
On exit: 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
, for
.
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 .
- 17:
– IntegerInput
-
On entry: the stride separating matrix column elements in the array
c.
Constraint:
.
- 18:
– doubleOutput
-
On exit: contains the residuals from the model evaluated at final value of
theta, i.e.,
, for
, contains the vector
.
- 19:
– doubleOutput
-
On exit: contains the vector of weights. contains the weight for the th observation, for .
- 20:
– doubleInput
-
On entry: 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
machine precision.
Constraint:
.
- 21:
– IntegerInput
-
On entry: the maximum number of iterations that should be used in the calculation of (if ), and of the estimates of and , and of (if and )
Suggested value:
A value of should be adequate for most uses.
Constraint:
.
- 22:
– IntegerInput
-
On entry: 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
Section 3).
- 23:
– const char *Input
-
On entry: a null terminated character string giving the name of the file to which results should be printed. If
outfile is
NULL or an empty string then the
stdout stream is used. Note that the file will be opened in the append mode.
- 24:
– doubleOutput
-
On exit: elements of info contain the following values:
- 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.
- 25:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_2_INT_ARG_GE
-
On entry, while . These arguments must satisfy .
- NE_2_INT_ARG_LT
-
On entry, while . These arguments must satisfy .
On entry, while . These arguments must satisfy .
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
- NE_BAD_HAMPEL_PSI_FUN
-
On entry,
and
,
and
. For this value of
psifun, the elements of
hpsi must satisfy the condition
and
.
- NE_BAD_PARAM
-
On entry, argument
covmat_est had an illegal value.
On entry, argument
psifun had an illegal value.
On entry, argument
regtype had an illegal value.
On entry, argument
sigma_est had an illegal value.
- NE_BETA1_ITER_EXCEEDED
-
The number of iterations required to calculate
exceeds
max_iter. This is only applicable if
and
.
- NE_COV_MAT_FACTOR_ZERO
-
In calculating the correlation factor for the asymptotic variance-covariance matrix, the factor for covariance matrix
.
For this error, either the value of
or |
, |
or |
.
See Section 9. In this case c is returned as .
(This is only applicable if ). |
- NE_ERR_DOF_LEQ_ZERO
-
, rank of
. The degrees of freedom for error,
(rank of
x) must be
.
- NE_ESTIM_SIGMA_ZERO
-
The estimated value of was during an iteration.
- NE_INT_ARG_LE
-
On entry,
max_iter must not be less than or equal to 0:
.
- NE_INT_ARG_LT
-
On entry, .
Constraint: .
On entry, .
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_INVALID_DCHI_FUN
-
On entry,
,
and
. For these values of
psifun and
sigma_est,
dchi must be
.
- NE_INVALID_HUBER_FUN
-
On entry,
and
. For this value of
psifun,
cpsi must be
.
- NE_INVALID_MALLOWS_REG_C
-
On entry,
,
and
. For this value of
regtype,
cucv must be
.
- NE_INVALID_SCHWEPPE_REG_C
-
On entry,
,
and
. For this value of
regtype,
cucv must be
.
- NE_LSQ_FAIL_CONV
-
The iterations to solve the weighted least squares equations failed to converge.
- NE_NOT_APPEND_FILE
-
Cannot open file for appending.
- NE_NOT_CLOSE_FILE
-
Cannot close file .
- NE_REAL_ARG_LE
-
On entry,
sigma must not be less than or equal to 0.0:
.
On entry,
tol must not be less than or equal to 0.0:
.
- NE_REG_MAT_SINGULAR
-
Failure to invert matrix while calculating covariance.
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
Section 9.
- NE_THETA_ITER_EXCEEDED
-
The number of iterations required to calculate
and
exceeds
max_iter. In this case,
on exit.
- NE_VAR_THETA_LEQ_ZERO
-
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 the 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
p being zero. See
Section 9.
- NE_WT_ITER_EXCEEDED
-
The number of iterations required to calculate the weights exceeds
max_iter. This is only applicable if
.
- NE_WT_LSQ_NOT_FULL_RANK
-
The weighted least squares equations are not of full rank.
7 Accuracy
The precision of the estimates is determined by
tol, see
Section 5. 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.
8 Parallelism and Performance
Not applicable.
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 with
fail set to one of the following values:
10 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_robust_m_regsn_estim (g02hac), , its standard error and are printed. In addition the weight and residual for each observation is printed.
10.1 Program Text
Program Text (g02hace.c)
10.2 Program Data
Program Data (g02hace.d)
10.3 Program Results
Program Results (g02hace.r)