G02DAF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G02DAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

G02DAF performs a general multiple linear regression when the independent variables may be linearly dependent. Parameter estimates, standard errors, residuals and influence statistics are computed. G02DAF may be used to perform a weighted regression.

2  Specification

SUBROUTINE G02DAF ( MEAN, WEIGHT, N, X, LDX, M, ISX, IP, Y, WT, RSS, IDF, B, SE, COV, RES, H, Q, LDQ, SVD, IRANK, P, TOL, WK, IFAIL)
INTEGER  N, LDX, M, ISX(M), IP, IDF, LDQ, IRANK, IFAIL
REAL (KIND=nag_wp)  X(LDX,M), Y(N), WT(*), RSS, B(IP), SE(IP), COV(IP*(IP+1)/2), RES(N), H(N), Q(LDQ,IP+1), P(2*IP+IP*IP), TOL, WK(max(2,5*(IP-1)+IP*IP))
LOGICAL  SVD
CHARACTER(1)  MEAN, WEIGHT

3  Description

The general linear regression model is defined by
y=Xβ+ε,  
where
If V=I, the identity matrix, then least squares estimation is used. If VI, then for a given weight matrix WV-1, weighted least squares estimation is used.
The least squares estimates β^ of the arguments β minimize y-XβT y-Xβ  while the weighted least squares estimates minimize y-XβT Wy-Xβ .
G02DAF finds a QR decomposition of X (or W1/2X in weighted case), i.e.,
X=QR*or  W1/2X=QR*,  
where R*= R 0  and R is a p by p upper triangular matrix and Q is an n by n orthogonal matrix. If R is of full rank, then β^ is the solution to
Rβ^=c1,  
where c=QTy (or QTW1/2y) and c1 is the first p elements of c. If R is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of R,
R=Q* D 0 0 0 PT,  
where D is a k by k diagonal matrix with nonzero diagonal elements, k being the rank of R, and Q* and P are p by p orthogonal matrices. This gives the solution
β^=P1D-1Q*1Tc1,  
P1 being the first k columns of P, i.e., P=P1P0, and Q*1 being the first k columns of Q*.
Details of the SVD, are made available, in the form of the matrix P*:
P*= D-1 P1T P0T .  
This will be only one of the possible solutions. Other estimates may be obtained by applying constraints to the arguments. These solutions can be obtained by using G02DKF after using G02DAF. Only certain linear combinations of the arguments will have unique estimates; these are known as estimable functions.
The fit of the model can be examined by considering the residuals, ri=yi-y^, where y^=Xβ^ are the fitted values. The fitted values 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 hi are sometimes known as leverages. Both ri and hi are provided by G02DAF.
The output of G02DAF also includes β^, the residual sum of squares and associated degrees of freedom, n-k, the standard errors of the parameter estimates and the variance-covariance matrix of the parameter estimates.
In many linear regression models the first term is taken as a mean term or an intercept, i.e., Xi,1=1, for i=1,2,,n. This is provided as an option. Also only some of the possible independent variables are required to be included in a model, a facility to select variables to be included in the model is provided.
Details of the QR decomposition and, if used, the SVD, are made available. These allow the regression to be updated by adding or deleting an observation using G02DCF, adding or deleting a variable using G02DEF and G02DFF or estimating and testing an estimable function using G02DNF.

4  References

Cook R D and Weisberg S (1982) Residuals and Influence in Regression Chapman and Hall
Draper N R and Smith H (1985) Applied Regression Analysis (2nd Edition) Wiley
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Hammarling S (1985) The singular value decomposition in multivariate statistics SIGNUM Newsl. 20(3) 2–25
McCullagh P and Nelder J A (1983) Generalized Linear Models Chapman and Hall
Searle S R (1971) Linear Models Wiley

5  Arguments

