NAG FL Interface
f04yaf (real_​gen_​lsq_​covmat)

Settings help

FL Name Style:


FL Specification Language:


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 <nag.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)
The routine may be called by the names f04yaf or nagf_linsys_real_gen_lsq_covmat.

3 Description

The estimated variance-covariance matrix C of the sample regression coefficients is given by
C = σ 2 ( X TX) - 1 , X T 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×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, 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 the argument svd should be set to .TRUE.. The argument p of this routine corresponds to the argument n in routines f04jgf and f08kaf.

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 Integer Input
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 Integer Input
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) array Input/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 Integer Input
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, ldamax(1,irank).
6: svd Logical Input
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 Integer Input
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<irankmin(n,p).
8: sv(p) Real (Kind=nag_wp) array Input
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) array Output
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) array Workspace
If job>0, work is not referenced.
11: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. 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, irank=value and p=value.
Constraint: if svd=.TRUE., irank0 and irankp.
On entry, job=value, lda=value and irank=value.
Constraint: if svd=.TRUE. and job0, ldamax(1,irank).
On entry, job=value and p=value.
Constraint: job−1 and jobp.
On entry, lda=value and p=value.
Constraint: if svd=.FALSE., ldap.
On entry, lda=value and p=value.
Constraint: if svd=.TRUE. and job=−1, ldap.
On entry, p=value.
Constraint: p1.
On entry, sigma=value.
Constraint: sigma0.0.
ifail=2
On entry, irank=value.
Constraint: if svd=.TRUE., irank>0.
ifail=3
On entry, svd=.FALSE. and overflow would occur in calculating an element of C. The upper triangular matrix U must be very nearly singular.
ifail=4
On entry, svd=.FALSE. and one of the first irank singular values is zero. Either the first irank singular values or irank must be incorrect: irank=value.
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 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface 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)