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_linregm_stat_resinf (g02fa)

## Purpose

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

## Syntax

[sres, ifail] = g02fa(n, ip, res, h, rms, 'nres', nres)
[sres, ifail] = nag_correg_linregm_stat_resinf(n, ip, res, h, rms, 'nres', nres)

## 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 arguments, 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 nag_correg_linregm_fit (g02da).
nag_correg_linregm_stat_resinf (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-1 n-p-RIi2 .$
The two measures of influence are:
(i) Cook's $D$
 $Di=1pREi2hi1-hi .$
(ii) Atkinson's $T$
 $Ti=REi n-pp hi1-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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
$n$, the number of observations included in the regression.
Constraint: ${\mathbf{n}}>{\mathbf{ip}}+1$.
2:     $\mathrm{ip}$int64int32nag_int scalar
$p$, the number of linear arguments estimated in the regression model.
Constraint: ${\mathbf{ip}}\ge 1$.
3:     $\mathrm{res}\left({\mathbf{nres}}\right)$ – double array
The residuals, ${r}_{i}$.
4:     $\mathrm{h}\left({\mathbf{nres}}\right)$ – double array
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}}$.
5:     $\mathrm{rms}$ – double scalar
The estimate of ${\sigma }^{2}$ based on all $n$ observations, ${s}^{2}$, i.e., the residual mean square.
Constraint: ${\mathbf{rms}}>0.0$.

### Optional Input Parameters

1:     $\mathrm{nres}$int64int32nag_int scalar
Default: the dimension of the arrays res, h. (An error is raised if these dimensions are not equal.)
The number of residuals.
Constraint: $1\le {\mathbf{nres}}\le {\mathbf{n}}$.

### Output Parameters

1:     $\mathrm{sres}\left(\mathit{ldsres},4\right)$ – double array
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}$.
2:     $\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{ip}}<1$, or ${\mathbf{n}}\le {\mathbf{ip}}+1$, or ${\mathbf{nres}}<1$, or ${\mathbf{nres}}>{\mathbf{n}}$, or $\mathit{ldsres}<{\mathbf{nres}}$, or ${\mathbf{rms}}\le 0.0$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{h}}\left(i\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}}=-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

Accuracy is sufficient for all practical purposes.

None.

## Example

A set of $24$ residuals and ${h}_{i}$ values from a $11$ argument 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.
```function g02fa_example

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

res = [ 0.2660  -0.1387  -0.2971   0.5926  -0.4013   0.1396 ...
-1.3173   1.1226   0.0321  -0.7111   0.3439  -0.4379 ...
0.0633  -0.0936   0.9968   0.0209  -0.4056   0.1396 ...
0.0327   0.2970  -0.2277   0.5180   0.5301  -1.0650 ];

h   = [ 0.5519   0.9746   0.6256   0.3144   0.4106   0.6268 ...
0.5479   0.2325   0.4115   0.3577   0.3342   0.1673 ...
0.3874   0.1705   0.3466   0.3743   0.7527   0.9069 ...
0.2610   0.6256   0.2485   0.3072   0.5848   0.4794 ];

n  = int64(numel(res));
ip = int64(11);
rms  = 0.5798;

% Calculate standardised residuals
[sres, ifail] = g02fa( ...
n, ip, res, h, rms);

% Display results
fprintf('        Internally    Internally\n');
fprintf('Obs.   standardized  standardized   Cook''s D   Atkinson''s T\n');
fprintf('         residuals     residuals\n\n');
for j = 1:ip-1
fprintf('%2d%13.3f%13.3f%13.3f%13.3f\n',j,sres(j,1:4))
end

```
```g02fa example results

Internally    Internally
Obs.   standardized  standardized   Cook's D   Atkinson's T
residuals     residuals

1        0.522        0.507        0.030        0.611
2       -1.143       -1.158        4.557       -7.797
3       -0.638       -0.622        0.062       -0.875
4        0.940        0.935        0.037        0.689
5       -0.686       -0.672        0.030       -0.610
6        0.300        0.289        0.014        0.408
7       -2.573       -3.529        0.729       -4.223
8        1.683        1.828        0.078        1.094
9        0.055        0.053        0.000        0.048
10       -1.165       -1.183        0.069       -0.960
```