1:     MEAN – CHARACTER(1)Input
On entry: indicates if a mean term is to be included.
MEAN='M'
A mean term, intercept, will be included in the model.
MEAN='Z'
The model will pass through the origin, zero-point.
Constraint: MEAN='M' or 'Z'.
2:     WEIGHT – CHARACTER(1)Input
On entry: indicates if weights are to be used.
WEIGHT='U'
Least squares estimation is used.
WEIGHT='W'
Weighted least squares is used and weights must be supplied in array WT.
Constraint: WEIGHT='U' or 'W'.
3:     N – INTEGERInput
On entry: n, the number of observations.
Constraint: N2.
4:     XLDXM – REAL (KIND=nag_wp) arrayInput
On entry: Xij must contain the ith observation for the jth independent variable, for i=1,2,,N and j=1,2,,M.
5:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G02DAF is called.
Constraint: LDXN.
6:     M – INTEGERInput
On entry: m, the total number of independent variables in the dataset.
Constraint: M1.
7:     ISXM – INTEGER arrayInput
On entry: indicates which independent variables are to be included in the model.
ISXj>0
The variable contained in the jth column of X is included in the regression model.
Constraints:
  • ISXj0, for j=1,2,,m;
  • if MEAN='M', exactly IP-1 values of ISX must be >0;
  • if MEAN='Z', exactly IP values of ISX must be >0.
8:     IP – INTEGERInput
On entry: the number of independent variables in the model, including the mean or intercept if present.
Constraints:
  • if MEAN='M', 1IPM+1;
  • if MEAN='Z', 1IPM;
  • otherwise 1IPN.
9:     YN – REAL (KIND=nag_wp) arrayInput
On entry: y, the observations on the dependent variable.
10:   WT* – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array WT must be at least N if WEIGHT='W', and at least 1 otherwise.
On entry: if WEIGHT='W', WT must contain the weights to be used in the weighted regression.
If WTi=0.0, the ith observation is not included in the model, in which case the effective number of observations is the number of observations with nonzero weights. The values of RES and H will be set to zero for observations with zero weights.
If WEIGHT='U', WT is not referenced and the effective number of observations is n.
Constraint: if WEIGHT='W', WTi0.0, for i=1,2,,n.
11:   RSS – REAL (KIND=nag_wp)Output
On exit: the residual sum of squares for the regression.
12:   IDF – INTEGEROutput
On exit: the degrees of freedom associated with the residual sum of squares.
13:   BIP – REAL (KIND=nag_wp) arrayOutput
On exit: Bi, i=1,2,,IP contains the least squares estimates of the parameters of the regression model, β^.
If MEAN='M', B1 will contain the estimate of the mean parameter and Bi+1 will contain the coefficient of the variable contained in column j of X, where ISXj is the ith positive value in the array ISX.
If MEAN='Z', Bi will contain the coefficient of the variable contained in column j of X, where ISXj is the ith positive value in the array ISX.
14:   SEIP – REAL (KIND=nag_wp) arrayOutput
On exit: SEi, i=1,2,,IP contains the standard errors of the IP parameter estimates given in B.
15:   COVIP×IP+1/2 – REAL (KIND=nag_wp) arrayOutput
On exit: the first IP×IP+1/2 elements of COV contain the upper triangular part of the variance-covariance matrix of the IP parameter estimates given in B. They are stored packed by column, i.e., the covariance between the parameter estimate given in Bi and the parameter estimate given in Bj, ji, is stored in COVj×j-1/2+i.
16:   RESN – REAL (KIND=nag_wp) arrayOutput
On exit: the (weighted) residuals, ri, for i=1,2,,n.
17:   HN – REAL (KIND=nag_wp) arrayOutput
On exit: the diagonal elements of H, hi, for i=1,2,,n.
18:   QLDQIP+1 – REAL (KIND=nag_wp) arrayOutput
On exit: the results of the QR decomposition:
  • the first column of Q contains c;
  • the upper triangular part of columns 2 to IP+1 contain the R matrix;
  • the strictly lower triangular part of columns 2 to IP+1 contain details of the Q matrix.
