NAG CL Interface
g07dcc (robust_​1var_​mestim_​wgt)

Settings help

CL Name Style:


1 Purpose

g07dcc computes an M-estimate of location with (optional) simultaneous estimation of scale, where you provide the weight functions.

2 Specification

#include <nag.h>
void  g07dcc (
double (*chi)(double t, Nag_Comm *comm),
double (*psi)(double t, Nag_Comm *comm),
Integer isigma, Integer n, const double x[], double beta, double *theta, double *sigma, Integer maxit, double tol, double rs[], Integer *nit, Nag_Comm *comm, NagError *fail)
The function may be called by the names: g07dcc, nag_univar_robust_1var_mestim_wgt or nag_robust_m_estim_1var_usr.

3 Description

The data consists of a sample of size n, denoted by x1,x2,,xn, drawn from a random variable X.
The xi are assumed to be independent with an unknown distribution function of the form,
F((xi-θ)/σ)  
where θ is a location parameter, and σ is a scale parameter. M-estimators of θ and σ are given by the solution to the following system of equations;
i=1nψ((xi-θ^)/σ^) = 0 i=1nχ((xi-θ^)/σ^) = (n-1)β  
where ψ and χ are user-supplied weight functions, and β is a constant. Optionally the second equation can be omitted and the first equation is solved for θ^ using an assigned value of σ=σc.
The constant β should be chosen so that σ^ is an unbiased estimator when xi, for i=1,2,,n has a Normal distribution. To achieve this the value of β is calculated as:
β=E(χ)=-χ(z)12πexp{-z22}dz  
The values of ψ ( xi-θ^σ^) σ^ are known as the Winsorized residuals.
The equations are solved by a simple iterative procedure, suggested by Huber:
σ^k=1β(n-1) (i=1nχ(xi-θ^k-1σ^k-1)) σ^k-12  
and
θ^k=θ^k- 1+1n i= 1nψ (xi-θ^k- 1σ^k) σ^k  
or
σ^k=σc  
if σ is fixed.
The initial values for θ^ and σ^ may be user-supplied or calculated within g07dbc as the sample median and an estimate of σ based on the median absolute deviation respectively.
g07dcc is based upon function LYHALG within the ROBETH library, 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 estimation of location and scale in ROBETH Cah. Rech. Doc. IUMSP, No. 3 ROB 1 Institut Universitaire de Médecine Sociale et Préventive, Lausanne

5 Arguments

