NAG Library Routine Document
G02DCF
1 Purpose
G02DCF adds or deletes an observation from a general regression model fitted by
G02DAF.
2 Specification
SUBROUTINE G02DCF ( 
UPDATE, MEAN, WEIGHT, M, ISX, Q, LDQ, IP, X, IX, Y, WT, RSS, WK, IFAIL) 
INTEGER 
M, ISX(M), LDQ, IP, IX, IFAIL 
REAL (KIND=nag_wp) 
Q(LDQ,IP+1), X(*), Y, WT, RSS, WK(3*IP) 
CHARACTER(1) 
UPDATE, MEAN, WEIGHT 

3 Description
G02DAF 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. G02DCF takes the results from
G02DAF and makes the required changes to the vector
$c$ and the upper triangular matrix
$R$ produced by
G02DAF. The regression coefficients, standard errors and the variancecovariance matrix of the regression coefficients can be obtained from
G02DDF after all required changes to the dataset have been made.
G02DAF performs a
$QR$ decomposition on the (weighted)
$X$ matrix of independent variables. To add a new observation to a model with
$p$ parameters, the upper triangular matrix
$R$ and vector
${c}_{1}$ (the first
$p$ elements of
$c$) are augmented by the new observation on independent variables in
${x}^{\mathrm{T}}$ and dependent variable
${y}_{\text{new}}$. Givens rotations are then used to restore the upper triangular form.
Note: only
$R$ and the upper part of
$c$ are updated the remainder of the
$Q$ matrix is unchanged.
4 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
5 Parameters
 1: $\mathrm{UPDATE}$ – CHARACTER(1)Input

On entry: indicates if an observation is to be added or deleted.
 ${\mathbf{UPDATE}}=\text{'A'}$
 The observation is added.
 ${\mathbf{UPDATE}}=\text{'D'}$
 The observation is deleted.
Constraint:
${\mathbf{UPDATE}}=\text{'A'}$ or $\text{'D'}$.
 2: $\mathrm{MEAN}$ – CHARACTER(1)Input

On entry: indicates if a mean has been used in the model.
 ${\mathbf{MEAN}}=\text{'M'}$
 A mean term or intercept will have been included in the model by G02DAF.
 ${\mathbf{MEAN}}=\text{'Z'}$
 A model with no mean term or intercept will have been fitted by G02DAF.
Constraint:
${\mathbf{MEAN}}=\text{'M'}$ or $\text{'Z'}$.
 3: $\mathrm{WEIGHT}$ – CHARACTER(1)Input

On entry: indicates if a weight is to be used.
 ${\mathbf{WEIGHT}}=\text{'U'}$
 The new observation is unweighted.
 ${\mathbf{WEIGHT}}=\text{'W'}$
 The new observation is to be weighted and the weight must be supplied in WT.
Constraint:
${\mathbf{WEIGHT}}=\text{'U'}$ or $\text{'W'}$.
 4: $\mathrm{M}$ – INTEGERInput

On entry: $m$, the total number of independent variables in the dataset.
Constraint:
${\mathbf{M}}\ge 1$.
 5: $\mathrm{ISX}\left({\mathbf{M}}\right)$ – INTEGER arrayInput

