# 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, ref double rss, 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, _ ByRef rss 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, double% rss, [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 * rss : float byref * 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"}$
- The observation is added.
- ${\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.*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)\times {\mathbf{ix}}\right]$ is to be included as a value of ${x}^{\mathrm{T}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{m}}$.

- 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}}$

- 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)\times {\mathbf{ix}}+1$.

- 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"}$.

- rss
- 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.

$$\left(\begin{array}{l}R:{c}_{1}\\ x:{y}_{\text{new}}\end{array}\right)\to \left(\begin{array}{l}{R}^{*}:{c}_{1}^{*}\\ 0:{y}_{\text{new}}^{*}\end{array}\right)\text{.}$$ |

**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, BaltimoreHammarling 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 $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-4000$
- Invalid dimension for array $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-8000$
- Negative dimension for array $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-6000$
- Invalid Parameters $\u2329\mathit{\text{value}}\u232a$

# Accuracy

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

# Parallelism and Performance

None.

# Further Comments

Care should be taken with the use of g02dc.

g02dc may also be used after

(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 g02da. |

(c) | Adding or deleting observations can alter the rank of the model. Such changes will only be detected when a call to g02dd has been made. g02dd should also be used to compute the new residual sum of squares when the model is not of full rank. |

**g02de****g02df**(G02EEF not in this release).