PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_opt_lsq_uncon_covariance (e04yc)
Purpose
nag_opt_lsq_uncon_covariance (e04yc) returns estimates of elements of the variance-covariance matrix of the estimated regression coefficients for a nonlinear least squares problem. The estimates are derived from the Jacobian of the function at the solution.
Syntax
Description
nag_opt_lsq_uncon_covariance (e04yc) is intended for use when the nonlinear least squares function,
, represents the goodness-of-fit of a nonlinear model to observed data. The function assumes that the Hessian of
, at the solution, can be adequately approximated by
, where
is the Jacobian of
at the solution. The estimated variance-covariance matrix
is then given by
where
is the estimated variance of the residual at the solution,
, given by
being the number of observations and
the number of variables.
The diagonal elements of
are estimates of the variances of the estimated regression coefficients. See the
E04 Chapter Introduction,
Bard (1974) and
Wolberg (1967) for further information on the use of
.
When
is singular then
is taken to be
where
is the pseudo-inverse of
, and
but in this case the argument
ifail is returned as nonzero as a warning to you that
has linear dependencies in its columns. The assumed rank of
can be obtained from
ifail.
The function can be used to find either the diagonal elements of , or the elements of the th column of , or the whole of .
nag_opt_lsq_uncon_covariance (e04yc) must be preceded by one of the nonlinear least squares functions mentioned in
Purpose, and requires the arguments
fsumsq,
s and
v to be supplied by those functions (e.g., see
nag_opt_lsq_uncon_mod_func_comp (e04fc)).
fsumsq is the residual sum of squares
and
s and
v contain the singular values and right singular vectors respectively in the singular value decomposition of
.
s and
v are returned directly by the comprehensive functions
nag_opt_lsq_uncon_mod_func_comp (e04fc),
nag_opt_lsq_uncon_quasi_deriv_comp (e04gb),
nag_opt_lsq_uncon_mod_deriv_comp (e04gd) and
nag_opt_lsq_uncon_mod_deriv2_comp (e04he), but are returned as part of the workspace argument
w (from one of the easy-to-use functions). In the case of
nag_opt_lsq_uncon_mod_func_easy (e04fy),
s starts at
, where
and in the cases of the remaining easy-to-use functions,
s starts at
, where
The argument
v starts immediately following the elements of
s, so that
v starts at
, where
For all the easy-to-use functions the argument
ldv must be supplied as
n. Thus a call to
nag_opt_lsq_uncon_covariance (e04yc) following
nag_opt_lsq_uncon_mod_func_easy (e04fy) can be illustrated as
.
.
.
[x, fsumsq, user, ifail] = e04fy(m, lsfun1, x);
.
.
.
ns = 6*n + 2*m + m*n + 1 + max((1,(n*(n-1))/2);
nv = ns + n;
[v, cj, ifail] = e04yc(job, m, fsumsq, w(ns:nv-1), w(nv:numel(w)));
where the arguments
m,
n,
fsumsq and the
elements
must not be altered between the calls to
nag_opt_lsq_uncon_mod_func_easy (e04fy) and
nag_opt_lsq_uncon_covariance (e04yc). The above illustration also holds for a call to
nag_opt_lsq_uncon_covariance (e04yc) following a call to one of
nag_opt_lsq_uncon_quasi_deriv_easy (e04gy),
nag_opt_lsq_uncon_mod_deriv_easy (e04gz) or
nag_opt_lsq_uncon_mod_deriv2_easy (e04hy), except that
must be computed as
References
Bard Y (1974) Nonlinear Parameter Estimation Academic Press
Wolberg J R (1967) Prediction Analysis Van Nostrand
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
Which elements of
are returned as follows:
- The by symmetric matrix is returned.
- The diagonal elements of are returned.
- The elements of column job of are returned.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
The number of observations (residuals ).
Constraint:
.
- 3:
– double scalar
-
The sum of squares of the residuals, , at the solution , as returned by the nonlinear least squares function.
Constraint:
.
- 4:
– double array
-
The
singular values of the Jacobian as returned by the nonlinear least squares function. See
Description for information on supplying
s following one of the easy-to-use functions.
- 5:
– double array
-
ldv, the first dimension of the array, must satisfy the constraint if , .
The
by
right-hand orthogonal matrix (the right singular vectors) of
as returned by the nonlinear least squares function. See
Description for information on supplying
v following one of the easy-to-use functions.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
s and the second dimension of the array
v. (An error is raised if these dimensions are not equal.)
The number of variables .
Constraint:
.
Output Parameters
- 1:
– double array
-
If
,
v is unchanged.
If
, the leading
by
part of
v stores the
by
matrix
. When
nag_opt_lsq_uncon_covariance (e04yc) is called with
following an easy-to-use function this means that
is returned, column by column, in the
elements of
w given by
. (See
Description for the definition of
.)
- 2:
– double array
-
If
,
cj returns the
diagonal elements of
.
If
,
cj returns the
elements of 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
Note: nag_opt_lsq_uncon_covariance (e04yc) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
On entry, | , |
or | , |
or | , |
or | , |
or | , |
or | . |
- W
-
The singular values are all zero, so that at the solution the Jacobian matrix has rank .
- W
-
At the solution the Jacobian matrix contains linear, or near linear, dependencies amongst its columns. In this case the required elements of
have still been computed based upon
having an assumed rank given by
. The rank is computed by regarding singular values
that are not larger than
as zero, where
is the
machine precision (see
nag_machine_precision (x02aj)). If you expect near linear dependencies at the solution and are happy with this tolerance in determining rank you should call
nag_opt_lsq_uncon_covariance (e04yc) with
in order to prevent termination. It is then essential to test the value of
ifail on exit from
nag_opt_lsq_uncon_covariance (e04yc).
-
-
If overflow occurs then either an element of is very large, or the singular values or singular 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 corresponding to a closely neighbouring Jacobian matrix .
Further Comments
When the time taken by nag_opt_lsq_uncon_covariance (e04yc) is approximately proportional to . When the time taken by the function is approximately proportional to .
Example
This example estimates the variance-covariance matrix
for the least squares estimates of
,
and
in the model
using the
sets of data given in the following table:
The program uses
as the initial guess at the position of the minimum and computes the least squares solution using
nag_opt_lsq_uncon_mod_func_easy (e04fy). See the function document
nag_opt_lsq_uncon_mod_func_easy (e04fy) for further information.
Open in the MATLAB editor:
e04yc_example
function e04yc_example
fprintf('e04yc example results\n\n');
global y t;
n = 3;
m = int64(15);
y = [0.14, 0.18, 0.22, 0.25, 0.29, 0.32, 0.35, 0.39, 0.37, ...
0.58, 0.73, 0.96, 1.34, 2.10, 4.39];
t = [1.0, 15.0, 1.0;
2.0, 14.0, 2.0;
3.0, 13.0, 3.0;
4.0, 12.0, 4.0;
5.0, 11.0, 5.0;
6.0, 10.0, 6.0;
7.0, 9.0, 7.0;
8.0, 8.0, 8.0;
9.0, 7.0, 7.0;
10.0, 6.0, 6.0;
11.0, 5.0, 5.0;
12.0, 4.0, 4.0;
13.0, 3.0, 3.0;
14.0, 2.0, 2.0;
15.0, 1.0, 1.0];
x = [0.5; 1; 1.5];
[x, fsumsq, fvec, fjac, s, v, niter, nf, user, ifail] = ...
e04fc( ...
m, @lsqfun, @lsqmon, x);
fprintf('The sum of squares is %12.4f\n', fsumsq)
fprintf('at the point\n');
fprintf('%12.4f', x);
fprintf('\n\n');
job = int64(0);
[~, cj, ifail] = e04yc(...
job, m, fsumsq, s, v);
fprintf('Estimated variances of the sample regression coefficients are:\n');
fprintf('%12.4f', cj);
fprintf('\n');
function [iflag,fvecc, user] = lsqfun(iflag, m, n, xc, user)
global y t;
fvecc = zeros(m,1);
for i=1:double(m)
fvecc(i) = xc(1) + t(i,1)/(xc(2)*t(i,2)+xc(3)*t(i,3)) - y(i);
end
function [user] = lsqmon(m, n, xc, fvecc, fjacc, ljc, ...
s, igrade, niter, nf, user)
e04yc example results
The sum of squares is 0.0082
at the point
0.0824 1.1330 2.3437
Estimated variances of the sample regression coefficients are:
0.0002 0.0948 0.0878
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015