19:   LDQ – INTEGERInput
On entry: the first dimension of the array Q as declared in the (sub)program from which G02DAF is called.
Constraint: LDQN.
20:   SVD – LOGICALOutput
On exit: if a singular value decomposition has been performed then SVD will be .TRUE., otherwise SVD will be .FALSE..
21:   IRANK – INTEGEROutput
On exit: the rank of the independent variables.
If SVD=.FALSE., IRANK=IP.
If SVD=.TRUE., IRANK is an estimate of the rank of the independent variables.
IRANK is calculated as the number of singular values greater that TOL× (largest singular value). It is possible for the SVD to be carried out but IRANK to be returned as IP.
22:   P2×IP+IP×IP – REAL (KIND=nag_wp) arrayOutput
On exit: details of the QR decomposition and SVD if used.
If SVD=.FALSE., only the first IP elements of P are used these will contain the zeta values for the QR decomposition (see F08AEF (DGEQRF) for details).
If SVD=.TRUE., the first IP elements of P will contain the zeta values for the QR decomposition (see F08AEF (DGEQRF) for details) and the next IP elements of P contain singular values. The following IP by IP elements contain the matrix P* stored by columns.
23:   TOL – REAL (KIND=nag_wp)Input
On entry: the value of TOL is used to decide if the independent variables are of full rank and if not what is the rank of the independent variables. The smaller the value of TOL the stricter the criterion for selecting the singular value decomposition. If TOL=0.0, the singular value decomposition will never be used; this may cause run time errors or inaccurate results if the independent variables are not of full rank.
Suggested value: TOL=0.000001.
Constraint: TOL0.0.
24:   WKmax2,5×IP-1+IP×IP – REAL (KIND=nag_wp) arrayOutput
On exit: if on exit SVD=.TRUE., WK contains information which is needed by G02DGF; otherwise WK is used as workspace.
25:   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).

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:
IFAIL=1
On entry,N<2,
orM<1,
orLDX<N,
orLDQ<N,
orTOL<0.0,
orIP0,
orIP>N.
IFAIL=2
On entry,MEAN'M' or 'Z',
orWEIGHT'W' or 'U'.
IFAIL=3
On entry,WEIGHT='W' and a value of WT<0.0.
IFAIL=4
On entry,a value of ISX<0,
orthe value of IP is incompatible with the values of MEAN and ISX,
orIP is greater than the effective number of observations.
IFAIL=5
The degrees of freedom for the residuals are zero, i.e., the designated number of arguments is equal to the effective number of observations. In this case the parameter estimates will be returned along with the diagonal elements of H, but neither standard errors nor the variance-covariance matrix will be calculated.
IFAIL=6
The singular value decomposition has failed to converge, see F02WUF. This is an unlikely error.
IFAIL=-99
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.
IFAIL=-399
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.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7  Accuracy

The accuracy of G02DAF is closely related to the accuracy of F02WUF and F08AEF (DGEQRF). These routine documents should be consulted.

8  Parallelism and Performance

G02DAF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02DAF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments

Standardized residuals and further measures of influence can be computed using G02FAF. G02FAF requires, in particular, the results stored in RES and H.

10  Example

Data from an experiment with four treatments and three observations per treatment are read in. The treatments are represented by dummy (0-1) variables. An unweighted model is fitted with a mean included in the model. G02BUF is then called to calculate the total sums of squares and the coefficient of determination (R2), adjusted R2 and Akaike's information criteria (AIC) are calculated.
G02BUF is then called to calculate the total sums of squares and the coefficient of determination (R2), adjusted R2 and Akaike's information criteria (AIC) are calculated.

10.1  Program Text

Program Text (g02dafe.f90)

10.2  Program Data

Program Data (g02dafe.d)

10.3  Program Results

Program Results (g02dafe.r)


G02DAF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

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