G02DDF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG02DDF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G02DDF calculates the regression parameters for a general linear regression model. It is intended to be called after G02DCF, G02DEF or G02DFF.

## 2  Specification

 SUBROUTINE G02DDF ( N, IP, Q, LDQ, RSS, IDF, B, SE, COV, SVD, IRANK, P, TOL, WK, IFAIL)
 INTEGER N, IP, LDQ, IDF, IRANK, IFAIL REAL (KIND=nag_wp) Q(LDQ,IP+1), RSS, B(IP), SE(IP), COV(IP*(IP+1)/2), P(IP*IP+2*IP), TOL, WK(IP*IP+(IP-1)*5) LOGICAL SVD

## 3  Description

A general linear regression model fitted by G02DAF may be adjusted by adding or deleting an observation using G02DCF, adding a new independent variable using G02DEF or deleting an existing independent variable using G02DFF. Alternatively a model may be constructed by a forward selection procedure using G02EEF. These routines compute the vector $c$ and the upper triangular matrix $R$. G02DDF 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* D 0 0 0 PT,$
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-1 P1T P0T .$
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 G02DKF after calling G02DDF. Only certain linear combinations of the parameters will have unique estimates; these are known as estimable functions. These can be estimated using G02DNF.
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.

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

## 5  Parameters

1:     N – INTEGERInput
On entry: the number of observations.
Constraint: ${\mathbf{N}}\ge 1$.
2:     IP – INTEGERInput
On entry: $p$, the number of terms in the regression model.
Constraint: ${\mathbf{IP}}\ge 1$.
3:     Q(LDQ,${\mathbf{IP}}+1$) – REAL (KIND=nag_wp) arrayInput
On entry: must be the array Q as output by G02DCF, G02DEF, G02DFF or G02EEF. If on entry ${\mathbf{RSS}}\le 0.0$ then all N elements of $c$ are needed. This is provided by routines G02DEF, G02DFF or G02EEF.
4:     LDQ – INTEGERInput
On entry: the first dimension of the array Q as declared in the (sub)program from which G02DDF is called.
Constraints:
• if ${\mathbf{RSS}}\le 0.0$, ${\mathbf{LDQ}}\ge {\mathbf{N}}$;
• otherwise ${\mathbf{LDQ}}\ge {\mathbf{IP}}$.
5:     RSS – REAL (KIND=nag_wp)Input/Output
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 routine.
On exit: if ${\mathbf{RSS}}\le 0.0$ on entry, then on exit RSS will contain the residual sum of squares as calculated by G02DDF.
If RSS was positive on entry, it will be unchanged.
6:     IDF – INTEGEROutput
On exit: the degrees of freedom associated with the residual sum of squares.
7:     B(IP) – REAL (KIND=nag_wp) arrayOutput
On exit: the estimates of the $p$ parameters, $\stackrel{^}{\beta }$.
8:     SE(IP) – REAL (KIND=nag_wp) arrayOutput
On exit: the standard errors of the $p$ parameters given in B.
9:     COV(${\mathbf{IP}}×\left({\mathbf{IP}}+1\right)/2$) – REAL (KIND=nag_wp) arrayOutput
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\right)$ and the parameter estimate given in ${\mathbf{B}}\left(j\right)$, $j\ge i$, is stored in ${\mathbf{COV}}\left(j×\left(j-1\right)/2+i\right)$.
10:   SVD – LOGICALOutput
On exit: if a singular value decomposition has been performed, ${\mathbf{SVD}}=\mathrm{.TRUE.}$, otherwise ${\mathbf{SVD}}=\mathrm{.FALSE.}$.
11:   IRANK – INTEGEROutput
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.
12:   P(${\mathbf{IP}}×{\mathbf{IP}}+2×{\mathbf{IP}}$) – REAL (KIND=nag_wp) arrayOutput
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.
13:   TOL – REAL (KIND=nag_wp)Input
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$.
14:   WK(${\mathbf{IP}}×{\mathbf{IP}}+\left({\mathbf{IP}}-1\right)×5$) – REAL (KIND=nag_wp) arrayWorkspace
15:   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{N}}<1$, or ${\mathbf{IP}}<1$, or ${\mathbf{LDQ}}<{\mathbf{IP}}$, or ${\mathbf{LDQ}}<{\mathbf{N}}$, 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. This is an unlikely error exit.

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

## 9  Example

A dataset consisting of $12$ observations and four independent variables is input and a regression model fitted by calls to G02DEF. The parameters are then calculated by G02DDF and the results printed.

### 9.1  Program Text

Program Text (g02ddfe.f90)

### 9.2  Program Data

Program Data (g02ddfe.d)

### 9.3  Program Results

Program Results (g02ddfe.r)

G02DDF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual