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

NAG Library Routine Document

G02DEF

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

G02DEF adds a new independent variable to a general linear regression model.

2  Specification

SUBROUTINE G02DEF ( WEIGHT, N, IP, Q, LDQ, P, WT, X, RSS, TOL, IFAIL)
INTEGER  N, IP, LDQ, IFAIL
REAL (KIND=nag_wp)  Q(LDQ,IP+2), P(IP+1), WT(*), X(N), RSS, TOL
CHARACTER(1)  WEIGHT

3  Description

A linear regression model may be built up by adding new independent variables to an existing model. G02DEF updates the QR decomposition used in the computation of the linear regression model. The QR decomposition may come from G02DAF or a previous call to G02DEF. The general linear regression model is defined by
y=Xβ+ε,  
where y is a vector of n observations on the dependent variable,
X is an n by p matrix of the independent variables of column rank k,
β is a vector of length p of unknown parameters,
and ε is a vector of length n of unknown random errors such that varε=Vσ2, where V is a known diagonal matrix.
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 parameters β minimize y-XβT y-Xβ  while the weighted least squares estimates, minimize y-XβT W y-Xβ .
The parameter estimates may be found by computing a QR decomposition of X (or W12X in the weighted case), i.e.,
X=QR*or  W12X=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 QTW12y) 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.
To add a new independent variable, xp+1, R and c have to be updated. The matrix Qp+1 is found such that Qp+1T R:QTxp+1 (or Qp+1T R:QTW12xp+1) is upper triangular. The vector c is then updated by multiplying by Qp+1T .
The new independent variable is tested to see if it is linearly related to the existing independent variables by checking that at least one of the values QTxp+1i, for i=p+2,,n, is nonzero.
The new parameter estimates, β^, can then be obtained by a call to G02DDF.
The routine can be used with p=0, in which case R and c are initialized.

4  References

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  Parameters

1:     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'.
2:     N – INTEGERInput
On entry: n, the number of observations.
Constraint: N1.
3:     IP – INTEGERInput
On entry: p, the number of independent variables already in the model.
Constraint: IP0 and IP<N.
4:     QLDQIP+2 – REAL (KIND=nag_wp) arrayInput/Output
On entry: if IP0, Q must contain the results of the QR decomposition for the model with p parameters as returned by G02DAF or a previous call to G02DEF.
If IP=0, the first column of Q should contain the n values of the dependent variable, y.
On exit: the results of the QR decomposition for the model with p+1 parameters:
  • the first column of Q contains the updated value of c;
  • the columns 2 to IP+1 are unchanged;
  • the first IP+1 elements of column IP+2 contain the new column of R, while the remaining N-IP-1 elements contain details of the matrix Qp+1.
5:     LDQ – INTEGERInput
On entry: the first dimension of the array Q as declared in the (sub)program from which G02DEF is called.
Constraint: LDQN.
6:     PIP+1 – REAL (KIND=nag_wp) arrayInput/Output
On entry: contains further details of the QR decomposition used. The first IP elements of P must contain the zeta values for the QR decomposition (see F08AEF (DGEQRF) for details).
The first IP elements of array P are provided by G02DAF or by previous calls to G02DEF.
On exit: the first IP elements of P are unchanged and the IP+1th element contains the zeta value for Qp+1.
7:     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.
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.
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.
8:     XN – REAL (KIND=nag_wp) arrayInput
On entry: x, the new independent variable.
9:     RSS – REAL (KIND=nag_wp)Output
On exit: the residual sum of squares for the new fitted model.
Note:  this will only be valid if the model is of full rank, see Section 9.
10:   TOL – REAL (KIND=nag_wp)Input
On entry: the value of TOL is used to decide if the new independent variable is linearly related to independent variables already included in the model. If the new variable is linearly related then c is not updated. The smaller the value of TOL the stricter the criterion for deciding if there is a linear relationship.
Suggested value: TOL=0.000001.
Constraint: TOL>0.0.
11:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction 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, because for this routine the values of the output parameters may be useful even if IFAIL0 on exit, the recommended value is -1. 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).
Note: G02DEF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
IFAIL=1
On entry,N<1,
orIP<0,
orIPN,
orLDQ<N,
orTOL0.0,
orWEIGHT'U' or 'W'.
IFAIL=2
On entry, WEIGHT='W' and a value of WT<0.0.
IFAIL=3
The new independent variable is a linear combination of existing variables. The IP+2th column of Q will therefore be null.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

The accuracy is closely related to the accuracy of F08AGF (DORMQR) which should be consulted for further details.

8  Parallelism and Performance

G02DEF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02DEF 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

It should be noted that the residual sum of squares produced by G02DEF may not be correct if the model to which the new independent variable is added is not of full rank. In such a case G02DDF should be used to calculate the residual sum of squares.

10  Example

A dataset consisting of 12 observations is read in. The four independent variables are stored in the array X while the dependent variable is read into the first column of Q. If the character variable mean indicates that a mean should be included in the model a variable taking the value 1.0 for all observations is set up and fitted. Subsequently, one variable at a time is selected to enter the model as indicated by the input value of indx. After the variable has been added the parameter estimates are calculated by G02DDF and the results printed. This is repeated until the input value of indx is 0.

10.1  Program Text

Program Text (g02defe.f90)

10.2  Program Data

Program Data (g02defe.d)

10.3  Program Results

Program Results (g02defe.r)


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

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