F04YAF (PDF version)
F04 Chapter Contents
F04 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

F04YAF

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

F04YAF returns elements of the estimated variance-covariance matrix of the sample regression coefficients for the solution of a linear least squares problem.
The routine can be used to find the estimated variances of the sample regression coefficients.

2  Specification

SUBROUTINE F04YAF ( JOB, P, SIGMA, A, LDA, SVD, IRANK, SV, CJ, WORK, IFAIL)
INTEGER  JOB, P, LDA, IRANK, IFAIL
REAL (KIND=nag_wp)  SIGMA, A(LDA,P), SV(P), CJ(P), WORK(P)
LOGICAL  SVD

3  Description

The estimated variance-covariance matrix C of the sample regression coefficients is given by
C = σ 2 XT X - 1 , XT X   nonsingular,
where XTX is the normal matrix for the linear least squares regression problem
min:y-Xb2, (1)
σ2 is the estimated variance of the residual vector r=y-Xb, and X is an n by p observation matrix.
When XTX is singular, C is taken to be
C=σ2 XTX ,
where XTX  is the pseudo-inverse of XTX; this assumes that the minimal least squares solution of (1) has been found.
The diagonal elements of C are the estimated variances of the sample regression coefficients, b.
The routine can be used to find either the diagonal elements of C, or the elements of the jth column of C, or the upper triangular part of C.
This routine must be preceded by a routine that returns either the upper triangular matrix U of the QU factorization of X or of the Cholesky factorization of XTX, or the singular values and right singular vectors of X. In particular this routine can be preceded by one of the routines F04JGF or F08KAF (DGELSS), which return the parameters IRANK, SIGMA, A and SV in the required form. F04JGF returns the parameter SVD, but when this routine is used following routine F08KAF (DGELSS) the parameter SVD should be set to .TRUE.. The parameter P of this routine corresponds to the parameter N in routines F04JGF and F08KAF (DGELSS).

4  References

Anderson T W (1958) An Introduction to Multivariate Statistical Analysis Wiley
Lawson C L and Hanson R J (1974) Solving Least-squares Problems Prentice–Hall

5  Parameters

1:     JOB – INTEGERInput
On entry: specifies which elements of C are required.
JOB=-1
The upper triangular part of C is required.
JOB=0
The diagonal elements of C are required.
JOB>0
The elements of column JOB of C are required.
Constraint: -1JOBP.
2:     P – INTEGERInput
On entry: p, the order of the variance-covariance matrix C.
Constraint: P1.
3:     SIGMA – REAL (KIND=nag_wp)Input
On entry: σ, the standard error of the residual vector given by
σ=rTr/n-k,n>kσ=0,n=k,
where k is the rank of X.
Constraint: SIGMA0.0.
4:     A(LDA,P) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if SVD=.FALSE., A must contain the upper triangular matrix U of the QU factorization of X, or of the Cholesky factorization of XTX; elements of the array below the diagonal need not be set.
If SVD=.TRUE., A must contain the first k rows of the matrix VT, where k is the rank of X and V is the right-hand orthogonal matrix of the singular value decomposition of X. Thus the ith row must contain the ith right-hand singular vector of X.
On exit: if JOB0, A is unchanged.
If JOB=-1, A contains the upper triangle of the symmetric matrix C.
If SVD=.TRUE., elements of the array below the diagonal are used as workspace.
If SVD=.FALSE., they are unchanged.
5:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F04YAF is called.
Constraints:
  • if SVD=.FALSE. or JOB=-1, LDAP;
  • if SVD=.TRUE. and JOB0, LDAmax1,IRANK.
6:     SVD – LOGICALInput
On entry: must be .TRUE. if the least squares solution was obtained from a singular value decomposition of X. SVD must be .FALSE. if the least squares solution was obtained from either a QU factorization of X or a Cholesky factorization of XTX. In the latter case the rank of X is assumed to be p and so is applicable only to full rank problems with np.
7:     IRANK – INTEGERInput
On entry: if SVD=.TRUE., IRANK must specify the rank k of the matrix X.
If SVD=.FALSE., IRANK is not referenced and the rank of X is assumed to be p.
Constraint: 0<IRANKminn,P.
8:     SV(P) – REAL (KIND=nag_wp) arrayInput
On entry: if SVD=.TRUE., SV must contain the first IRANK singular values of X.
If SVD=.FALSE., SV is not referenced.
9:     CJ(P) – REAL (KIND=nag_wp) arrayOutput
On exit: if JOB=0, CJ returns the diagonal elements of C.
If JOB=j>0, CJ returns the jth column of C.
If JOB=-1, CJ is not referenced.
10:   WORK(P) – REAL (KIND=nag_wp) arrayWorkspace
If JOB>0, WORK is not referenced.
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, 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,P<1,
orSIGMA<0.0,
orJOB<-1,
orJOB>P,
orSVD=.TRUE. and (IRANK<0 or IRANK>P)
or (JOB0 and LDA<max1,IRANK)
or (JOB=-1 and LDA<P)),
orSVD=.FALSE. and LDA<P.
IFAIL=2
On entry, SVD=.TRUE. and IRANK=0.
IFAIL=3
On entry, SVD=.FALSE. and overflow would occur in computing an element of C. The upper triangular matrix U must be very nearly singular.
IFAIL=4
On entry, SVD=.TRUE. and one of the first IRANK singular values is zero. Either the first IRANK singular values or IRANK must be incorrect.
overflow
If overflow occurs then either an element of C is very large, or more likely, either the rank, or the upper triangular matrix, or the singular values or vectors have been incorrectly supplied.

7  Accuracy

The computed elements of C will be the exact covariances of a closely neighbouring least squares problem, so long as a numerically stable method has been used in the solution of the least squares problem.

8  Further Comments

When JOB=-1 the time taken by F04YAF is approximately proportional to pk2, where k is the rank of X. When JOB=0 and SVD=.FALSE., the time taken by the routine is approximately proportional to pk2, otherwise the time taken is approximately proportional to pk.

9  Example

This example finds the estimated variances of the sample regression coefficients (the diagonal elements of C) for the linear least squares problem
minrTr ,   where ​ r=y-Xb  and
X= 0.6 1.2 3.9 5.0 4.0 2.5 1.0 -4.0 -5.5 -1.0 -2.0 -6.5 -4.2 -8.4 -4.8 ,   b= 3.0 4.0 -1.0 -5.0 -1.0 ,
following a solution obtained by F04JGF. See the routine document for F04JGF for further information.

9.1  Program Text

Program Text (f04yafe.f90)

9.2  Program Data

Program Data (f04yafe.d)

9.3  Program Results

Program Results (f04yafe.r)


F04YAF (PDF version)
F04 Chapter Contents
F04 Chapter Introduction
NAG Library Manual

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