# NAG FL Interfaceg02faf (linregm_​stat_​resinf)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g02faf calculates two types of standardized residuals and two measures of influence for a linear regression.

## 2Specification

Fortran Interface
 Subroutine g02faf ( n, ip, nres, res, h, rms, sres,
 Integer, Intent (In) :: n, ip, nres, ldsres Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: res(nres), h(nres), rms Real (Kind=nag_wp), Intent (Inout) :: sres(ldsres,4)
#include <nag.h>
 void g02faf_ (const Integer *n, const Integer *ip, const Integer *nres, const double res[], const double h[], const double *rms, double sres[], const Integer *ldsres, Integer *ifail)
The routine may be called by the names g02faf or nagf_correg_linregm_stat_resinf.

## 3Description

For the general linear regression model
 $y=Xβ+ε,$
 where $y$ is a vector of length $n$ of the dependent variable, $X$ is an $n×p$ matrix of the independent variables, $\beta$ is a vector of length $p$ of unknown parameters, and $\epsilon$ is a vector of length $n$ of unknown random errors such that $\mathrm{var}\epsilon ={\sigma }^{2}I$.
The residuals are given by
 $r=y-y^=y-Xβ^$
and the fitted values, $\stackrel{^}{y}=X\stackrel{^}{\beta }$, can be written as $Hy$ for an $n×n$ matrix $H$. The $i$th diagonal elements of $H$, ${h}_{i}$, give a measure of the influence of the $i$th values of the independent variables on the fitted regression model. The values of $r$ and the ${h}_{i}$ are returned by g02daf.
g02faf calculates statistics which help to indicate if an observation is extreme and having an undue influence on the fit of the regression model. Two types of standardized residual are calculated:
1. (i)The $i$th residual is standardized by its variance when the estimate of ${\sigma }^{2}$, ${s}^{2}$, is calculated from all the data; this is known as internal Studentization.
 $RIi=ris⁢1-hi .$
2. (ii)The $i$th residual is standardized by its variance when the estimate of ${\sigma }^{2}$, ${s}_{-i}^{2}$ is calculated from the data excluding the $i$th observation; this is known as external Studentization.
 $REi=ris-i1-hi =rin-p-1 n-p-RIi2 .$
The two measures of influence are:
1. (i)Cook's $D$
 $Di=1pREi2hi1-hi .$
2. (ii)Atkinson's $T$
 $Ti=|REi| (n-pp) (hi1-hi ) .$
Atkinson A C (1981) Two graphical displays for outlying and influential observations in regression Biometrika 68 13–20
Cook R D and Weisberg S (1982) Residuals and Influence in Regression Chapman and Hall

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the number of observations included in the regression.
Constraint: ${\mathbf{n}}>{\mathbf{ip}}+1$.
2: $\mathbf{ip}$Integer Input
On entry: $p$, the number of linear parameters estimated in the regression model.
Constraint: ${\mathbf{ip}}\ge 1$.
3: $\mathbf{nres}$Integer Input
On entry: the number of residuals.
Constraint: $1\le {\mathbf{nres}}\le {\mathbf{n}}$.
4: $\mathbf{res}\left({\mathbf{nres}}\right)$Real (Kind=nag_wp) array Input
On entry: the residuals, ${r}_{i}$.
5: $\mathbf{h}\left({\mathbf{nres}}\right)$Real (Kind=nag_wp) array Input
On entry: the diagonal elements of $H$, ${h}_{i}$, corresponding to the residuals in res.
Constraint: $0.0<{\mathbf{h}}\left(\mathit{i}\right)<1.0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nres}}$.
6: $\mathbf{rms}$Real (Kind=nag_wp) Input
On entry: the estimate of ${\sigma }^{2}$ based on all $n$ observations, ${s}^{2}$, i.e., the residual mean square.
Constraint: ${\mathbf{rms}}>0.0$.
7: $\mathbf{sres}\left({\mathbf{ldsres}},4\right)$Real (Kind=nag_wp) array Output
On exit: the standardized residuals and influence statistics.
For the observation with residual, ${r}_{i}$, given in ${\mathbf{res}}\left(i\right)$.
${\mathbf{sres}}\left(i,1\right)$
Is the internally standardized residual, ${\mathrm{RI}}_{i}$.
${\mathbf{sres}}\left(i,2\right)$
Is the externally standardized residual, ${\mathrm{RE}}_{i}$.
${\mathbf{sres}}\left(i,3\right)$
Is Cook's $D$ statistic, ${D}_{i}$.
${\mathbf{sres}}\left(i,4\right)$
Is Atkinson's $T$ statistic, ${T}_{i}$.
8: $\mathbf{ldsres}$Integer Input
On entry: the first dimension of the array sres as declared in the (sub)program from which g02faf is called.
Constraint: ${\mathbf{ldsres}}\ge {\mathbf{nres}}$.
9: $\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{ip}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ip}}\ge 1$.
On entry, ${\mathbf{ip}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}-1>{\mathbf{ip}}$.
On entry, ${\mathbf{ldsres}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{nres}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldsres}}\ge {\mathbf{nres}}$.
On entry, ${\mathbf{nres}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nres}}\ge 1$.
On entry, ${\mathbf{nres}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nres}}\le {\mathbf{n}}$.
On entry, ${\mathbf{rms}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{rms}}>0.0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{h}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$.
Constraint: $0.0<{\mathbf{h}}\left(i\right)<1.0$, for all $i$.
${\mathbf{ifail}}=3$
On entry, a value in res is too large for given rms. ${\mathbf{res}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{rms}}=⟨\mathit{\text{value}}⟩$.
${\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

Accuracy is sufficient for all practical purposes.

## 8Parallelism and Performance

g02faf is not threaded in any implementation.

None.

## 10Example

A set of $24$ residuals and ${h}_{i}$ values from a $11$ parameter model fitted to the cloud seeding data considered in Cook and Weisberg (1982) are input and the standardized residuals etc calculated and printed for the first $10$ observations.

### 10.1Program Text

Program Text (g02fafe.f90)

### 10.2Program Data

Program Data (g02fafe.d)

### 10.3Program Results

Program Results (g02fafe.r)