hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_correg_linregm_obs_edit (g02dc)

Purpose

nag_correg_linregm_obs_edit (g02dc) adds or deletes an observation from a general regression model fitted by nag_correg_linregm_fit (g02da).

Syntax

[q, rss, ifail] = g02dc(update, mean, isx, q, x, ix, y, rss, 'm', m, 'ip', ip, 'wt', wt)
[q, rss, ifail] = nag_correg_linregm_obs_edit(update, mean, isx, q, x, ix, y, rss, 'm', m, 'ip', ip, 'wt', wt)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 22: ip has been made optional
Mark 23: weight dropped from interface, wt now optional
.

Description

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 cc and the upper triangular matrix RR 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 QRQR decomposition on the (weighted) XX matrix of independent variables. To add a new observation to a model with pp parameters, the upper triangular matrix RR and vector c1c1 (the first pp elements of cc) are augmented by the new observation on independent variables in xTxT and dependent variable ynewynew. Givens rotations are then used to restore the upper triangular form.
(R : c1)
x : ynew
(R* : c1 * )
0 : ynew *
.
R:c1 x:ynew R*:c1* 0:ynew* .
Note:  only RR and the upper part of cc are updated the remainder of the QQ matrix is unchanged.

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

Parameters

Compulsory Input Parameters

1:     update – string (length ≥ 1)
Indicates if an observation is to be added or deleted.
update = 'A'update='A'
The observation is added.
update = 'D'update='D'
The observation is deleted.
Constraint: update = 'A'update='A' or 'D''D'.
2:     mean – string (length ≥ 1)
Indicates if a mean has been used in the model.
mean = 'M'mean='M'
A mean term or intercept will have been included in the model by nag_correg_linregm_fit (g02da).
mean = 'Z'mean='Z'
A model with no mean term or intercept will have been fitted by nag_correg_linregm_fit (g02da).
Constraint: mean = 'M'mean='M' or 'Z''Z'.
3:     isx(m) – int64int32nag_int array
m, the dimension of the array, must satisfy the constraint m1m1.
If isx(j)isxj is greater than 00, the value contained in x((j1) × ix + 1)x(j-1)×ix+1 is to be included as a value of xTxT, for j = 1,2,,mj=1,2,,m.
Constraint: if mean = 'M'mean='M', exactly ip1ip-1 elements of isx must be > 0>0 and if mean = 'Z'mean='Z', exactly ip elements of isx must be > 0>0.
4:     q(ldq,ip + 1ip+1) – double array
ldq, the first dimension of the array, must satisfy the constraint ldqipldqip.
Must be array q as output by nag_correg_linregm_fit (g02da), nag_correg_linregm_var_add (g02de), nag_correg_linregm_var_del (g02df) or nag_correg_linregm_fit_onestep (g02ee), or a previous call to nag_correg_linregm_obs_edit (g02dc).
5:     x( : :) – double array
Note: the dimension of the array x must be at least (m1) × ix + 1 (m-1)×ix+1 .
The ip values for the dependent variables of the new observation, xTxT. The positions will depend on the value of ix.
6:     ix – int64int32nag_int scalar
The increment for elements of x. Two situations are common:
ix = 1ix=1
The values of xx are to be chosen from consecutive locations in x, i.e., x(1),x(2),,x(m)x1,x2,,xm.
ix = ldxix=ldx
The values of xx are to be chosen from a row of a two-dimensional array with first dimension ldx, i.e., x(1),x(ldx + 1),,x((m1)ldx + 1)x1,xldx+1,,x(m-1)ldx+1.
Constraint: ix1ix1.
7:     y – double scalar
The value of the dependent variable for the new observation, ynewynew.
8:     rss – double scalar
The value of the residual sums of squares for the original set of observations.
Constraint: rss0.0rss0.0.

Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The dimension of the array isx.
mm, the total number of independent variables in the dataset.
Constraint: m1m1.
2:     ip – int64int32nag_int scalar
Default: The first dimension of the array q.
The number of linear terms in general linear regression model (including mean if there is one).
Constraint: ip1ip1.
3:     wt – double scalar
If provided , wt must contain the weight to be used with the new observation.
If wt = 0.0wt=0.0, the observation is not included in the model.
Default: 00
Constraint: if wt0.0wt0.0, weight = 'W'weight='W'.

