g02 Chapter Contents
g02 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_robust_m_regsn_param_var (g02hfc)

## 1  Purpose

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

## 2  Specification

 #include #include
void  nag_robust_m_regsn_param_var (Nag_OrderType order,
 double (*psi)(double t, Nag_Comm *comm),
 double (*psp)(double t, Nag_Comm *comm),
Nag_RegType regtype, Nag_CovMatrixEst covmat_est, double sigma, Integer n, Integer m, const double x[], Integer pdx, const double rs[], const double wgt[], double cov[], Integer pdc, double comm_arr[], Nag_Comm *comm, NagError *fail)

## 3  Description

For a description of bounded influence regression see nag_robust_m_regsn_user_fn (g02hdc). 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_robust_m_regsn_param_var (g02hfc):
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_robust_m_regsn_param_var (g02hfc) 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:    $\mathbf{order}$Nag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 2.3.1.3 in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2:    $\mathbf{psi}$function, supplied by the userExternal Function
psi must return the value of the $\psi$ function for a given value of its argument.
The specification of psi is:
 double psi (double t, Nag_Comm *comm)
1:    $\mathbf{t}$doubleInput
On entry: the argument for which psi must be evaluated.
2:    $\mathbf{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 nag_robust_m_regsn_param_var (g02hfc) you may allocate memory and initialize these pointers with various quantities for use by psi when called from nag_robust_m_regsn_param_var (g02hfc) (see Section 2.3.1.1 in How to Use the NAG Library and its Documentation).
3:    $\mathbf{psp}$function, supplied by the userExternal Function
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:
 double psp (double t, Nag_Comm *comm)
1:    $\mathbf{t}$doubleInput
On entry: the argument for which psp must be evaluated.
2:    $\mathbf{comm}$Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to psp.
userdouble *
iuserInteger *
pPointer
The type Pointer will be void *. Before calling nag_robust_m_regsn_param_var (g02hfc) you may allocate memory and initialize these pointers with various quantities for use by psp when called from nag_robust_m_regsn_param_var (g02hfc) (see Section 2.3.1.1 in How to Use the NAG Library and its Documentation).
4:    $\mathbf{regtype}$Nag_RegTypeInput
On entry: the type of regression for which the asymptotic variance-covariance matrix is to be calculated.
${\mathbf{regtype}}=\mathrm{Nag_MallowsReg}$
Mallows type regression.
${\mathbf{regtype}}=\mathrm{Nag_HuberReg}$
Huber type regression.
${\mathbf{regtype}}=\mathrm{Nag_SchweppeReg}$
Schweppe type regression.
Constraint: ${\mathbf{regtype}}=\mathrm{Nag_MallowsReg}$, $\mathrm{Nag_HuberReg}$ or $\mathrm{Nag_SchweppeReg}$.
5:    $\mathbf{covmat_est}$Nag_CovMatrixEstInput
On entry: if ${\mathbf{regtype}}\ne \mathrm{Nag_HuberReg}$, covmat_est must specify the approximation to be used.
If ${\mathbf{covmat_est}}=\mathrm{Nag_CovMatAve}$, averaging over residuals.
If ${\mathbf{covmat_est}}=\mathrm{Nag_CovMatObs}$, replacing expected by observed.
If ${\mathbf{regtype}}=\mathrm{Nag_HuberReg}$, covmat_est is not referenced.
Constraint: ${\mathbf{covmat_est}}=\mathrm{Nag_CovMatAve}$ or $\mathrm{Nag_CovMatObs}$.
6:    $\mathbf{sigma}$doubleInput
On entry: the value of $\stackrel{^}{\sigma }$, as given by nag_robust_m_regsn_user_fn (g02hdc).
Constraint: ${\mathbf{sigma}}>0.0$.
7:    $\mathbf{n}$IntegerInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.
8:    $\mathbf{m}$IntegerInput
On entry: $m$, the number of independent variables.
Constraint: $1\le {\mathbf{m}}<{\mathbf{n}}$.
9:    $\mathbf{x}\left[\mathit{dim}\right]$const doubleInput
Note: the dimension, dim, of the array x must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdx}}×{\mathbf{m}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×{\mathbf{pdx}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
Where ${\mathbf{X}}\left(i,j\right)$ appears in this document, it refers to the array element
• ${\mathbf{x}}\left[\left(j-1\right)×{\mathbf{pdx}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{x}}\left[\left(i-1\right)×{\mathbf{pdx}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
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$.
10:  $\mathbf{pdx}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array x.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdx}}\ge {\mathbf{n}}$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdx}}\ge {\mathbf{m}}$.
11:  $\mathbf{rs}\left[{\mathbf{n}}\right]$const doubleInput
On entry: the residuals from the bounded influence regression. These are given by nag_robust_m_regsn_user_fn (g02hdc).
12:  $\mathbf{wgt}\left[{\mathbf{n}}\right]$const doubleInput
On entry: if ${\mathbf{regtype}}\ne \mathrm{Nag_HuberReg}$, wgt must contain the vector of weights used by the bounded influence regression. These should be used with nag_robust_m_regsn_user_fn (g02hdc).
If ${\mathbf{regtype}}=\mathrm{Nag_HuberReg}$, wgt is not referenced.
13:  $\mathbf{cov}\left[\mathit{dim}\right]$doubleOutput
Note: the dimension, dim, of the array cov must be at least ${\mathbf{pdc}}×{\mathbf{m}}$.
The $\left(i,j\right)$th element of the matrix is stored in
• ${\mathbf{cov}}\left[\left(j-1\right)×{\mathbf{pdc}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{cov}}\left[\left(i-1\right)×{\mathbf{pdc}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On exit: the estimate of the variance-covariance matrix.
14:  $\mathbf{pdc}$IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array cov.
Constraint: ${\mathbf{pdc}}\ge {\mathbf{m}}$.
15:  $\mathbf{comm_arr}\left[\mathit{dim}\right]$doubleOutput
Note: the dimension, dim, of the array comm_arr must be at least ${\mathbf{m}}×\left({\mathbf{n}}+{\mathbf{m}}+1\right)+2×{\mathbf{n}}$.
On exit: if ${\mathbf{regtype}}\ne \mathrm{Nag_HuberReg}$, ${\mathbf{comm_arr}}\left[\mathit{i}-1\right]$, for $\mathit{i}=1,2,\dots ,n$, will contain the diagonal elements of the matrix $D$ and ${\mathbf{comm_arr}}\left[\mathit{i}-1\right]$, for $\mathit{i}=n+1,\dots ,2n$, will contain the diagonal elements of matrix $P$.
16:  $\mathbf{comm}$Nag_Comm *
The NAG communication argument (see Section 2.3.1.1 in How to Use the NAG Library and its Documentation).
17:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_CORRECTION_FACTOR
Correction factor = 0 (Huber type regression).
NE_INT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}>1$.
On entry, ${\mathbf{pdc}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdc}}>0$.
On entry, ${\mathbf{pdx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdx}}>0$.
NE_INT_2
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: $1\le {\mathbf{m}}<{\mathbf{n}}$.
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$ and ${\mathbf{pdc}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdc}}\ge {\mathbf{m}}$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}>{\mathbf{m}}$.
On entry, ${\mathbf{pdc}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdc}}\ge {\mathbf{m}}$.
On entry, ${\mathbf{pdx}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdx}}\ge {\mathbf{m}}$.
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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_POS_DEF
${X}^{\mathrm{T}}X$ matrix not positive definite.
NE_REAL
On entry, ${\mathbf{sigma}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{sigma}}\ge 0.0$.
NE_SINGULAR
${S}_{1}$ matrix is singular or almost singular.

## 7  Accuracy

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

## 8  Parallelism and Performance

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

nag_robust_m_regsn_param_var (g02hfc) 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 (g02hfce.c)

### 10.2  Program Data

Program Data (g02hfce.d)

### 10.3  Program Results

Program Results (g02hfce.r)