NAG Library Function Document

nag_regsn_std_resid_influence (g02fac)


    1  Purpose
    7  Accuracy


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


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


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,
  β is a vector of length p  of unknown arguments,
and ε is a vector of length n  of unknown random errors such that varε = σ 2 I .
The residuals are given by
r = y - y ^ = y - X β ^ .  
The fitted values, y ^ = X β ^ , 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 σ 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 σ 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 .  


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


1:     n IntegerInput
On entry: number of observations included in the regression, n .
Constraint: n > ip + 1 .
2:     ip IntegerInput
On entry: the number of linear arguments estimated in the regression model, p .
Constraint: ip1 .
3:     nres IntegerInput
On entry: the number of residuals.
Constraint: 1 nres 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 < h[i] < 1.0 , for i=0,1,,nres - 1.
6:     rms doubleInput
On entry: the estimate of σ 2  based on all n  observations, s 2 , i.e., the residual mean square.
Constraint: rms>0.0 .
7:     sres[nres×4] doubleOutput
On exit: the standardized residuals and influence statistics.
For the observation with residual given in res[i] :
  • sres[i×4]  is the internally studentized residual
  • sres[i×4+1]  is the externally studentized residual
  • sres[i×4+2]  is Cook's D  statistic
  • sres[i×4+3]  is Atkinson's T  statistic.
8:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

On entry, nres=value  while n=value . These arguments must satisfy nresn .
On entry, n=value  while ip + 1 = value. These arguments must satisfy n > ip + 1 .
On entry, ip=value.
Constraint: ip1.
On entry, nres=value.
Constraint: nres1.
On entry, h[value]  must not be greater than or equal to 1.0: h[value] = value.
On entry, h[value]  must not be less than or equal to 0.0: h[value] = value.
On entry, rms must not be less than or equal to 0.0: rms=value .
On entry, the value of a residual is too large for the given value of rms: res[value] = value, rms=value .


Accuracy is sufficient for all practical purposes.

Parallelism and Performance

nag_regsn_std_resid_influence (g02fac) is not threaded in any implementation.

Further Comments



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.

Program Text

Program Text (g02face.c)

Program Data

Program Data (g02face.d)

Program Results

Program Results (g02face.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017