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

NAG Library Routine Document

G02DGF

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

G02DGF calculates the estimates of the parameters of a general linear regression model for a new dependent variable after a call to G02DAF.

2  Specification

SUBROUTINE G02DGF ( WEIGHT, N, WT, RSS, IP, IRANK, COV, Q, LDQ, SVD, P, Y, B, SE, RES, WK, IFAIL)
INTEGER  N, IP, IRANK, LDQ, IFAIL
REAL (KIND=nag_wp)  WT(*), RSS, COV(IP*(IP+1)/2), Q(LDQ,IP+1), P(*), Y(N), B(IP), SE(IP), RES(N), WK(5*(IP-1)+IP*IP)
LOGICAL  SVD
CHARACTER(1)  WEIGHT

3  Description

G02DGF uses the results given by G02DAF to fit the same set of independent variables to a new dependent variable.
G02DAF computes a QR decomposition of the matrix of p independent variables and also, if the model is not of full rank, a singular value decomposition (SVD). These results can be used to compute estimates of the parameters for a general linear model with a new dependent variable. The QR decomposition leads to the formation of an upper triangular p by p matrix R and an n by n orthogonal matrix Q. In addition the vector c=QTy (or QTW1/2y) is computed. For a new dependent variable, ynew, G02DGF computes a new value of c=QTynew or QTW1/2ynew.
If R is of full rank, then the least squares parameter estimates, β^, are the solution to
Rβ^=c1,
where c1 is the first p elements of c.
If R is not of full rank, then G02DAF will have computed an 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-1 Q*1T c1,
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 by G02DAF in the form of the matrix P*:
P*= D-1 P1T P0T .
The matrix Q* is made available through the workspace of G02DAF.
In addition to parameter estimates, the new residuals are computed and the variance-covariance matrix of the parameter estimates are found by scaling the variance-covariance matrix for the original regression.

4  References

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
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: NIP.
3:     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.
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.
4:     RSS – REAL (KIND=nag_wp)Input/Output
On entry: the residual sum of squares for the original dependent variable.
On exit: the residual sum of squares for the new dependent variable.
Constraint: RSS>0.0.
5:     IP – INTEGERInput
On entry: p, the number of independent variables (including the mean if fitted).
Constraint: 1IPN.
6:     IRANK – INTEGERInput
On entry: the rank of the independent variables, as given by G02DAF.
Constraint: IRANK>0, and if SVD=.FALSE., then IRANK=IP, else IRANKIP.
7:     COV(IP×IP+1/2) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the covariance matrix of the parameter estimates as given by G02DAF.
On exit: 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.
8:     Q(LDQ,IP+1) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the results of the QR decomposition as returned by G02DAF.
On exit: the first column of Q contains the new values of c, the remainder of Q will be unchanged.
9:     LDQ – INTEGERInput
On entry: the first dimension of the array Q as declared in the (sub)program from which G02DGF is called.
Constraint: LDQN.
10:   SVD – LOGICALInput
On entry: indicates if a singular value decomposition was used by G02DAF.
SVD=.TRUE.
A singular value decomposition was used by G02DAF.
SVD=.FALSE.
A singular value decomposition was not used by G02DAF.
11:   P(*) – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array P must be at least IP if SVD=.FALSE., and at least IP×IP+2×IP otherwise.
On entry: details of the QR decomposition and SVD, if used, as returned in array P by G02DAF.
If SVD=.FALSE., only the first IP elements of P are used; these contain the zeta values for the QR decomposition (see F08AEF (DGEQRF) for details).
If SVD=.TRUE., the first IP elements of P contain the zeta values for the QR decomposition (see F08AEF (DGEQRF) for details) and the next IP×IP+IP elements of P contain details of the singular value decomposition.
12:   Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the new dependent variable, ynew.
13:   B(IP) – REAL (KIND=nag_wp) arrayOutput
On exit: the least squares estimates of the parameters of the regression model, β^.
14:   SE(IP) – REAL (KIND=nag_wp) arrayOutput
On exit: the standard error of the estimates of the parameters.
15:   RES(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the residuals for the new regression model.
16:   WK(5×IP-1+IP×IP) – REAL (KIND=nag_wp) arrayInput
On entry: if SVD=.TRUE., WK must be unaltered from the previous call to G02DAF or G02DGF.
If SVD=.FALSE., WK is used as workspace.
17:   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, if you are not familiar with this parameter, 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,IP<1,
orN<IP,
orIRANK0,
orSVD=.FALSE. and IRANKIP,
orSVD=.TRUE. and IRANK>IP,
orLDQ<N,
orRSS0.0,
orWEIGHT'U' or 'W'.
IFAIL=2
On entry,WEIGHT='W' and a value of WT<0.0.

7  Accuracy

The same accuracy as G02DAF is obtained.

8  Further Comments

The values of the leverages, hi, are unaltered by a change in the dependent variable so a call to G02FAF can be made using the value of H from G02DAF.

9  Example

A dataset consisting of 12 observations with four independent variables and two dependent variables are read in. A model with all four independent variables is fitted to the first dependent variable by G02DAF and the results printed. The model is then fitted to the second dependent variable by G02DGF and those results printed.

9.1  Program Text

Program Text (g02dgfe.f90)

9.2  Program Data

Program Data (g02dgfe.d)

9.3  Program Results

Program Results (g02dgfe.r)


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

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