g02dd calculates the regression parameters for a general linear regression model. It is intended to be called after g02dcg02de or g02df.

# Syntax

C#
```public static void g02dd(
int n,
int ip,
double[,] q,
out int idf,
double[] b,
double[] se,
double[] cov,
out bool svd,
out int irank,
double[] p,
double tol,
out int ifail
)```
Visual Basic
```Public Shared Sub g02dd ( _
n As Integer, _
ip As Integer, _
q As Double(,), _
<OutAttribute> ByRef idf As Integer, _
b As Double(), _
se As Double(), _
cov As Double(), _
<OutAttribute> ByRef svd As Boolean, _
<OutAttribute> ByRef irank As Integer, _
p As Double(), _
tol As Double, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g02dd(
int n,
int ip,
array<double,2>^ q,
[OutAttribute] int% idf,
array<double>^ b,
array<double>^ se,
array<double>^ cov,
[OutAttribute] bool% svd,
[OutAttribute] int% irank,
array<double>^ p,
double tol,
[OutAttribute] int% ifail
)```
F#
```static member g02dd :
n : int *
ip : int *
q : float[,] *
idf : int byref *
b : float[] *
se : float[] *
cov : float[] *
svd : bool byref *
irank : int byref *
p : float[] *
tol : float *
ifail : int byref -> unit
```

#### Parameters

n
Type: System..::..Int32
On entry: the number of observations.
Constraint: ${\mathbf{n}}\ge 1$.
ip
Type: System..::..Int32
On entry: $p$, the number of terms in the regression model.
Constraint: ${\mathbf{ip}}\ge 1$.
q
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, ${\mathbf{ip}}+1$]
Note: dim1 must satisfy the constraint:
• if ${\mathbf{rss}}\le 0.0$, $\mathrm{dim1}\ge {\mathbf{n}}$;
• otherwise $\mathrm{dim1}\ge {\mathbf{ip}}$.
On entry: must be the array q as output by g02dc g02de g02df (G02EEF not in this release). If on entry ${\mathbf{rss}}\le 0.0$ then all n elements of $c$ are needed. This is provided by methods g02de g02df (G02EEF not in this release).
Type: System..::..Double%
On entry: either the residual sum of squares or a value less than or equal to $0.0$ to indicate that the residual sum of squares is to be calculated by the method.
On exit: if ${\mathbf{rss}}\le 0.0$ on entry, then on exit rss will contain the residual sum of squares as calculated by g02dd.
If rss was positive on entry, it will be unchanged.
idf
Type: System..::..Int32%
On exit: the degrees of freedom associated with the residual sum of squares.
b
Type: array<System..::..Double>[]()[][]
An array of size [ip]
On exit: the estimates of the $p$ parameters, $\stackrel{^}{\beta }$.
se
Type: array<System..::..Double>[]()[][]
An array of size [ip]
On exit: the standard errors of the $p$ parameters given in b.
cov
Type: array<System..::..Double>[]()[][]
An array of size [${\mathbf{ip}}×\left({\mathbf{ip}}+1\right)/2$]
On exit: the upper triangular part of the variance-covariance matrix of the $p$ parameter estimates given in b. They are stored packed by column, i.e., the covariance between the parameter estimate given in ${\mathbf{b}}\left[i-1\right]$ and the parameter estimate given in ${\mathbf{b}}\left[j-1\right]$, $j\ge i$, is stored in ${\mathbf{cov}}\left[j×\left(j-1\right)/2+i-1\right]$.
svd
Type: System..::..Boolean%
On exit: if a singular value decomposition has been performed, ${\mathbf{svd}}=\mathrm{true}$, otherwise ${\mathbf{svd}}=\mathrm{false}$.
irank
Type: System..::..Int32%
On exit: the rank of the independent variables.
If ${\mathbf{svd}}=\mathrm{false}$, ${\mathbf{irank}}={\mathbf{ip}}$.
If ${\mathbf{svd}}=\mathrm{true}$, irank is an estimate of the rank of the independent variables.
irank is calculated as the number of singular values greater than ${\mathbf{tol}}×\text{}$ (largest singular value). It is possible for the SVD to be carried out but irank to be returned as ip.
p
Type: array<System..::..Double>[]()[][]
An array of size [${\mathbf{ip}}×{\mathbf{ip}}+2×{\mathbf{ip}}$]
On exit: contains details of the singular value decomposition if used.
If ${\mathbf{svd}}=\mathrm{false}$, p is not referenced.
If ${\mathbf{svd}}=\mathrm{true}$, the first ip elements of p will not be referenced, the next ip values contain the singular values. The following ${\mathbf{ip}}×{\mathbf{ip}}$ values contain the matrix ${P}^{*}$ stored by columns.
tol
Type: System..::..Double
On entry: the value of tol is used to decide if the independent variables are of full rank and, if not, what is the rank of the independent variables. The smaller the value of tol the stricter the criterion for selecting the singular value decomposition. If ${\mathbf{tol}}=0.0$, the singular value decomposition will never be used, this may cause run time errors or inaccuracies if the independent variables are not of full rank.
Suggested value: ${\mathbf{tol}}=0.000001$.
Constraint: ${\mathbf{tol}}\ge 0.0$.
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

A general linear regression model fitted by g02da may be adjusted by adding or deleting an observation using g02dc, adding a new independent variable using g02de or deleting an existing independent variable using g02df. Alternatively a model may be constructed by a forward selection procedure using (G02EEF not in this release). These methods compute the vector $c$ and the upper triangular matrix $R$. g02dd takes these basic results and computes the regression coefficients, $\stackrel{^}{\beta }$, their standard errors and their variance-covariance matrix.
If $R$ is of full rank, then $\stackrel{^}{\beta }$ is the solution to
 $Rβ^=c1,$
where ${c}_{1}$ is the first $p$ elements of $c$.
If $R$ is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of $R$,
 $R=Q*D000PT,$
where $D$ is a $k$ by $k$ diagonal matrix with nonzero diagonal elements, $k$ being the rank of $R$, and ${Q}_{*}$ and $P$ are $p$ by $p$ orthogonal matrices. This gives the solution
 $β^=P1D-1Q*1Tc1.$
${P}_{1}$ being the first $k$ columns of $P$, i.e., $P=\left({P}_{1}{P}_{0}\right)$, and ${Q}_{{*}_{1}}$ being the first $k$ columns of ${Q}_{*}$.
Details of the SVD are made available in the form of the matrix ${P}^{*}$:
 $P*=D-1P1TP0T.$
This will be only one of the possible solutions. Other estimates may be obtained by applying constraints to the parameters. These solutions can be obtained by calling g02dk after calling g02dd. Only certain linear combinations of the parameters will have unique estimates; these are known as estimable functions. These can be estimated using g02dn.
The residual sum of squares required to calculate the standard errors and the variance-covariance matrix can either be input or can be calculated if additional information on $c$ for the whole sample is provided.

# 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
Searle S R (1971) Linear Models Wiley

# 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{n}}<1$, or ${\mathbf{ip}}<1$, or ${\mathbf{tol}}<0.0$.
${\mathbf{ifail}}=2$
The degrees of freedom for error are less than or equal to $0$. In this case the estimates of $\beta$ are returned but not the standard errors or covariances.
${\mathbf{ifail}}=3$
The singular value decomposition, if used, has failed to converge, see (F02WUF not in this release). This is an unlikely error exit.
${\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

The accuracy of the results will depend on the accuracy of the input $R$ matrix, which may lose accuracy if a large number of observations or variables have been dropped.

None.