# NAG FL Interfaceg02ddf (linregm_​update)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g02ddf calculates the regression parameters for a general linear regression model. It is intended to be called after g02dcf, g02def or g02dff.

## 2Specification

Fortran Interface
 Subroutine g02ddf ( n, ip, q, ldq, rss, idf, b, se, cov, svd, p, tol, wk,
 Integer, Intent (In) :: n, ip, ldq Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: idf, irank Real (Kind=nag_wp), Intent (In) :: q(ldq,ip+1), tol Real (Kind=nag_wp), Intent (Inout) :: rss, p(ip*ip+2*ip) Real (Kind=nag_wp), Intent (Out) :: b(ip), se(ip), cov(ip*(ip+1)/2), wk(ip*ip+(ip-1)*5) Logical, Intent (Out) :: svd
#include <nag.h>
 void g02ddf_ (const Integer *n, const Integer *ip, const double q[], const Integer *ldq, double *rss, Integer *idf, double b[], double se[], double cov[], logical *svd, Integer *irank, double p[], const double *tol, double wk[], Integer *ifail)
The routine may be called by the names g02ddf or nagf_correg_linregm_update.

## 3Description

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×k$ diagonal matrix with nonzero diagonal elements, $k$ being the rank of $R$, and ${Q}_{*}$ and $P$ are $p×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.

## 4References

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

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: the number of observations.
Constraint: ${\mathbf{n}}\ge 1$.
2: $\mathbf{ip}$Integer Input
On entry: $p$, the number of terms in the regression model.
Constraint: ${\mathbf{ip}}\ge 1$.
3: $\mathbf{q}\left({\mathbf{ldq}},{\mathbf{ip}}+1\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{ldq}$Integer Input
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: $\mathbf{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: $\mathbf{idf}$Integer Output
On exit: the degrees of freedom associated with the residual sum of squares.
7: $\mathbf{b}\left({\mathbf{ip}}\right)$Real (Kind=nag_wp) array Output
On exit: the estimates of the $p$ parameters, $\stackrel{^}{\beta }$.
8: $\mathbf{se}\left({\mathbf{ip}}\right)$Real (Kind=nag_wp) array Output
On exit: the standard errors of the $p$ parameters given in b.
9: $\mathbf{cov}\left({\mathbf{ip}}×\left({\mathbf{ip}}+1\right)/2\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{svd}$Logical Output
On exit: if a singular value decomposition has been performed, ${\mathbf{svd}}=\mathrm{.TRUE.}$, otherwise ${\mathbf{svd}}=\mathrm{.FALSE.}$.
11: $\mathbf{irank}$Integer Output
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: $\mathbf{p}\left({\mathbf{ip}}×{\mathbf{ip}}+2×{\mathbf{ip}}\right)$Real (Kind=nag_wp) array Input/Output
On entry: must be array p as output by g02daf, g02def or g02eef, or a previous call to g02ddf.
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 are unchanged, the next ip values contain the singular values. The following ${\mathbf{ip}}×{\mathbf{ip}}$ values contain the matrix ${P}^{*}$ stored by columns.
13: $\mathbf{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: $\mathbf{wk}\left({\mathbf{ip}}×{\mathbf{ip}}+\left({\mathbf{ip}}-1\right)×5\right)$Real (Kind=nag_wp) array Workspace
15: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ip}}\ge 1$.
On entry, ${\mathbf{ldq}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ip}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{rss}}\le 0.0$, ${\mathbf{ldq}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{ldq}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ip}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldq}}\ge {\mathbf{ip}}$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.
On entry, ${\mathbf{tol}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{tol}}\ge 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$
SVD solution failed to converge.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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.

## 8Parallelism and Performance

g02ddf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g02ddf 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 implementation-specific information.

None.

## 10Example

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.

### 10.1Program Text

Program Text (g02ddfe.f90)

### 10.2Program Data

Program Data (g02ddfe.d)

### 10.3Program Results

Program Results (g02ddfe.r)