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β + ε, $y=Xβ+ε,$
 where y$y$ is a vector of length n$n$ of the dependent variable, X$X$ is an n$n$ by p$p$ matrix of the independent variables, β$\beta$ is a vector of length p$p$ of unknown parameters, and ε$\epsilon$ is a vector of length n$n$ of unknown random errors such that varε = σ2I$\mathrm{var}\epsilon ={\sigma }^{2}I$.
The residuals are given by
 r = y − ŷ = y − Xβ̂ $r=y-y^=y-Xβ^$
and the fitted values, = Xβ̂$\stackrel{^}{y}=X\stackrel{^}{\beta }$, can be written as Hy$Hy$ for an n$n$ by n$n$ matrix H$H$. The i$i$th diagonal elements of H$H$, hi${h}_{i}$, give a measure of the influence of the i$i$th values of the independent variables on the fitted regression model. The values of r$r$ and the hi${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$i$th residual is standardized by its variance when the estimate of σ2${\sigma }^{2}$, s2${s}^{2}$, is calculated from all the data; this is known as internal Studentization.
 RIi = (ri)/(s×sqrt(1 − hi)). $RIi=ris⁢1-hi .$
(ii) The i$i$th residual is standardized by its variance when the estimate of σ2${\sigma }^{2}$, si2${s}_{-i}^{2}$ is calculated from the data excluding the i$i$th observation; this is known as external Studentization.
 REi = (ri)/(s − isqrt(1 − hi)) = risqrt((n − p − 1)/(n − p − RIi2)). $REi=ris-i1-hi =rin-p-1 n-p-RIi2 .$
The two measures of influence are:
(i) Cook's D$D$
 Di = 1/pREi2(hi)/(1 − hi). $Di=1pREi2hi1-hi .$
(ii) Atkinson's T$T$
 Ti = |REi|sqrt( ((n − p)/p) ((hi)/(1 − hi)) ). $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:     n – int64int32nag_int scalar
n$n$, the number of observations included in the regression.
Constraint: n > ip + 1${\mathbf{n}}>{\mathbf{ip}}+1$.
2:     ip – int64int32nag_int scalar
p$p$, the number of linear parameters estimated in the regression model.
Constraint: ip1${\mathbf{ip}}\ge 1$.
3:     res(nres) – double array
nres, the dimension of the array, must satisfy the constraint 1nresn$1\le {\mathbf{nres}}\le {\mathbf{n}}$.
The residuals, ri${r}_{i}$.
4:     h(nres) – double array
nres, the dimension of the array, must satisfy the constraint 1nresn$1\le {\mathbf{nres}}\le {\mathbf{n}}$.
The diagonal elements of H$H$, hi${h}_{i}$, corresponding to the residuals in res.
Constraint: 0.0 < h(i) < 1.0$0.0<{\mathbf{h}}\left(\mathit{i}\right)<1.0$, for i = 1,2,,nres$\mathit{i}=1,2,\dots ,{\mathbf{nres}}$.
5:     rms – double scalar
The estimate of σ2${\sigma }^{2}$ based on all n$n$ observations, s2${s}^{2}$, i.e., the residual mean square.
Constraint: rms > 0.0${\mathbf{rms}}>0.0$.

### Optional Input Parameters

1:     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: 1nresn$1\le {\mathbf{nres}}\le {\mathbf{n}}$.

ldsres

### Output Parameters

1:     sres(ldsres,4$4$) – double array
ldsresnres$\mathit{ldsres}\ge {\mathbf{nres}}$.
The standardized residuals and influence statistics.
For the observation with residual, ri${r}_{i}$, given in res(i)${\mathbf{res}}\left(i\right)$.
sres(i,1)${\mathbf{sres}}\left(i,1\right)$
Is the internally standardized residual, RIi${\mathrm{RI}}_{i}$.
sres(i,2)${\mathbf{sres}}\left(i,2\right)$
Is the externally standardized residual, REi${\mathrm{RE}}_{i}$.
sres(i,3)${\mathbf{sres}}\left(i,3\right)$
Is Cook's D$D$ statistic, Di${D}_{i}$.
sres(i,4)${\mathbf{sres}}\left(i,4\right)$
Is Atkinson's T$T$ statistic, Ti${T}_{i}$.
2:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, ip < 1${\mathbf{ip}}<1$, or n ≤ ip + 1${\mathbf{n}}\le {\mathbf{ip}}+1$, or nres < 1${\mathbf{nres}}<1$, or ${\mathbf{nres}}>{\mathbf{n}}$, or ldsres < nres$\mathit{ldsres}<{\mathbf{nres}}$, or rms ≤ 0.0${\mathbf{rms}}\le 0.0$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, h(i) ≤ 0.0${\mathbf{h}}\left(i\right)\le 0.0$ or ≥ 1.0$\text{}\ge 1.0$, for some i = 1,2, … ,nres$i=1,2,\dots ,{\mathbf{nres}}$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, the value of a residual is too large for the given value of rms.

## Accuracy

Accuracy is sufficient for all practical purposes.

None.

## Example

```function nag_correg_linregm_stat_resinf_example
n = int64(24);
ip = int64(11);
res = [0.266;
-0.1387;
-0.2971;
0.5926;
-0.4013;
0.1396;
-1.3173;
1.1226;
0.0321;
-0.7111];
h = [0.5519;
0.9746;
0.6256;
0.3144;
0.4106;
0.6268;
0.5479;
0.2325;
0.4115;
0.3577];
rms = 0.5798;
[sres, ifail] = nag_correg_linregm_stat_resinf(n, ip, res, h, rms)
```
```

sres =

0.5219    0.5067    0.0305    0.6113
-1.1429   -1.1578    4.5566   -7.7966
-0.6377   -0.6225    0.0618   -0.8747
0.9399    0.9354    0.0368    0.6886
-0.6865   -0.6718    0.0298   -0.6096
0.3001    0.2893    0.0138    0.4076
-2.5729   -3.5286    0.7293   -4.2230
1.6829    1.8282    0.0780    1.0939
0.0550    0.0528    0.0002    0.0480
-1.1653   -1.1830    0.0687   -0.9598

ifail =

0

```
```function g02fa_example
n = int64(24);
ip = int64(11);
res = [0.266;
-0.1387;
-0.2971;
0.5926;
-0.4013;
0.1396;
-1.3173;
1.1226;
0.0321;
-0.7111];
h = [0.5519;
0.9746;
0.6256;
0.3144;
0.4106;
0.6268;
0.5479;
0.2325;
0.4115;
0.3577];
rms = 0.5798;
[sres, ifail] = g02fa(n, ip, res, h, rms)
```
```

sres =

0.5219    0.5067    0.0305    0.6113
-1.1429   -1.1578    4.5566   -7.7966
-0.6377   -0.6225    0.0618   -0.8747
0.9399    0.9354    0.0368    0.6886
-0.6865   -0.6718    0.0298   -0.6096
0.3001    0.2893    0.0138    0.4076
-2.5729   -3.5286    0.7293   -4.2230
1.6829    1.8282    0.0780    1.0939
0.0550    0.0528    0.0002    0.0480
-1.1653   -1.1830    0.0687   -0.9598

ifail =

0

```