naginterfaces.library.correg.robustm_user¶
- naginterfaces.library.correg.robustm_user(psi, psip0, beta, indw, isigma, x, y, wgt, theta, sigma, chi=None, tol=5e-05, eps=5e-06, maxit=50, nitmon=0, data=None, io_manager=None)[source]¶
robustm_user
performs bounded influence regression (-estimates) using an iterative weighted least squares algorithm.For full information please refer to the NAG Library document for g02hd
https://www.nag.com/numeric/nl/nagdoc_29.2/flhtml/g02/g02hdf.html
- Parameters
- psicallable retval = psi(t, data=None)
must return the value of the weight function for a given value of its argument.
- Parameters
- tfloat
The argument for which must be evaluated.
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- retvalfloat
The value of the weight function evaluated at .
- psip0float
The value of .
- betafloat
If , must specify the value of .
For Huber and Schweppe type regressions, is the th percentile of the standard Normal distribution (see
stat.inv_cdf_normal
).For Mallows type regression is the solution to
where is the standard Normal cumulative distribution function (see
specfun.cdf_normal
).If , must specify the value of .
where is the standard normal density, i.e., .
If , is not referenced.
- indwint
Determines the type of regression to be performed.
Huber type regression.
Mallows type regression.
Schweppe type regression.
- isigmaint
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.
- xfloat, array-like, shape
The values of the matrix, i.e., the independent variables. must contain the th element of , for , for .
If , 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 , 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 .
- wgtfloat, array-like, shape
The weight for the th observation, for .
If , during calculations 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 .
If , the th observation is not included in the analysis.
If , is not referenced.
- 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.
- chiNone or callable retval = chi(t, data=None), optional
Note: if this argument is None then a NAG-supplied facility will be used.
If , must return the value of the weight function for a given value of its argument.
The value of must be non-negative.
- Parameters
- tfloat
The argument for which must be evaluated.
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- retvalfloat
The value of the weight function evaluated at .
- tolfloat, optional
The relative precision for the final estimates. Convergence is assumed when both the relative change in the value of and the relative change in the value of each element of are less than .
It is advisable for to be greater than .
- epsfloat, optional
A relative tolerance to be used to determine the rank of . See
linsys.real_gen_solve
for further details.If or , machine precision will be used in place of .
A reasonable value for is where this value is possible.
- maxitint, optional
The maximum number of iterations that should be used during the estimation.
A value of should be adequate for most uses.
- nitmonint, optional
Determines the amount of information that is printed on each iteration.
No information is printed.
On the first and every iterations the values of , and the change in during the iteration are printed.
When printing occurs the output is directed to the file object associated with the advisory I/O unit (see
FileObjManager
).- dataarbitrary, optional
User-communication data for callback functions.
- 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.
- wgtfloat, ndarray, shape
Unchanged, except as described above.
- thetafloat, ndarray, shape
The M-estimate of , for .
- kint
The column rank of the matrix .
- sigmafloat
The final estimate of if or the value assigned on entry if .
- rsfloat, ndarray, shape
The residuals from the model evaluated at final value of , i.e., contains the vector .
- nitint
The number of iterations that were used during the estimation.
- Raises
- NagValueError
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
Value given by function : .
The value of must be non-negative.
- (errno )
Estimated value of is zero.
- (errno )
Iterations to solve the weighted least squares equations failed to converge.
- (errno )
The function has failed to converge in iterations.
- (errno )
Having removed cases with zero weight, the value of , i.e., no degree of freedom for error. This error will only occur if .
- Warns
- NagAlgorithmicWarning
- (errno )
The weighted least squares equations are not of full rank. This may be due to the matrix not being of full rank, in which case the results will be valid. It may also occur if some of the values become very small or zero, see Further Comments. The rank of the equations is given by . If the matrix just fails the test for nonsingularity then the result = 7 and is possible (see
linsys.real_gen_solve
).
- Notes
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 var ,
robustm_user
calculates the M-estimates given by the solution, , to the equationwhere
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
robustm_wts()
,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
linsys.real_gen_solve
. 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.
robustm_user
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