g02dc adds or deletes an observation from a general regression model fitted by g02da.

# Syntax

C#
```public static void g02dc(
string update,
string mean,
string weight,
int m,
int[] isx,
double[,] q,
int ip,
double[] x,
int ix,
double y,
double wt,
out int ifail
)```
Visual Basic
```Public Shared Sub g02dc ( _
update As String, _
mean As String, _
weight As String, _
m As Integer, _
isx As Integer(), _
q As Double(,), _
ip As Integer, _
x As Double(), _
ix As Integer, _
y As Double, _
wt As Double, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g02dc(
String^ update,
String^ mean,
String^ weight,
int m,
array<int>^ isx,
array<double,2>^ q,
int ip,
array<double>^ x,
int ix,
double y,
double wt,
[OutAttribute] int% ifail
)```
F#
```static member g02dc :
update : string *
mean : string *
weight : string *
m : int *
isx : int[] *
q : float[,] *
ip : int *
x : float[] *
ix : int *
y : float *
wt : float *
ifail : int byref -> unit
```

#### Parameters

update
Type: System..::..String
On entry: indicates if an observation is to be added or deleted.
${\mathbf{update}}=\text{"A"}$
${\mathbf{update}}=\text{"D"}$
The observation is deleted.
Constraint: ${\mathbf{update}}=\text{"A"}$ or $\text{"D"}$.
mean
Type: System..::..String
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 g02da.
${\mathbf{mean}}=\text{"Z"}$
A model with no mean term or intercept will have been fitted by g02da.
Constraint: ${\mathbf{mean}}=\text{"M"}$ or $\text{"Z"}$.
weight
Type: System..::..String
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"}$.
m
Type: System..::..Int32
On entry: $m$, the total number of independent variables in the dataset.
Constraint: ${\mathbf{m}}\ge 1$.
isx
Type: array<System..::..Int32>[]()[][]
An array of size [m]
On entry: if ${\mathbf{isx}}\left[\mathit{j}-1\right]$ is greater than $0$, the value contained in ${\mathbf{x}}\left[\left(\mathit{j}-1\right)×{\mathbf{ix}}\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$.
q
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, ${\mathbf{ip}}+1$]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{ip}}$
On entry: must be array q as output by g02da g02de g02df (G02EEF not in this release), or a previous call to g02dc.
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.
ip
Type: System..::..Int32
On entry: the number of linear terms in general linear regression model (including mean if there is one).
Constraint: ${\mathbf{ip}}\ge 1$.
x
Type: array<System..::..Double>[]()[][]
An array of size [dim1]
Note: the dimension of the array x must be at least $\left({\mathbf{m}}-1\right)×{\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.
ix
Type: System..::..Int32
On entry: the increment for elements of x.
Constraint: ${\mathbf{ix}}\ge 1$.
y
Type: System..::..Double
On entry: the value of the dependent variable for the new observation, ${y}_{\text{new}}$.
wt
Type: System..::..Double
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"}$.
Type: System..::..Double%
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.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

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. g02dc takes the results from g02da and makes the required changes to the vector $c$ and the upper triangular matrix $R$ produced by g02da. The regression coefficients, standard errors and the variance-covariance matrix of the regression coefficients can be obtained from g02dd after all required changes to the dataset have been made.
g02da 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.
 $R:c1x:ynew→R*:c1*0:ynew*.$
Note:  only $R$ and the upper part of $c$ are updated the remainder of the $Q$ 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

# Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDQ) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{ip}}<1$, 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 g02da.
${\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}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

Higher accuracy is achieved by updating the $R$ matrix rather than the traditional methods of updating ${X}^{\prime }X$.

None.