G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG02HFF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G02HFF calculates an estimate of the asymptotic variance-covariance matrix for the bounded influence regression estimates (M-estimates). It is intended for use with G02HDF.

## 2  Specification

 SUBROUTINE G02HFF ( PSI, PSP, INDW, INDC, SIGMA, N, M, X, LDX, RS, WGT, C, LDC, WK, IFAIL)
 INTEGER INDW, INDC, N, M, LDX, LDC, IFAIL REAL (KIND=nag_wp) PSI, PSP, SIGMA, X(LDX,M), RS(N), WGT(N), C(LDC,M), WK(M*(N+M+1)+2*N) EXTERNAL PSI, PSP

## 3  Description

For a description of bounded influence regression see G02HDF. Let $\theta$ be the regression arguments and let $C$ be the asymptotic variance-covariance matrix of $\stackrel{^}{\theta }$. Then for Huber type regression
 $C=fHXTX-1σ^2,$
where
 $fH=1n-m ∑i= 1nψ2 ri/σ^ 1n∑ψ′ riσ^ 2 κ2$
 $κ2=1+mn 1n ∑i=1n ψ′ ri/σ^-1n∑i=1nψ′ ri/σ^ 2 1n ∑i=1nψ′ riσ^ 2 ,$
see Huber (1981) and Marazzi (1987).
For Mallows and Schweppe type regressions, $C$ is of the form
 $σ^n2S1-1S2S1-1,$
where ${S}_{1}=\frac{1}{n}{X}^{\mathrm{T}}DX$ and ${S}_{2}=\frac{1}{n}{X}^{\mathrm{T}}PX$.
$D$ is a diagonal matrix such that the $i$th element approximates $E\left({\psi }^{\prime }\left({r}_{i}/\left(\sigma {w}_{i}\right)\right)\right)$ in the Schweppe case and $E\left({\psi }^{\prime }\left({r}_{i}/\sigma \right){w}_{i}\right)$ in the Mallows case.
$P$ is a diagonal matrix such that the $i$th element approximates $E\left({\psi }^{2}\left({r}_{i}/\left(\sigma {w}_{i}\right)\right){w}_{i}^{2}\right)$ in the Schweppe case and $E\left({\psi }^{2}\left({r}_{i}/\sigma \right){w}_{i}^{2}\right)$ in the Mallows case.
Two approximations are available in G02HFF:
1. Average over the ${r}_{i}$
 $Schweppe Mallows Di=1n∑j=1nψ′ rjσ^wi wi Di=1n∑j=1nψ′ rjσ^ wi Pi=1n∑j=1nψ2 rjσ^wi wi2 Pi=1n∑j=1nψ2 rjσ^ wi2$
2. Replace expected value by observed
 $Schweppe Mallows Di=ψ′ riσ ^wi wi Di=ψ′ riσ ^ wi Pi=ψ2 riσ ^wi wi2 Pi=ψ2 riσ ^ wi2$
In all cases $\stackrel{^}{\sigma }$ is a robust estimate of $\sigma$.
G02HFF is based on routines in ROBETH; 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 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:     $\mathrm{PSI}$ – REAL (KIND=nag_wp) FUNCTION, supplied by the user.External Procedure
PSI must return the value of the $\psi$ function for a given value of its argument.
The specification of PSI is:
 FUNCTION PSI ( T)
 REAL (KIND=nag_wp) PSI
 REAL (KIND=nag_wp) T
1:     $\mathrm{T}$ – REAL (KIND=nag_wp)Input
On entry: the argument for which PSI must be evaluated.
PSI must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which G02HFF is called. Arguments denoted as Input must not be changed by this procedure.
2:     $\mathrm{PSP}$ – REAL (KIND=nag_wp) FUNCTION, supplied by the user.External Procedure
PSP must return the value of ${\psi }^{\prime }\left(t\right)=\frac{d}{dt}\psi \left(t\right)$ for a given value of its argument.
The specification of PSP is:
 FUNCTION PSP ( T)
 REAL (KIND=nag_wp) PSP
 REAL (KIND=nag_wp) T
