Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_correg_robustm_user_varmat (g02hf)

## Purpose

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

## Syntax

[c, wk, ifail] = g02hf(psi, psp, indw, indc, sigma, x, rs, wgt, 'n', n, 'm', m)
[c, wk, ifail] = nag_correg_robustm_user_varmat(psi, psp, indw, indc, sigma, x, rs, wgt, 'n', n, 'm', m)

## Description

For a description of bounded influence regression see nag_correg_robustm_user (g02hd). 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 nag_correg_robustm_user_varmat (g02hf):
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$.
nag_correg_robustm_user_varmat (g02hf) 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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{psi}$ – function handle or string containing name of m-file
psi must return the value of the $\psi$ function for a given value of its argument.
[result] = psi(t)

Input Parameters

1:     $\mathrm{t}$ – double scalar
The argument for which psi must be evaluated.

Output Parameters

1:     $\mathrm{result}$ – double scalar
The value of the function $\psi$ evaluated at t.
2:     $\mathrm{psp}$ – function handle or string containing name of m-file
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.
[result] = psp(t)

Input Parameters

1:     $\mathrm{t}$ – double scalar
The argument for which psp must be evaluated.

Output Parameters

1:     $\mathrm{result}$ – double scalar
The value of ${\psi }^{\prime }\left(t\right)$ evaluated at t.
3:     $\mathrm{indw}$int64int32nag_int scalar
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}$int64int32nag_int scalar
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}$ – double scalar
The value of $\stackrel{^}{\sigma }$, as given by nag_correg_robustm_user (g02hd).
Constraint: ${\mathbf{sigma}}>0.0$.
6:     $\mathrm{x}\left(\mathit{ldx},{\mathbf{m}}\right)$ – double array
ldx, the first dimension of the array, must satisfy the constraint $\mathit{ldx}\ge {\mathbf{n}}$.
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$.
7:     $\mathrm{rs}\left({\mathbf{n}}\right)$ – double array
The residuals from the bounded influence regression. These are given by nag_correg_robustm_user (g02hd).
8:     $\mathrm{wgt}\left({\mathbf{n}}\right)$ – double array
If ${\mathbf{indw}}\ne 0$, wgt must contain the vector of weights used by the bounded influence regression. These should be used with nag_correg_robustm_user (g02hd).
If ${\mathbf{indw}}=0$, wgt is not referenced.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the arrays rs, wgt and the first dimension of the array x. (An error is raised if these dimensions are not equal.)
$n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.
2:     $\mathrm{m}$int64int32nag_int scalar
Default: the second dimension of the array x.
$m$, the number of independent variables.
Constraint: $1\le {\mathbf{m}}<{\mathbf{n}}$.

### Output Parameters

1:     $\mathrm{c}\left(\mathit{ldc},{\mathbf{m}}\right)$ – double array
The estimate of the variance-covariance matrix.
2:     $\mathrm{wk}\left({\mathbf{m}}×\left({\mathbf{n}}+{\mathbf{m}}+1\right)+2×{\mathbf{n}}\right)$ – double array
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.
3:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}\le 1$, or ${\mathbf{m}}<1$, or ${\mathbf{n}}\le {\mathbf{m}}$, or $\mathit{ldc}<{\mathbf{m}}$, or $\mathit{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 nag_correg_robustm_user_varmat (g02hf) returns $C$ as ${\left({X}^{\mathrm{T}}X\right)}^{-1}$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

In general, the accuracy of the variance-covariance matrix will depend primarily on the accuracy of the results from nag_correg_robustm_user (g02hd).

nag_correg_robustm_user_varmat (g02hf) 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$.

## 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.
```function g02hf_example

fprintf('g02hf example results\n\n');

x = [1, -1, -1;
1, -1,  1;
1,  1, -1;
1,  1,  1;
1,  0,  3];

rs  = [0.5643;  -1.1286;   0.5643;  -1.1286;   1.1286];
wgt = [0.4039;   0.5012;   0.4039;   0.5012;   0.3862];

% Estimate variance-covariance matrix
indw  = int64(1);
indc  = int64(1);
sigma = 20.7783;
[c, wk, ifail] = g02hf( ...
@psi, @psp, indw, indc, sigma, x, rs, wgt);

disp('Covariance matrix');
disp(c);

function [result] = psi(t)
if t < -1.5
result = -1.5;
elseif abs(t) < 1.5
result = t;
else
result = 1.5;
end;

function [result] = psp(t)
if (abs(t) < 1.5)
result=1;
else
result=0;
end
```
```g02hf example results

Covariance matrix
0.2070         0   -0.0478
0    0.2229         0
-0.0478         0    0.0796

```