nag_correg_linregm_obs_edit (g02dc) adds or deletes an observation from a general regression model fitted by
nag_correg_linregm_fit (g02da).
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: |
weight was removed from the interface; wt was made optional |
At Mark 22: |
ip was made optional |
nag_correg_linregm_fit (g02da) fits a general linear regression model to a dataset. You may wish to change the model by either adding or deleting an observation from the dataset.
nag_correg_linregm_obs_edit (g02dc) takes the results from
nag_correg_linregm_fit (g02da) and makes the required changes to the vector
and the upper triangular matrix
produced by
nag_correg_linregm_fit (g02da). The regression coefficients, standard errors and the variance-covariance matrix of the regression coefficients can be obtained from
nag_correg_linregm_update (g02dd) after all required changes to the dataset have been made.
nag_correg_linregm_fit (g02da) performs a
decomposition on the (weighted)
matrix of independent variables. To add a new observation to a model with
arguments, the upper triangular matrix
and vector
(the first
elements of
) are augmented by the new observation on independent variables in
and dependent variable
. Givens rotations are then used to restore the upper triangular form.
Note: only
and the upper part of
are updated the remainder of the
matrix is unchanged.
Hammarling S (1985) The singular value decomposition in multivariate statistics SIGNUM Newsl. 20(3) 2–25
Care should be taken with the use of
nag_correg_linregm_obs_edit (g02dc).
(a) |
It is possible to delete observations which were not included in the original model. |
(b) |
If several additions/deletions have been performed you are advised to recompute the regression using nag_correg_linregm_fit (g02da). |
(c) |
Adding or deleting observations can alter the rank of the model. Such changes will only be detected when a call to nag_correg_linregm_update (g02dd) has been made. nag_correg_linregm_update (g02dd) should also be used to compute the new residual sum of squares when the model is not of full rank. |
nag_correg_linregm_obs_edit (g02dc) may also be used after
nag_correg_linregm_var_add (g02de),
nag_correg_linregm_var_del (g02df) and
nag_correg_linregm_fit_onestep (g02ee)
A dataset consisting of
observations with four independent variables is read in and a general linear regression model fitted by
nag_correg_linregm_fit (g02da) and parameter estimates printed. The last observation is then dropped and the parameter estimates recalculated, using
nag_correg_linregm_update (g02dd), and printed. Finally a new observation is added and new parameter estimates computed and printed.
function g02dc_example
fprintf('g02dc 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;
1, 1, 1, 1];
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');
mean_p = 'Z';
ip = int64(m);
[rss, idf, b, se, covar, res, h, q, svd, irank, p, wk, ifail] = ...
g02da(mean_p, x, isx, ip, y);
fprintf('Results from initial model fit using g02da\n\n');
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]');
action = {'dropping'; 'adding'};
xobs = [1 1 1 1;
0 1 0 0];
yobs = [37.89;
37.89];
nobs = numel(yobs);
ix = int64(1);
for j = 1:nobs
[q, rss, ifail] = g02dc( ...
action{j}, mean_p, isx, q, xobs(j,:), ix, ...
yobs(j), rss, 'ip', ip);
if strcmp(action{j},'adding')
n = n + 1;
else
n = n - 1;
end
[rss, idf, b, se, covar, svd, irank, p, ifail] = ...
g02dd(int64(n), ip, q, rss);
fprintf('\nResults from %s an observation\n',action{j});
fprintf('Residual sum of squares = %12.4e\n', rss);
fprintf('Degrees of freedom = %4d\n', idf);
fprintf('\nVariable Parameter estimate Standard error\n\n');
fprintf('%6d%20.4e%20.4e\n',[ivar b se]');
end