Input Parameters Omitted from the MATLAB Interface

weight ldq wk

Output Parameters

1:     q(ldq,ip + 1ip+1) – double array
ldqipldqip.
The first ip elements of the first column of q will contain c1 * c1* the upper triangular part of columns 22 to ip + 1ip+1 will contain R*R* the remainder is unchanged.
2:     rss – double scalar
The updated values of the residual sums of squares.
Note:  this will only be valid if the model is of full rank.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,ip < 1ip<1,
orldq < ipldq<ip,
orm < 1m<1,
orix < 1ix<1,
orrss < 0.0rss<0.0,
orupdate'A'update'A' or 'D''D',
ormean'M'mean'M' or 'Z''Z',
orweight'U'weight'U' or 'W''W',
ormean = 'M'mean='M' and there are not exactly ip1ip-1 nonzero values of isx,
ormean = 'Z'mean='Z' and there are not exactly ip nonzero values of isx,
  ifail = 2ifail=2
On entry,weight = 'W'weight='W' and wt < 0.0wt<0.0.
  ifail = 3ifail=3
The RR matrix could not be updated. This may occur if an attempt is made to delete an observation which was not in the original dataset or to add an observation to a RR matrix with a zero diagonal element. This error is also possible when removing an observation which reduces the rank of design matrix. In such cases the model should be recomputed using nag_correg_linregm_fit (g02da).
  ifail = 4ifail=4
The residual sums of squares cannot be updated. This will occur if the input residual sum of squares is less than the calculated decrease in residual sum of squares when the new observation is deleted.

Accuracy

Higher accuracy is achieved by updating the RR matrix rather than the traditional methods of updating XXXX.

Further Comments

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)

Example

function nag_correg_linregm_obs_edit_example
update = 'D';
mean_p = 'Z';
isx = [int64(1);1;1;1];
q = [-72.95, -2, -0.5, -0.5, -0.5;
     45.48298632955565, 0, 1.6583123951777, 0.4522670168666454, 0.4522670168666454;
     56.11154475279979, 0, -0.6030226891555274, 1.882937743382544, 0.2896827297511605;
     -42.04198673812751, 0, -0, -0.4963538360840667, -1.860521018838127];
x = [1; 1; 1; 1];
ix = int64(1);
y = 37.89;
rss = 5274.815851111109;
[qOut, rssOut, ifail] = nag_correg_linregm_obs_edit(update, mean_p, isx, q, x, ix, y, rss)
 

qOut =

  -62.3596   -1.7321    0.0000   -0.0000    0.0000
   52.3330         0    1.4142    0.0000   -0.0000
   72.0591         0   -0.6030    1.7321    0.0000
  -65.6043         0         0   -0.4964   -1.7321


rssOut =

   21.7046


ifail =

                    0


function g02dc_example
update = 'D';
mean_p = 'Z';
isx = [int64(1);1;1;1];
q = [-72.95, -2, -0.5, -0.5, -0.5;
     45.48298632955565, 0, 1.6583123951777, 0.4522670168666454, 0.4522670168666454;
     56.11154475279979, 0, -0.6030226891555274, 1.882937743382544, 0.2896827297511605;
     -42.04198673812751, 0, -0, -0.4963538360840667, -1.860521018838127];
x = [1; 1; 1; 1];
ix = int64(1);
y = 37.89;
rss = 5274.815851111109;
[qOut, rssOut, ifail] = g02dc(update, mean_p, isx, q, x, ix, y, rss)
 

qOut =

  -62.3596   -1.7321    0.0000   -0.0000    0.0000
   52.3330         0    1.4142    0.0000   -0.0000
   72.0591         0   -0.6030    1.7321    0.0000
  -65.6043         0         0   -0.4964   -1.7321


rssOut =

   21.7046


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013