naginterfaces.library.correg.robustm¶
- naginterfaces.library.correg.robustm(indw, ipsi, isigma, indc, x, y, cpsi, h1, h2, h3, cucv, dchi, theta, sigma, tol=5e-05, maxit=50, nitmon=0, io_manager=None)[source]¶
robustm
performs bounded influence regression (-estimates). Several standard methods are available.For full information please refer to the NAG Library document for g02ha
https://www.nag.com/numeric/nl/nagdoc_29.3/flhtml/g02/g02haf.html
- Parameters
- indwint
Specifies the type of regression to be performed.
Mallows type regression with Maronna’s proposed weights.
Huber type regression.
Schweppe type regression with Krasker–Welsch weights.
- ipsiint
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.
- isigmaint
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.
- indcint
If , specifies the approximations used in estimating the covariance matrix of .
Averaging over residuals.
Replacing expected by observed.
is not referenced.
- xfloat, array-like, shape
The values of the matrix, i.e., the independent variables. must contain the th element of , for , for .
If , then during calculations the elements of will be transformed as described in Notes.
Before exit the inverse transformation will be applied.
As a result there may be slight differences between the input and the output .
- yfloat, array-like, shape
The data values of the dependent variable.
must contain the value of for the th observation, for .
If , then during calculations the elements of will be transformed as described in Notes.
Before exit the inverse transformation will be applied.
As a result there may be slight differences between the input and the output .
- cpsifloat
If , must specify the parameter, , of Huber’s function.
If on entry, is not referenced.
- h1float
If , , , and must specify the parameters , , and , of Hampel’s piecewise linear function. , , and are not referenced if .
- h2float
If , , , and must specify the parameters , , and , of Hampel’s piecewise linear function. , , and are not referenced if .
- h3float
If , , , and must specify the parameters , , and , of Hampel’s piecewise linear function. , , and are not referenced if .
- cucvfloat
If , must specify the value of the constant, , of the function for Maronna’s proposed weights.
If , must specify the value of the function for the Krasker–Welsch weights.
If , is not referenced.
- dchifloat
, the constant of the function. is not referenced if , or if .
- thetafloat, array-like, shape
Starting values of the parameter vector . These may be obtained from least squares regression. Alternatively if and or if and approximately equals the standard deviation of the dependent variable, , then , for may provide reasonable starting values.
- sigmafloat
A starting value for the estimation of . should be approximately the standard deviation of the residuals from the model evaluated at the value of given by on entry.
- tolfloat, optional
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 .
If and , is also used to determine the precision of .
It is advisable for to be greater than .
- maxitint, optional
The maximum number of iterations that should be used in the calculation of (if ), and of the estimates of and , and of (if and ).
A value of should be adequate for most uses.
- nitmonint, optional
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 Notes).
When printing occurs the output is directed to the file object associated with the advisory I/O unit (see
FileObjManager
).- io_managerFileObjManager, optional
Manager for I/O in this routine.
- Returns
- xfloat, ndarray, shape
Unchanged, except as described above.
- yfloat, ndarray, shape
Unchanged, except as described above.
- thetafloat, ndarray, shape
contains the M-estimate of , for .
- sigmafloat
Contains the final estimate of if or the value assigned on entry if .
- cfloat, ndarray, shape
The diagonal elements of contain the estimated asymptotic standard errors of the estimates of , i.e., contains the estimated asymptotic standard error of the estimate contained in .
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 .
- rsfloat, ndarray, shape
The residuals from the model evaluated at final value of , i.e., contains the vector .
- wgtfloat, ndarray, shape
The vector of weights. contains the weight for the th observation, for .
- statfloat, ndarray, shape
The following values are assigned to :
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.
- Raises
- NagValueError
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry: .
Constraint: , , , or .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry: , , incorrectly set.
Constraint: and .
- (errno )
On entry: .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
The number of iterations required to calculate the weights exceeds . (Only if .)
- (errno )
The number of iterations required to calculate exceeds . (Only if and .)
- (errno )
Iterations to calculate estimates of failed to converge in iterations: .
- (errno )
The number of iterations required to calculate and exceeds .
- (errno )
Error degrees of freedom , where and the rank of , .
- (errno )
Estimated value of is zero.
- Warns
- NagAlgorithmicWarning
- (errno )
Weighted least squares equations not of full rank: rank .
- (errno )
Failure to invert matrix while calculating covariance.
- (errno )
Factor for covariance matrix , uncorrected given.
- (errno )
Variance of an element of , correlations set to .
- Notes
In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.
For the linear regression model
where
is a vector of length of the dependent variable,
is an matrix of independent variables of column rank ,
is a vector of length of unknown parameters,
and
is a vector of length of unknown errors with ,
robustm
calculates the M-estimates given by the solution, , to the equationwhere
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 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 Section 3 of Marazzi (1987a)).
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 (see
specfun.cdf_normal
).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 solving the associated least squares problem. If is of full column rank then an orthogonal-triangular () decomposition is used; if not, a singular value decomposition is used.
The following functions are available for and in
robustm
.Unit Weights
This gives least squares regression.
Huber’s Function
Hampel’s Piecewise Linear Function
Andrew’s Sine Wave Function
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 an lower triangular matrix,
and
is a suitable function.
The weights are then calculated as
for a suitable function .
robustm
finds using the iterative procedurewhere ,
and
and and are bounds set at .
Two weights are available in
robustm
: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.
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
See Huber (1981) and Marazzi (1987b).
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
robustm
:Average over the
Replace expected value by observed
See Hampel et al. (1986) and Marazzi (1987b).
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.
robustm
is based on routines in ROBETH; see Marazzi (1987a).
- 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, 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, 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