# NAG FL Interfaceg02hff (robustm_​user_​varmat)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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.

## 2Specification

Fortran Interface
 Subroutine g02hff ( psi, psp, indw, indc, n, m, x, ldx, rs, wgt, c, ldc, wk,
 Integer, Intent (In) :: indw, indc, n, m, ldx, ldc Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), External :: psi, psp Real (Kind=nag_wp), Intent (In) :: sigma, x(ldx,m), rs(n), wgt(n) Real (Kind=nag_wp), Intent (Inout) :: c(ldc,m) Real (Kind=nag_wp), Intent (Out) :: wk(m*(n+m+1)+2*n)
#include <nag.h>
 void g02hff_ (double (NAG_CALL *psi)(const double *t),double (NAG_CALL *psp)(const double *t),const Integer *indw, const Integer *indc, const double *sigma, const Integer *n, const Integer *m, const double x[], const Integer *ldx, const double rs[], const double wgt[], double c[], const Integer *ldc, double wk[], Integer *ifail)
The routine may be called by the names g02hff or nagf_correg_robustm_user_varmat.

## 3Description

For a description of bounded influence regression see g02hdf. Let $\theta$ be the regression parameters and let $C$ be the asymptotic variance-covariance matrix of $\stackrel{^}{\theta }$. Then for Huber type regression
 $C=fH(XTX)−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. 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. 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).

## 4References

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

## 5Arguments

1: $\mathbf{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:
Fortran Interface
 Function psi ( t)
 Real (Kind=nag_wp) :: psi Real (Kind=nag_wp), Intent (In) :: t
 double psi (const double *t)
1: $\mathbf{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.
Note: psi should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by g02hff. If your code inadvertently does return any NaNs or infinities, g02hff is likely to produce unexpected results.
2: $\mathbf{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:
Fortran Interface
 Function psp ( t)
 Real (Kind=nag_wp) :: psp Real (Kind=nag_wp), Intent (In) :: t
 double psp (const double *t)
1: $\mathbf{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.
Note: psp should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by g02hff. If your code inadvertently does return any NaNs or infinities, g02hff is likely to produce unexpected results.
3: $\mathbf{indw}$Integer Input
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: $\mathbf{indc}$Integer Input
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: $\mathbf{sigma}$Real (Kind=nag_wp) Input
On entry: the value of $\stackrel{^}{\sigma }$, as given by g02hdf.
Constraint: ${\mathbf{sigma}}>0.0$.
6: $\mathbf{n}$Integer Input
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.
7: $\mathbf{m}$Integer Input
On entry: $m$, the number of independent variables.
Constraint: $1\le {\mathbf{m}}<{\mathbf{n}}$.
8: $\mathbf{x}\left({\mathbf{ldx}},{\mathbf{m}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{ldx}$Integer Input
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: $\mathbf{rs}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the residuals from the bounded influence regression. These are given by g02hdf.
11: $\mathbf{wgt}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{c}\left({\mathbf{ldc}},{\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
On exit: the estimate of the variance-covariance matrix.
13: $\mathbf{ldc}$Integer Input
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: $\mathbf{wk}\left({\mathbf{m}}×\left({\mathbf{n}}+{\mathbf{m}}+1\right)+2×{\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{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 $-\mathbf{1}$ 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).

## 6Error 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{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ldc}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldc}}\ge {\mathbf{m}}$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 2$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ldx}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldx}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}>{\mathbf{m}}$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{sigma}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{sigma}}\ge 0.0$.
${\mathbf{ifail}}=3$
${S}_{1}$ matrix is singular or almost singular.
${X}^{\mathrm{T}}X$ matrix not positive definite.
${\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 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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

## 8Parallelism 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$.

## 10Example

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.1Program Text

Program Text (g02hffe.f90)

### 10.2Program Data

Program Data (g02hffe.d)

### 10.3Program Results

Program Results (g02hffe.r)