# NAG CL Interfaceg02fac (linregm_​stat_​resinf)

Settings help

CL Name Style:

## 1Purpose

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

## 2Specification

 #include
 void g02fac (Integer n, Integer ip, Integer nres, const double res[], const double h[], double rms, double sres[], NagError *fail)
The function may be called by the names: g02fac, nag_correg_linregm_stat_resinf or nag_regsn_std_resid_influence.

## 3Description

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×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×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 g02dac.
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:
1. (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 .$
2. (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:
1. (a)Cook's $D$
 $D i = 1 p RE i 2 h i 1 - h i$
2. (b)Atkinson's $T$
 $T i = | RE i | ( n-p p ) ( h i 1 - h i ) .$

## 4References

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: number of observations included in the regression, $n$.
Constraint: ${\mathbf{n}}>{\mathbf{ip}}+1$.
2: $\mathbf{ip}$Integer Input
On entry: the number of linear arguments estimated in the regression model, $p$.
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]$const double Input
On entry: the residuals, ${r}_{i}$.
5: $\mathbf{h}\left[{\mathbf{nres}}\right]$const double 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}=0,1,\dots ,{\mathbf{nres}}-1$.
6: $\mathbf{rms}$double 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{nres}}×4\right]$double Output
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\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: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error 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}}⟩$.

## 7Accuracy

Accuracy is sufficient for all practical purposes.

## 8Parallelism and Performance

g02fac is not threaded in any implementation.

None.

## 10Example

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.

### 10.1Program Text

Program Text (g02face.c)

### 10.2Program Data

Program Data (g02face.d)

### 10.3Program Results

Program Results (g02face.r)