NAG Library Routine Document

f04yaf  (real_gen_lsq_covmat)

 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

Fortran Interface
Subroutine f04yaf ( job, p, sigma, a, lda, svd, irank, sv, cj, work, ifail)
Integer, Intent (In):: job, p, lda, irank
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: sigma, sv(p)
Real (Kind=nag_wp), Intent (Inout):: a(lda,p)
Real (Kind=nag_wp), Intent (Out):: cj(p), work(p)
Logical, Intent (In):: svd
C Header Interface
#include nagmk26.h
void  f04yaf_ ( const Integer *job, const Integer *p, const double *sigma, double a[], const Integer *lda, const logical *svd, const Integer *irank, const double sv[], double cj[], double work[], Integer *ifail)

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 arguments irank, sigma, a and sv in the required form. f04jgf returns the argument svd, but when this routine is used following routine f08kaf (dgelss) the argument svd should be set to .TRUE.. The argument p of this routine corresponds to the argument 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
Arguments

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:     aldap – 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:     svp – 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:     cjp – 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:   workp – 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 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,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.
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 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
Parallelism and Performance

f04yaf 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

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.

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

10.1
Program Text

Program Text (f04yafe.f90)

10.2
Program Data

Program Data (f04yafe.d)

10.3
Program Results

Program Results (f04yafe.r)

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