1: chi function, supplied by the user External Function
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 double Input
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 g07dcc you may allocate memory and initialize these pointers with various quantities for use by chi when called from g07dcc (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
Note: chi should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by g07dcc. If your code inadvertently does return any NaNs or infinities, g07dcc is likely to produce unexpected results.
2: psi function, supplied by the user External 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 double Input
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 g07dcc you may allocate memory and initialize these pointers with various quantities for use by psi when called from g07dcc (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
Note: psi should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by g07dcc. If your code inadvertently does return any NaNs or infinities, g07dcc is likely to produce unexpected results.
3: isigma Integer Input
On entry: the value assigned to isigma determines whether σ^ is to be simultaneously estimated.
isigma=0
The estimation of σ^ is bypassed and sigma is set equal to σc.
isigma=1
σ^ is estimated simultaneously.
4: n Integer Input
On entry: n, the number of observations.
Constraint: n>1.
5: x[n] const double Input
On entry: the vector of observations, x1,x2,,xn.
6: beta double Input
On entry: the value of the constant β of the chosen chi function.
Constraint: beta>0.0.
7: theta double * Input/Output
On entry: if sigma>0, theta must be set to the required starting value of the estimate of the location parameter θ^. A reasonable initial value for θ^ will often be the sample mean or median.
On exit: the M-estimate of the location parameter θ^.
8: sigma double * Input/Output
On entry: the role of sigma depends on the value assigned to isigma as follows.
If isigma=1, sigma must be assigned a value which determines the values of the starting points for the calculation of θ^ and σ^. If sigma0.0, g07dcc will determine the starting points of θ^ and σ^. Otherwise, the value assigned to sigma will be taken as the starting point for σ^, and theta must be assigned a relevant value before entry, see above.
If isigma=0, sigma must be assigned a value which determines the values of σc, which is held fixed during the iterations, and the starting value for the calculation of θ^. If sigma0, g07dcc will determine the value of σc as the median absolute deviation adjusted to reduce bias (see g07dac) and the starting point for θ. Otherwise, the value assigned to sigma will be taken as the value of σc and theta must be assigned a relevant value before entry, see above.
On exit: the M-estimate of the scale parameter σ^, if isigma was assigned the value 1 on entry, otherwise sigma will contain the initial fixed value σc.
9: maxit Integer Input
On entry: the maximum number of iterations that should be used during the estimation.
Suggested value: maxit=50.
Constraint: maxit>0.
10: tol double Input
On entry: the relative precision for the final estimates. Convergence is assumed when the increments for theta, and sigma are less than tol×max(1.0,σk-1).
Constraint: tol>0.0.
11: rs[n] double Output
On exit: the Winsorized residuals.
12: nit Integer * Output
On exit: the number of iterations that were used during the estimation.
13: comm Nag_Comm *
The NAG communication argument (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
14: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_FUN_RET_VAL
The chi function returned a negative value: chi=value.
NE_INT
On entry, isigma=value.
Constraint: isigma=0 or 1.
On entry, maxit=value.
Constraint: maxit>0.
On entry, n=value.
Constraint: n>1.
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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL
On entry, beta=value.
Constraint: beta>0.0.
On entry, tol=value.
Constraint: tol>0.0.
NE_REAL_ARRAY_ELEM_CONS
All elements of x are equal.
NE_SIGMA_NEGATIVE
Current estimate of sigma is zero or negative: sigma=value. This error exit is very unlikely, although it may be caused by too large an initial value of sigma.
NE_TOO_MANY_ITER
Number of iterations required exceeds maxit: maxit=value.
NE_ZERO_RESID
All winsorized residuals are zero. This may occur when using the isigma=0 option with a redescending ψ function, i.e., Hampel's piecewise linear function, Andrew's sine wave, and Tukey's biweight.
If the given value of σ is too small, the standardized residuals xi-θ^kσc , will be large and all the residuals may fall into the region for which ψ(t)=0. This may incorrectly terminate the iterations thus making theta and sigma invalid.
Re-enter the function with a larger value of σc or with isigma=1.

7 Accuracy

On successful exit the accuracy of the results is related to the value of tol, see Section 5.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g07dcc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g07dcc 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

Standard forms of the functions ψ and χ are given in Hampel et al. (1986), Huber (1981) and Marazzi (1987). g07dbc calculates M-estimates using some standard forms for ψ and χ.
When you supply the initial values, care has to be taken over the choice of the initial value of σ. If too small a value is chosen then initial values of the standardized residuals xi-θ^kσ will be large. If the redescending ψ functions are used, i.e., ψ=0 if |t|>τ, for some positive constant τ, then these large values are Winsorized as zero. If a sufficient number of the residuals fall into this category then a false solution may be returned, see page 152 of Hampel et al. (1986).

10 Example

The following program reads in a set of data consisting of eleven observations of a variable X.
The psi and chi functions used are Hampel's Piecewise Linear Function and Hubers chi function respectively.
Using the following starting values various estimates of θ and σ are calculated and printed along with the number of iterations used:
  1. (a)g07dcc determined the starting values, σ is estimated simultaneously.
  2. (b)You must supply the starting values, σ is estimated simultaneously.
  3. (c)g07dcc determined the starting values, σ is fixed.
  4. (d)You must supply the starting values, σ is fixed.

10.1 Program Text

Program Text (g07dcce.c)

10.2 Program Data

Program Data (g07dcce.d)

10.3 Program Results

Program Results (g07dcce.r)