NAG FL Interface
g07dbf (robust_​1var_​mestim)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

g07dbf computes an M-estimate of location with (optional) simultaneous estimation of the scale using Huber's algorithm.

2 Specification

Fortran Interface
Subroutine g07dbf ( isigma, n, x, ipsi, c, h1, h2, h3, dchi, theta, sigma, maxit, tol, rs, nit, wrk, ifail)
Integer, Intent (In) :: isigma, n, ipsi, maxit
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: nit
Real (Kind=nag_wp), Intent (In) :: x(n), c, h1, h2, h3, dchi, tol
Real (Kind=nag_wp), Intent (Inout) :: theta, sigma
Real (Kind=nag_wp), Intent (Out) :: rs(n), wrk(n)
C Header Interface
#include <nag.h>
void  g07dbf_ (const Integer *isigma, const Integer *n, const double x[], const Integer *ipsi, const double *c, const double *h1, const double *h2, const double *h3, const double *dchi, double *theta, double *sigma, const Integer *maxit, const double *tol, double rs[], Integer *nit, double wrk[], Integer *ifail)
The routine may be called by the names g07dbf or nagf_univar_robust_1var_mestim.

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 (1)
i=1nχ ((xi-θ^)/σ^)=(n-1)β (2)
where ψ and χ are given functions, and β is a constant, such that σ^ is an unbiased estimator when xi, for i=1,2,,n has a Normal distribution. Optionally, the second equation can be omitted and the first equation is solved for θ^ using an assigned value of σ=σc.
The values of ψ ( xi-θ^σ^) σ^ are known as the Winsorized residuals.
The following functions are available for ψ and χ in g07dbf:
  1. (a)Null Weights
    ψ(t)=t
    χ(t) = t2 2
    Use of these null functions leads to the mean and standard deviation of the data.
  2. (b)Huber's Function
    ψ(t) = max(-c,min(c,t))
    χ(t) = |t|2 2 |t|d
    χ(t) = d2 2 |t|>d
  3. (c)Hampel's Piecewise Linear Function
    ψ h1 , h2 , h3 (t) = - ψ h1 , h2 , h3 (-t)
    ψ h1 , h2 , h3 (t) = t 0 t h1
    ψ h1 , h2 , h3 (t) = h1 h1 t h2
    ψ h1, h2, h3 (t) = h1 (h3-t) / (h3-h2) h2 t h3
    ψ h1 , h2 , h3 (t) = 0 t>h3
    χ(t) = |t|2 2 |t|d
    χ(t) = d2 2 |t|>d
  4. (d)Andrew's Sine Wave Function
    ψ(t) = sint -π t π
    ψ(t)=0 otherwise
    χ(t) = |t|22 |t|d
    χ(t) = d22 |t|>d
  5. (e)Tukey's Bi-weight
    ψ(t) = t (1-t2) 2 |t|1
    ψ(t)=0 otherwise
    χ(t) = |t|22 |t|d
    χ(t) = d22 |t|>d
where c, h1, h2, h3 and d are constants.
Equations (1) and (2) 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+1ni= 1nψ (xi-θ^k- 1σ^k) σ^k  
or
σ^k=σc,   if  σ  is fixed.  
The initial values for θ^ and σ^ may either be user-supplied or calculated within g07dbf as the sample median and an estimate of σ based on the median absolute deviation respectively.
g07dbf is based upon subroutine 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: 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.
2: n Integer Input
On entry: n, the number of observations.
Constraint: n>1.
3: x(n) Real (Kind=nag_wp) array Input
On entry: the vector of observations, x1,x2,,xn.
4: ipsi Integer Input
On entry: which ψ function is to be used.
ipsi=0
ψ(t)=t.
ipsi=1
Huber's function.
ipsi=2
Hampel's piecewise linear function.
ipsi=3
Andrew's sine wave,
ipsi=4
Tukey's bi-weight.
5: c Real (Kind=nag_wp) Input
On entry: if ipsi=1, c must specify the parameter, c, of Huber's ψ function. c is not referenced if ipsi1.
Constraint: if ipsi=1, c>0.0.
6: h1 Real (Kind=nag_wp) Input
7: h2 Real (Kind=nag_wp) Input
8: h3 Real (Kind=nag_wp) Input
On entry: if ipsi=2, h1, h2 and h3 must specify the parameters, h1, h2, and h3, of Hampel's piecewise linear ψ function. h1, h2 and h3 are not referenced if ipsi2.
Constraint: 0h1h2h3 and h3>0.0 if ipsi=2.
9: dchi Real (Kind=nag_wp) Input
On entry: d, the parameter of the χ function. dchi is not referenced if ipsi=0.
Constraint: if ipsi0, dchi>0.0.
10: theta Real (Kind=nag_wp) Input/Output
On entry: if sigma>0 then theta must be set to the required starting value of the estimation 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, θ^.
11: sigma Real (Kind=nag_wp) 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 calculations of θ^ and σ^. If sigma0.0 then g07dbf 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 value before entry, see above;
  • if isigma=0, sigma must be assigned a value which determines the value of σc, which is held fixed during the iterations, and the starting value for the calculation of θ^. If sigma0, g07dbf will determine the value of σc as the median absolute deviation adjusted to reduce bias (see g07daf) 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: contains 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.
12: maxit Integer Input
On entry: the maximum number of iterations that should be used during the estimation.
Suggested value: maxit=50.
Constraint: maxit>0.
13: tol Real (Kind=nag_wp) 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.
14: rs(n) Real (Kind=nag_wp) array Output
On exit: the Winsorized residuals.
15: nit Integer Output
On exit: the number of iterations that were used during the estimation.
16: wrk(n) Real (Kind=nag_wp) array Output
On exit: if sigma0.0 on entry, wrk will contain the n observations in ascending order.
17: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or −1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, ipsi=value.
Constraint: ipsi=0, 1, 2, 3 or 4.
On entry, isigma=value.
Constraint: isigma=0 or 1.
On entry, maxit=value.
Constraint: maxit>0.
On entry, n=value.
Constraint: n>1.
On entry, tol=value.
Constraint: tol>0.0.
ifail=2
On entry, c=value.
Constraint: c>0.0.
On entry, dchi=value.
Constraint: dchi>0.0.
On entry, h1=value, h2=value and h3=value.
Constraint: 0h1h2h3 and h3>0.0.
ifail=3
All elements of x are equal.
ifail=4
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.
ifail=5
Number of iterations required exceeds maxit: maxit=value.
ifail=6
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 routine with a larger value of σc or with isigma=1.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

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.
g07dbf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g07dbf 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

When you supply the initial values, care has to be taken over the choice of the initial value of σ. If too small a value of σ is chosen then initial values of the standardized residuals xi-θ^kσ will be large. If the redescending ψ functions are used, i.e., Hampel's piecewise linear function, Andrew's sine wave, or Tukey's bi-weight, then these large values of the standardized residuals 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.
For this example, Hampel's Piecewise Linear Function is used (ipsi=2), values for h1, h2 and h3 along with d for the χ function, being read from the data file.
Using the following starting values various estimates of θ and σ are calculated and printed along with the number of iterations used:
  1. (a)g07dbf determines the starting values, σ is estimated simultaneously.
  2. (b)You must supply the starting values, σ is estimated simultaneously.
  3. (c)g07dbf determines the starting values, σ is fixed.
  4. (d)You must supply the starting values, σ is fixed.

10.1 Program Text

Program Text (g07dbfe.f90)

10.2 Program Data

Program Data (g07dbfe.d)

10.3 Program Results

Program Results (g07dbfe.r)