NAG Library Routine Document

g02faf (linregm_stat_resinf)


    1  Purpose
    7  Accuracy


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


Fortran Interface
Subroutine g02faf ( n, ip, nres, res, h, rms, sres, ldsres, ifail)
Integer, Intent (In):: n, ip, nres, ldsres
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: res(nres), h(nres), rms
Real (Kind=nag_wp), Intent (Inout):: sres(ldsres,4)
C Header Interface
#include nagmk26.h
void  g02faf_ (const Integer *n, const Integer *ip, const Integer *nres, const double res[], const double h[], const double *rms, double sres[], const Integer *ldsres, Integer *ifail)


For the general linear regression model
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ε=σ2I.
The residuals are given by
and the fitted values, y^=Xβ^, can be written as Hy for an n by n matrix H. The ith diagonal elements of H, hi, give a measure of the influence of the ith values of the independent variables on the fitted regression model. The values of r and the hi are returned by g02daf.
g02faf 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 ith residual is standardized by its variance when the estimate of σ2, s2, is calculated from all the data; this is known as internal Studentization.
RIi=ris1-hi .  
(ii) The ith residual is standardized by its variance when the estimate of σ2, s-i2 is calculated from the data excluding the ith 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 .  


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: n, the number of observations included in the regression.
Constraint: n>ip+1.
2:     ip – IntegerInput
On entry: p, the number of linear arguments estimated in the regression model.
Constraint: ip1.
3:     nres – IntegerInput
On entry: the number of residuals.
Constraint: 1nresn.
4:     resnres – Real (Kind=nag_wp) arrayInput
On entry: the residuals, ri.
5:     hnres – Real (Kind=nag_wp) arrayInput
On entry: the diagonal elements of H, hi, corresponding to the residuals in res.
Constraint: 0.0<hi<1.0, for i=1,2,,nres.
6:     rms – Real (Kind=nag_wp)Input
On entry: the estimate of σ2 based on all n observations, s2, i.e., the residual mean square.
Constraint: rms>0.0.
7:     sresldsres4 – Real (Kind=nag_wp) arrayOutput
On exit: the standardized residuals and influence statistics.
For the observation with residual, ri, given in resi.
Is the internally standardized residual, RIi.
Is the externally standardized residual, REi.
Is Cook's D statistic, Di.
Is Atkinson's T statistic, Ti.
8:     ldsres – IntegerInput
On entry: the first dimension of the array sres as declared in the (sub)program from which g02faf is called.
Constraint: ldsresnres.
9:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry, ip=value.
Constraint: ip1.
On entry, ip=value and n=value.
Constraint: n-1>ip.
On entry, ldsres=value and nres=value.
Constraint: ldsresnres.
On entry, nres=value.
Constraint: nres1.
On entry, nres=value and n=value.
Constraint: nresn.
On entry, rms=value.
Constraint: rms>0.0.
On entry, hvalue=value.
Constraint: 0.0<hi<1.0, for all i.
On entry, a value in res is too large for given rms. resvalue=value and rms=value.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


Accuracy is sufficient for all practical purposes.

Parallelism and Performance

g02faf is not threaded in any implementation.

Further Comments



A set of 24 residuals and hi 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.

Program Text

Program Text (g02fafe.f90)

Program Data

Program Data (g02fafe.d)

Program Results

Program Results (g02fafe.r)

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