1:     $\mathrm{T}$ – REAL (KIND=nag_wp)Input
On entry: the argument for which PSP must be evaluated.
PSP must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which G02HFF is called. Arguments denoted as Input must not be changed by this procedure.
3:     $\mathrm{INDW}$ – INTEGERInput
On entry: the type of regression for which the asymptotic variance-covariance matrix is to be calculated.
${\mathbf{INDW}}<0$
Mallows type regression.
${\mathbf{INDW}}=0$
Huber type regression.
${\mathbf{INDW}}>0$
Schweppe type regression.
4:     $\mathrm{INDC}$ – INTEGERInput
On entry: if ${\mathbf{INDW}}\ne 0$, INDC must specify the approximation to be used.
If ${\mathbf{INDC}}=1$, averaging over residuals.
If ${\mathbf{INDC}}\ne 1$ , replacing expected by observed.
If ${\mathbf{INDW}}=0$, INDC is not referenced.
5:     $\mathrm{SIGMA}$ – REAL (KIND=nag_wp)Input
On entry: the value of $\stackrel{^}{\sigma }$, as given by G02HDF.
Constraint: ${\mathbf{SIGMA}}>0.0$.
6:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{N}}>1$.
7:     $\mathrm{M}$ – INTEGERInput
On entry: $m$, the number of independent variables.
Constraint: $1\le {\mathbf{M}}<{\mathbf{N}}$.
8:     $\mathrm{X}\left({\mathbf{LDX}},{\mathbf{M}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: the values of the $X$ matrix, i.e., the independent variables. ${\mathbf{X}}\left(\mathit{i},\mathit{j}\right)$ must contain the $\mathit{i}\mathit{j}$th element of $X$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,m$.
9:     $\mathrm{LDX}$ – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G02HFF is called.
Constraint: ${\mathbf{LDX}}\ge {\mathbf{N}}$.
10:   $\mathrm{RS}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: the residuals from the bounded influence regression. These are given by G02HDF.
11:   $\mathrm{WGT}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: if ${\mathbf{INDW}}\ne 0$, WGT must contain the vector of weights used by the bounded influence regression. These should be used with G02HDF.
If ${\mathbf{INDW}}=0$, WGT is not referenced.
12:   $\mathrm{C}\left({\mathbf{LDC}},{\mathbf{M}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the estimate of the variance-covariance matrix.
13:   $\mathrm{LDC}$ – INTEGERInput
On entry: the first dimension of the array C as declared in the (sub)program from which G02HFF is called.
Constraint: ${\mathbf{LDC}}\ge {\mathbf{M}}$.
14:   $\mathrm{WK}\left({\mathbf{M}}×\left({\mathbf{N}}+{\mathbf{M}}+1\right)+2×{\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: if ${\mathbf{INDW}}\ne 0$, ${\mathbf{WK}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,n$, will contain the diagonal elements of the matrix $D$ and ${\mathbf{WK}}\left(\mathit{i}\right)$, for $\mathit{i}=n+1,\dots ,2n$, will contain the diagonal elements of matrix $P$.
The rest of the array is used as workspace.
15:   $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{N}}\le 1$, or ${\mathbf{M}}<1$, or ${\mathbf{N}}\le {\mathbf{M}}$, or ${\mathbf{LDC}}<{\mathbf{M}}$, or ${\mathbf{LDX}}<{\mathbf{N}}$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{SIGMA}}\le 0.0$.
${\mathbf{IFAIL}}=3$
If ${\mathbf{INDW}}=0$ then the matrix ${X}^{\mathrm{T}}X$ is either not positive definite, possibly due to rounding errors, or is ill-conditioned.
If ${\mathbf{INDW}}\ne 0$ then the matrix ${S}_{1}$ is singular or almost singular. This may be due to many elements of $D$ being zero.
${\mathbf{IFAIL}}=4$
Either the value of $\frac{1}{n}\sum _{i=1}^{n}{\psi }^{\prime }\left(\frac{{r}_{i}}{\stackrel{^}{\sigma }}\right)=0$,
or $\kappa =0$,
or $\sum _{i=1}^{n}{\psi }^{2}\left(\frac{{r}_{i}}{\stackrel{^}{\sigma }}\right)=0$.
In this situation G02HFF returns $C$ as ${\left({X}^{\mathrm{T}}X\right)}^{-1}$.
${\mathbf{IFAIL}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7  Accuracy

In general, the accuracy of the variance-covariance matrix will depend primarily on the accuracy of the results from G02HDF.

## 8  Parallelism and Performance

G02HFF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02HFF 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.

G02HFF is only for situations in which $X$ has full column rank.
Care has to be taken in the choice of the $\psi$ function since if ${\psi }^{\prime }\left(t\right)=0$ for too wide a range then either the value of ${f}_{H}$ will not exist or too many values of ${D}_{i}$ will be zero and it will not be possible to calculate $C$.

## 10  Example

The asymptotic variance-covariance matrix is calculated for a Schweppe type regression. The values of $X$, $\stackrel{^}{\sigma }$ and the residuals and weights are read in. The averaging over residuals approximation is used.

### 10.1  Program Text

Program Text (g02hffe.f90)

### 10.2  Program Data

Program Data (g02hffe.d)

### 10.3  Program Results

Program Results (g02hffe.r)