NAG Library Routine Document

g02dgf  (linregm_fit_newvar)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

g02dgf calculates the estimates of the arguments of a general linear regression model for a new dependent variable after a call to g02daf.

2
Specification

Fortran Interface
Subroutine g02dgf ( weight, n, wt, rss, ip, irank, cov, q, ldq, svd, p, y, b, se, res, wk, ifail)
Integer, Intent (In):: n, ip, irank, ldq
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: wt(*), p(*), y(n), wk(5*(ip-1)+ip*ip)
Real (Kind=nag_wp), Intent (Inout):: rss, cov(ip*(ip+1)/2), q(ldq,ip+1)
Real (Kind=nag_wp), Intent (Out):: b(ip), se(ip), res(n)
Logical, Intent (In):: svd
Character (1), Intent (In):: weight
C Header Interface
#include nagmk26.h
void  g02dgf_ ( const char *weight, const Integer *n, const double wt[], double *rss, const Integer *ip, const Integer *irank, double cov[], double q[], const Integer *ldq, const logical *svd, const double p[], const double y[], double b[], double se[], double res[], const double wk[], Integer *ifail, const Charlen length_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 arguments 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
Arguments

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:     covip×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:     qldqip+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:   yn – Real (Kind=nag_wp) arrayInput
On entry: the new dependent variable, ynew.
13:   bip – Real (Kind=nag_wp) arrayOutput
On exit: the least squares estimates of the parameters of the regression model, β^.
14:   seip – Real (Kind=nag_wp) arrayOutput
On exit: the standard error of the estimates of the parameters.
15:   resn – Real (Kind=nag_wp) arrayOutput
On exit: the residuals for the new regression model.
16:   wk5×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 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, ip=value.
Constraint: ip1.
On entry, irank=value.
Constraint: irank>0.
On entry, irank=value and ip=value.
Constraint: if svd=.FALSE., irank=ip.
On entry, irank=value and ip=value.
Constraint: if svd=.TRUE., irankip.
On entry, ldq=value and n=value.
Constraint: ldqn.
On entry, n=value and ip=value.
Constraint: nip.
On entry, rss=value.
Constraint: rss>0.0.
On entry, weight=value.
Constraint: weight='W' or 'U'.
ifail=2
On entry, wtvalue<0.0.
Constraint: wti0.0, for i=1,2,,n.
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 same accuracy as g02daf is obtained.

8
Parallelism and Performance

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

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.

10
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.

10.1
Program Text

Program Text (g02dgfe.f90)

10.2
Program Data

Program Data (g02dgfe.d)

10.3
Program Results

Program Results (g02dgfe.r)

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