PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_linsys_real_gen_lsq_covmat (f04ya)
Purpose
nag_linsys_real_gen_lsq_covmat (f04ya) returns elements of the estimated variance-covariance matrix of the sample regression coefficients for the solution of a linear least squares problem.
The function can be used to find the estimated variances of the sample regression coefficients.
Syntax
Description
The estimated variance-covariance matrix
of the sample regression coefficients is given by
where
is the normal matrix for the linear least squares regression problem
is the estimated variance of the residual vector
, and
is an
by
observation matrix.
When
is singular,
is taken to be
where
is the pseudo-inverse of
; this assumes that the minimal least squares solution of
(1) has been found.
The diagonal elements of are the estimated variances of the sample regression coefficients, .
The function can be used to find either the diagonal elements of , or the elements of the th column of , or the upper triangular part of .
This function must be preceded by a function that returns either the upper triangular matrix
of the
factorization of
or of the Cholesky factorization of
, or the singular values and right singular vectors of
. In particular this function can be preceded by one of the functions
nag_linsys_real_gen_solve (f04jg) or
nag_lapack_dgelss (f08ka), which return the arguments
irank,
sigma,
a and
sv in the required form.
nag_linsys_real_gen_solve (f04jg) returns the argument
svd, but when this function is used following function
nag_lapack_dgelss (f08ka) the argument
svd should be set to
true. The argument
p of this function corresponds to the argument
n in functions
nag_linsys_real_gen_solve (f04jg) and
nag_lapack_dgelss (f08ka).
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
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
Specifies which elements of
are required.
- The upper triangular part of is required.
- The diagonal elements of are required.
- The elements of column job of are required.
Constraint:
.
- 2:
– double scalar
-
, the standard error of the residual vector given by
where
is the rank of
.
Constraint:
.
- 3:
– double array
-
lda, the first dimension of the array, must satisfy the constraint
- if or , ;
- if and , .
If
,
a must contain the upper triangular matrix
of the
factorization of
, or of the Cholesky factorization of
; elements of the array below the diagonal need not be set.
If , must contain the first rows of the matrix , where is the rank of and is the right-hand orthogonal matrix of the singular value decomposition of . Thus the th row must contain the th right-hand singular vector of .
- 4:
– logical scalar
-
Must be
true if the least squares solution was obtained from a singular value decomposition of
.
svd must be
false if the least squares solution was obtained from either a
factorization of
or a Cholesky factorization of
. In the latter case the rank of
is assumed to be
and so is applicable only to full rank problems with
.
- 5:
– int64int32nag_int scalar
-
If
,
irank must specify the rank
of the matrix
.
If
,
irank is not referenced and the rank of
is assumed to be
.
Constraint:
.
- 6:
– double array
-
If
,
sv must contain the first
irank singular values of
.
If
,
sv is not referenced.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
sv and the second dimension of the array
a. (An error is raised if these dimensions are not equal.)
, the order of the variance-covariance matrix .
Constraint:
.
Output Parameters
- 1:
– double array
-
If
,
is unchanged.
If
,
a contains the upper triangle of the symmetric matrix
.
If , elements of the array below the diagonal are used as workspace.
If , they are unchanged.
- 2:
– double array
-
If
,
cj returns the diagonal elements of
.
If
,
cj returns the
th column of
.
If
,
cj is not referenced.
- 3:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
On entry, | , |
or | , |
or | , |
or | , |
or | and ( or ) or ( and ) or ( and )), |
or | and . |
-
-
On entry, and .
-
-
On entry, and overflow would occur in computing an element of . The upper triangular matrix must be very nearly singular.
-
-
On entry,
and one of the first
irank singular values is zero. Either the first
irank singular values or
irank must be incorrect.
-
-
If overflow occurs then either an element of is very large, or more likely, either the rank, or the upper triangular matrix, or the singular values or vectors have been incorrectly supplied.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The computed elements of 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.
Further Comments
When the time taken by nag_linsys_real_gen_lsq_covmat (f04ya) is approximately proportional to , where is the rank of . When and , the time taken by the function is approximately proportional to , otherwise the time taken is approximately proportional to .
Example
This example finds the estimated variances of the sample regression coefficients (the diagonal elements of
) for the linear least squares problem
following a solution obtained by
nag_linsys_real_gen_solve (f04jg). See the function document for
nag_linsys_real_gen_solve (f04jg) for further information.
Open in the MATLAB editor:
f04ya_example
function f04ya_example
fprintf('f04ya example results\n\n');
a = [ 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; 4; -1; -5; -1];
[n,p] = size(a);
tol = 0.0005;
lwork = int64(32);
[a, x, svd, sigma, irank, work, ifail] = ...
f04jg(a, b, tol, lwork);
fprintf('Standard error = %6.3f, rank = %2d\n\n', sigma, irank);
if svd==1
fprintf('Solution obtained from SVD of A\n');
else
fprintf('Solution obtained from QU factorization of A\n');
end
disp(x(1:p)');
job = int64(0);
[a, cj, ifail] = f04ya( ...
job, sigma, a, svd, irank, work(1:p));
disp('Estimated variances of regression coefficients');
disp(cj');
f04ya example results
Standard error = 0.412, rank = 3
Solution obtained from QU factorization of A
0.9533 -0.8433 0.9067
Estimated variances of regression coefficients
0.0106 0.0093 0.0045
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015