g02 Chapter Contents
g02 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_regsn_std_resid_influence (g02fac)

## 1  Purpose

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

## 2  Specification

 #include #include
 void nag_regsn_std_resid_influence (Integer n, Integer ip, Integer nres, const double res[], const double h[], double rms, double sres[], NagError *fail)

## 3  Description

For the general linear regression model is defined by
 $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 β ^ .$
The fitted values, $\stackrel{^}{y}=X\stackrel{^}{\beta }$, can be written as $Hy$ for an $n$ by $n$ matrix $H$. The $i$th diagonal element of $H$, ${h}_{i}$, gives a measure of the influence of the $i$th value of the independent variables on the fitted regression model. The values of $r$ and the ${h}_{i}$ are returned by nag_regsn_mult_linear (g02dac).
nag_regsn_std_resid_influence (g02fac) 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:
(a) The $i$th residual is standardized by its variance when the estimate of ${\sigma }^{2}$, ${s}^{2}$, is calculated from all the data; known as internal studentization.
 $RI i = r i s 1 - h i .$
(b) 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; known as external studentization.
 $RE i = r i s -i 1 - h i = r i n-p - 1 n - p - R I i 2 .$
The two measures of influence are:
(a) Cook's $D$
 $D i = 1 p RE i 2 h i 1 - h i$
(b) Atkinson's $T$
 $T i = RE i n-p p h i 1 - h i .$

## 4  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

## 5  Arguments

1:     nIntegerInput
On entry: number of observations included in the regression, $n$.
Constraint: ${\mathbf{n}}>{\mathbf{ip}}+1$.
2:     ipIntegerInput
On entry: the number of linear arguments estimated in the regression model, $p$.
Constraint: ${\mathbf{ip}}\ge 1$.
3:     nresIntegerInput
On entry: the number of residuals.
Constraint: $1\le {\mathbf{nres}}\le {\mathbf{n}}$.
4:     res[nres]const doubleInput
On entry: the residuals, ${r}_{i}$.
5:     h[nres]const doubleInput
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$.
6:     rmsdoubleInput
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:     sres[${\mathbf{nres}}×4$]doubleOutput
On exit: the standardized residuals and influence statistics.
For the observation with residual given in ${\mathbf{res}}\left[i\right]$:
• ${\mathbf{sres}}\left[\left(i\right)×4+0\right]$ is the internally studentized residual
• ${\mathbf{sres}}\left[\left(i\right)×4+1\right]$ is the externally studentized residual
• ${\mathbf{sres}}\left[\left(i\right)×4+2\right]$ is Cook's $D$ statistic
• ${\mathbf{sres}}\left[\left(i\right)×4+3\right]$ is Atkinson's $T$ statistic.
8:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_INT_ARG_GT
On entry, ${\mathbf{nres}}=〈\mathit{\text{value}}〉$ while ${\mathbf{n}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{nres}}\ge {\mathbf{n}}$.
NE_2_INT_ARG_LE
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ while ${\mathbf{ip}}+1=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{n}}>{\mathbf{ip}}+1$.
NE_INT_ARG_LT
On entry, ${\mathbf{ip}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ip}}\ge 1$.
On entry, ${\mathbf{nres}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nres}}\ge 1$.
NE_REAL_ARG_GE
On entry, ${\mathbf{h}}\left[〈\mathit{\text{value}}〉\right]$ must not be greater than or equal to 1.0: ${\mathbf{h}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
NE_REAL_ARG_LE
On entry, ${\mathbf{h}}\left[〈\mathit{\text{value}}〉\right]$ must not be less than or equal to 0.0: ${\mathbf{h}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
On entry, rms must not be less than or equal to 0.0: ${\mathbf{rms}}=〈\mathit{\text{value}}〉$.
NE_RESID_LARG
On entry, the value of a residual is too large for the given value of rms: ${\mathbf{res}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, ${\mathbf{rms}}=〈\mathit{\text{value}}〉$.

## 7  Accuracy

Accuracy is sufficient for all practical purposes.

None.

## 9  Example

A set of 24 residuals and ${h}_{i}$ values from an 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.

### 9.1  Program Text

Program Text (g02face.c)

### 9.2  Program Data

Program Data (g02face.d)

### 9.3  Program Results

Program Results (g02face.r)