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

# Syntax

C#
```public static void g02fa(
int n,
int ip,
int nres,
double[] res,
double[] h,
double rms,
double[,] sres,
out int ifail
)```
Visual Basic
```Public Shared Sub g02fa ( _
n As Integer, _
ip As Integer, _
nres As Integer, _
res As Double(), _
h As Double(), _
rms As Double, _
sres As Double(,), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g02fa(
int n,
int ip,
int nres,
array<double>^ res,
array<double>^ h,
double rms,
array<double,2>^ sres,
[OutAttribute] int% ifail
)```
F#
```static member g02fa :
n : int *
ip : int *
nres : int *
res : float[] *
h : float[] *
rms : float *
sres : float[,] *
ifail : int byref -> unit
```

#### Parameters

n
Type: System..::..Int32
On entry: $n$, the number of observations included in the regression.
Constraint: ${\mathbf{n}}>{\mathbf{ip}}+1$.
ip
Type: System..::..Int32
On entry: $p$, the number of linear parameters estimated in the regression model.
Constraint: ${\mathbf{ip}}\ge 1$.
nres
Type: System..::..Int32
On entry: the number of residuals.
Constraint: $1\le {\mathbf{nres}}\le {\mathbf{n}}$.
res
Type: array<System..::..Double>[]()[][]
An array of size [nres]
On entry: the residuals, ${r}_{i}$.
h
Type: array<System..::..Double>[]()[][]
An array of size [nres]
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}=0,1,\dots ,{\mathbf{nres}}-1$.
rms
Type: System..::..Double
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$.
sres
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, $4$]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{nres}}$
On exit: the standardized residuals and influence statistics.
For the observation with residual, ${r}_{i}$, given in ${\mathbf{res}}\left[i-1\right]$.
${\mathbf{sres}}\left[i-1,0\right]$
Is the internally standardized residual, ${\mathrm{RI}}_{i}$.
${\mathbf{sres}}\left[i-1,1\right]$
Is the externally standardized residual, ${\mathrm{RE}}_{i}$.
${\mathbf{sres}}\left[i-1,2\right]$
Is Cook's $D$ statistic, ${D}_{i}$.
${\mathbf{sres}}\left[i-1,3\right]$
Is Atkinson's $T$ statistic, ${T}_{i}$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

For the general linear regression model
 $y=Xβ+ε,$
 where $y$ is a vector of length $n$ of the dependent variable, $X$ is an $n$ by $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$ by $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 g02da.
g02fa 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:
(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.$
(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-1n-p-RIi2.$
The two measures of influence are:
(i) Cook's $D$
 $Di=1pREi2hi1-hi.$
(ii) Atkinson's $T$
 $Ti=REin-pphi1-hi.$

# References

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

# Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDSRES) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{ip}}<1$, or ${\mathbf{n}}\le {\mathbf{ip}}+1$, or ${\mathbf{nres}}<1$, or ${\mathbf{nres}}>{\mathbf{n}}$, or ${\mathbf{rms}}\le 0.0$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{h}}\left[i-1\right]\le 0.0$ or $\text{}\ge 1.0$, for some $i=1,2,\dots ,{\mathbf{nres}}$.
${\mathbf{ifail}}=3$
 On entry, the value of a residual is too large for the given value of rms.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

Accuracy is sufficient for all practical purposes.

None.

None.

# Example

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.

Example program (C#): g02fae.cs

Example program data: g02fae.d

Example program results: g02fae.r