PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_correg_linregm_update (g02dd)
Purpose
nag_correg_linregm_update (g02dd) calculates the regression arguments for a general linear regression model. It is intended to be called after
nag_correg_linregm_obs_edit (g02dc),
nag_correg_linregm_var_add (g02de) or
nag_correg_linregm_var_del (g02df).
Syntax
[
rss,
idf,
b,
se,
covar,
svd,
irank,
p,
ifail] = g02dd(
n,
ip,
q,
rss, 'tol',
tol)
[
rss,
idf,
b,
se,
covar,
svd,
irank,
p,
ifail] = nag_correg_linregm_update(
n,
ip,
q,
rss, 'tol',
tol)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: |
n was made a compulsory input parameter; p was made output only |
At Mark 22: |
n was made optional |
Description
A general linear regression model fitted by
nag_correg_linregm_fit (g02da) may be adjusted by adding or deleting an observation using
nag_correg_linregm_obs_edit (g02dc), adding a new independent variable using
nag_correg_linregm_var_add (g02de) or deleting an existing independent variable using
nag_correg_linregm_var_del (g02df). Alternatively a model may be constructed by a forward selection procedure using
nag_correg_linregm_fit_onestep (g02ee). These functions compute the vector
and the upper triangular matrix
.
nag_correg_linregm_update (g02dd) takes these basic results and computes the regression coefficients,
, their standard errors and their variance-covariance matrix.
If
is of full rank, then
is the solution to
where
is the first
elements of
.
If
is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of
,
where
is a
by
diagonal matrix with nonzero diagonal elements,
being the rank of
, and
and
are
by
orthogonal matrices. This gives the solution
being the first
columns of
, i.e.,
, and
being the first
columns of
.
Details of the SVD are made available in the form of the matrix
:
This will be only one of the possible solutions. Other estimates may be obtained by applying constraints to the arguments. These solutions can be obtained by calling
nag_correg_linregm_constrain (g02dk) after calling
nag_correg_linregm_update (g02dd). Only certain linear combinations of the arguments will have unique estimates; these are known as estimable functions. These can be estimated using
nag_correg_linregm_estfunc (g02dn).
The residual sum of squares required to calculate the standard errors and the variance-covariance matrix can either be input or can be calculated if additional information on for the whole sample is provided.
References
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Hammarling S (1985) The singular value decomposition in multivariate statistics SIGNUM Newsl. 20(3) 2–25
Searle S R (1971) Linear Models Wiley
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
The number of observations.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
, the number of terms in the regression model.
Constraint:
.
- 3:
– double array
-
ldq, the first dimension of the array, must satisfy the constraint
- if , ;
- otherwise .
-
Either the residual sum of squares or a value less than or equal to to indicate that the residual sum of squares is to be calculated by the function.
Optional Input Parameters
- 1:
– double scalar
Default:
The value of
tol is used to decide if the independent variables are of full rank and, if not, what is the rank of the independent variables. The smaller the value of
tol the stricter the criterion for selecting the singular value decomposition. If
, the singular value decomposition will never be used, this may cause run time errors or inaccuracies if the independent variables are not of full rank.
Constraint:
.
Output Parameters
-
If
on entry, then on exit
rss will contain the residual sum of squares as calculated by
nag_correg_linregm_update (g02dd).
If
rss was positive on entry, it will be unchanged.
- 2:
– int64int32nag_int scalar
-
The degrees of freedom associated with the residual sum of squares.
- 3:
– double array
-
The estimates of the parameters, .
- 4:
– double array
-
The standard errors of the
parameters given in
b.
- 5:
– double array
-
The upper triangular part of the variance-covariance matrix of the
parameter estimates given in
b. They are stored packed by column, i.e., the covariance between the parameter estimate given in
and the parameter estimate given in
,
, is stored in
.
- 6:
– logical scalar
-
If a singular value decomposition has been performed, , otherwise .
- 7:
– int64int32nag_int scalar
-
The rank of the independent variables.
If , .
If
,
irank is an estimate of the rank of the independent variables.
irank is calculated as the number of singular values greater than
(largest singular value). It is possible for the SVD to be carried out but
irank to be returned as
ip.
- 8:
– double array
-
Contains details of the singular value decomposition if used.
If
,
p is not referenced.
If
, the first
ip elements of
p will not be referenced, the next
ip values contain the singular values. The following
values contain the matrix
stored by columns.
- 9:
– 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 | . |
-
-
The degrees of freedom for error are less than or equal to . In this case the estimates of are returned but not the standard errors or covariances.
-
-
The singular value decomposition, if used, has failed to converge, see
nag_eigen_real_triang_svd (f02wu). This is an unlikely error exit.
-
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 accuracy of the results will depend on the accuracy of the input matrix, which may lose accuracy if a large number of observations or variables have been dropped.
Further Comments
None.
Example
A dataset consisting of
observations and four independent variables is input and a regression model fitted by calls to
nag_correg_linregm_var_add (g02de). The arguments are then calculated by
nag_correg_linregm_update (g02dd) and the results printed.
Open in the MATLAB editor:
g02dd_example
function g02dd_example
fprintf('g02dd example results\n\n');
x = [1, 0, 0, 0;
0, 0, 0, 1;
0, 1, 0, 0;
0, 0, 1, 0;
0, 0, 0, 1;
0, 1, 0, 0;
0, 0, 0, 1;
1, 0, 0, 0;
0, 0, 1, 0;
1, 0, 0, 0;
0, 0, 1, 0;
0, 1, 0, 0];
y = [33.63; 39.62; 38.18; 41.46; 38.02; 35.83;
35.99; 36.58; 42.92; 37.80; 40.43; 37.89];
[n,m] = size(x);
isx = ones(m,1,'int64');
ip = int64(0);
q = zeros(n,m+1);
lp = (m*(m+1))/2;
p = zeros(lp,1);
q(:,1) = y;
for j = 1:m
[q, p, rss, ifail] = g02de( ...
ip, q, p, x(:,j));
ip = ip + 1;
end
rss = 0;
[rss, idf, b, se, covar, svd, irank, p, ifail] = ...
g02dd(int64(n), ip, q, rss);
if svd
fprintf('Model not of full rank, rank = %4d\n\n', irank);
end
fprintf('Residual sum of squares = %12.4e\n', rss);
fprintf('Degrees of freedom = %4d\n', idf);
fprintf('\nVariable Parameter estimate Standard error\n\n');
ivar = double([1:ip]');
fprintf('%6d%20.4e%20.4e\n',[ivar b se]');
g02dd example results
Residual sum of squares = 2.2227e+01
Degrees of freedom = 8
Variable Parameter estimate Standard error
1 3.6003e+01 9.6235e-01
2 3.7300e+01 9.6235e-01
3 4.1603e+01 9.6235e-01
4 3.7877e+01 9.6235e-01
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015