On entry: if
${\mathbf{ISX}}\left(\mathit{j}\right)$ is greater than $0$, the value contained in ${\mathbf{X}}\left(\left(\mathit{j}1\right)\times {\mathbf{IX}}+1\right)$ is to be included as a value of ${x}^{\mathrm{T}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{M}}$.
Constraint:
if
${\mathbf{MEAN}}=\text{'M'}$, exactly
${\mathbf{IP}}1$ elements of
ISX must be
$\text{}>0$ and if
${\mathbf{MEAN}}=\text{'Z'}$, exactly
IP elements of
ISX must be
$\text{}>0$.
 6: $\mathrm{Q}\left({\mathbf{LDQ}},{\mathbf{IP}}+1\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On entry: must be array
Q as output by
G02DAF,
G02DEF,
G02DFF or
G02EEF, or a previous call to G02DCF.
On exit: the first
IP elements of the first column of
Q will contain
${c}_{1}^{*}$ the upper triangular part of columns
$2$ to
${\mathbf{IP}}+1$ will contain
${R}^{*}$ the remainder is unchanged.
 7: $\mathrm{LDQ}$ – INTEGERInput

On entry: the first dimension of the array
Q as declared in the (sub)program from which G02DCF is called.
Constraint:
${\mathbf{LDQ}}\ge {\mathbf{IP}}$.
 8: $\mathrm{IP}$ – INTEGERInput

On entry: the number of linear terms in general linear regression model (including mean if there is one).
Constraint:
${\mathbf{IP}}\ge 1$.
 9: $\mathrm{X}\left(*\right)$ – REAL (KIND=nag_wp) arrayInput

Note: the dimension of the array
X
must be at least
$\left({\mathbf{M}}1\right)\times {\mathbf{IX}}+1$.
On entry: the
IP values for the dependent variables of the new observation,
${x}^{\mathrm{T}}$. The positions will depend on the value of
IX.
 10: $\mathrm{IX}$ – INTEGERInput

On entry: the increment for elements of
X.
Two situations are common:
 ${\mathbf{IX}}=1$
 The values of $x$ are to be chosen from consecutive locations in X, i.e., ${\mathbf{X}}\left(1\right),{\mathbf{X}}\left(2\right),\dots ,{\mathbf{X}}\left({\mathbf{M}}\right)$.
 ${\mathbf{IX}}={\mathbf{LDX}}$
 The values of $x$ are to be chosen from a row of a twodimensional array with first dimension LDX, i.e., ${\mathbf{X}}\left(1\right),{\mathbf{X}}\left({\mathbf{LDX}}+1\right),\dots ,{\mathbf{X}}\left(\left({\mathbf{M}}1\right){\mathbf{LDX}}+1\right)$.
Constraint:
${\mathbf{IX}}\ge 1$.
 11: $\mathrm{Y}$ – REAL (KIND=nag_wp)Input

On entry: the value of the dependent variable for the new observation, ${y}_{\text{new}}$.
 12: $\mathrm{WT}$ – REAL (KIND=nag_wp)Input

On entry: if
${\mathbf{WEIGHT}}=\text{'W'}$ ,
WT must contain the weight to be used with the new observation.
If ${\mathbf{WT}}=0.0$, the observation is not included in the model.
If
${\mathbf{WEIGHT}}=\text{'U'}$,
WT is not referenced.
Constraint:
if ${\mathbf{WT}}\ge 0.0$, ${\mathbf{WEIGHT}}=\text{'W'}$.

On entry: the value of the residual sums of squares for the original set of observations.
Constraint:
${\mathbf{RSS}}\ge 0.0$.
On exit: the updated values of the residual sums of squares.
Note: this will only be valid if the model is of full rank.
 14: $\mathrm{WK}\left(3\times {\mathbf{IP}}\right)$ – REAL (KIND=nag_wp) arrayWorkspace

 15: $\mathrm{IFAIL}$ – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
$0$.
When the value $\mathbf{1}\text{ or}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$

On entry,  ${\mathbf{IP}}<1$, 
or  ${\mathbf{LDQ}}<{\mathbf{IP}}$, 
or  ${\mathbf{M}}<1$, 
or  ${\mathbf{IX}}<1$, 
or  ${\mathbf{RSS}}<0.0$, 
or  ${\mathbf{UPDATE}}\ne \text{'A'}$ or $\text{'D'}$, 
or  ${\mathbf{MEAN}}\ne \text{'M'}$ or $\text{'Z'}$, 
or  ${\mathbf{WEIGHT}}\ne \text{'U'}$ or $\text{'W'}$, 
or  ${\mathbf{MEAN}}=\text{'M'}$ and there are not exactly ${\mathbf{IP}}1$ nonzero values of ISX, 
or  ${\mathbf{MEAN}}=\text{'Z'}$ and there are not exactly IP nonzero values of ISX, 
 ${\mathbf{IFAIL}}=2$

On entry,  ${\mathbf{WEIGHT}}=\text{'W'}$ and ${\mathbf{WT}}<0.0$. 
 ${\mathbf{IFAIL}}=3$

The
$R$ 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
$R$ 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
G02DAF.
 ${\mathbf{IFAIL}}=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.
 ${\mathbf{IFAIL}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
 ${\mathbf{IFAIL}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
 ${\mathbf{IFAIL}}=999$
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
Higher accuracy is achieved by updating the $R$ matrix rather than the traditional methods of updating ${X}^{\prime}X$.
8 Parallelism and Performance
G02DCF is not threaded by NAG in any implementation.
G02DCF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementationspecific information.
Care should be taken with the use of G02DCF.
(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 G02DAF. 
(c) 
Adding or deleting observations can alter the rank of the model. Such changes will only be detected when a call to G02DDF has been made. G02DDF should also be used to compute the new residual sum of squares when the model is not of full rank. 
G02DCF may also be used after
G02DEF,
G02DFF and
G02EEF.
10 Example
A dataset consisting of
$12$ observations with four independent variables is read in and a general linear regression model fitted by
G02DAF and parameter estimates printed. The last observation is then dropped and the parameter estimates recalculated, using
G02DDF, and printed. Finally a new observation is added and new parameter estimates computed and printed.
10.1 Program Text
Program Text (g02dcfe.f90)
10.2 Program Data
Program Data (g02dcfe.d)
10.3 Program Results
Program Results (g02dcfe.r)