Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_correg_linregm_update (g02dd)

Purpose

nag_correg_linregm_update (g02dd) calculates the regression parameters for a general linear regression model. It is intended to be called after nag_correg_linregm_obs_edit (g02dc), nag_correg_linregm_var_add (g02de) or nag_correg_linregm_var_del (g02df).

Syntax

[rss, idf, b, se, cov, svd, irank, p, ifail] = g02dd(n, ip, q, rss, 'tol', tol)
[rss, idf, b, se, cov, svd, irank, p, ifail] = nag_correg_linregm_update(n, ip, q, rss, 'tol', tol)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 22: n has been made optional
Mark 23: n is now a compulsory input parameter, instead of optional. p is now output only, not input/output.
.

Description

A general linear regression model fitted by nag_correg_linregm_fit (g02da) may be adjusted by adding or deleting an observation using nag_correg_linregm_obs_edit (g02dc), adding a new independent variable using nag_correg_linregm_var_add (g02de) or deleting an existing independent variable using nag_correg_linregm_var_del (g02df). Alternatively a model may be constructed by a forward selection procedure using nag_correg_linregm_fit_onestep (g02ee). These functions compute the vector c$c$ and the upper triangular matrix R$R$. nag_correg_linregm_update (g02dd) takes these basic results and computes the regression coefficients, β̂$\stackrel{^}{\beta }$, their standard errors and their variance-covariance matrix.
If R$R$ is of full rank, then β̂$\stackrel{^}{\beta }$ is the solution to
 Rβ̂ = c1, $Rβ^=c1,$
where c1${c}_{1}$ is the first p$p$ elements of c$c$.
If R$R$ is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of R$R$,
R = Q*
 ( D 0 ) 0 0
PT,
$R=Q* D 0 0 0 PT,$
where D$D$ is a k$k$ by k$k$ diagonal matrix with nonzero diagonal elements, k$k$ being the rank of R$R$, and Q*${Q}_{*}$ and P$P$ are p$p$ by p$p$ orthogonal matrices. This gives the solution
 β̂ = P1D − 1Q*1Tc1. $β^=P1D-1Q*1Tc1.$
P1${P}_{1}$ being the first k$k$ columns of P$P$, i.e., P = (P1P0)$P=\left({P}_{1}{P}_{0}\right)$, and Q*1${Q}_{{*}_{1}}$ being the first k$k$ columns of Q*${Q}_{*}$.
Details of the SVD are made available in the form of the matrix P*${P}^{*}$:
P* =
 ( D − 1 P1T ) P0T
.
$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 nag_correg_linregm_constrain (g02dk) after calling nag_correg_linregm_update (g02dd). Only certain linear combinations of the parameters will have unique estimates; these are known as estimable functions. These can be estimated using nag_correg_linregm_estfunc (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$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

Parameters

Compulsory Input Parameters

1:     n – int64int32nag_int scalar
The number of observations.
Constraint: n1${\mathbf{n}}\ge 1$.
2:     ip – int64int32nag_int scalar
p$p$, the number of terms in the regression model.
Constraint: ip1${\mathbf{ip}}\ge 1$.
3:     q(ldq,ip + 1${\mathbf{ip}}+1$) – double array
ldq, the first dimension of the array, must satisfy the constraint
• if rss0.0${\mathbf{rss}}\le 0.0$, ldqn$\mathit{ldq}\ge {\mathbf{n}}$;
• otherwise ldqip$\mathit{ldq}\ge {\mathbf{ip}}$.
Must be the array q as output by nag_correg_linregm_obs_edit (g02dc), nag_correg_linregm_var_add (g02de), nag_correg_linregm_var_del (g02df) or nag_correg_linregm_fit_onestep (g02ee). If on entry rss0.0${\mathbf{rss}}\le 0.0$ then all n elements of c$c$ are needed. This is provided by functions nag_correg_linregm_var_add (g02de), nag_correg_linregm_var_del (g02df) or nag_correg_linregm_fit_onestep (g02ee).
Either the residual sum of squares or a value less than or equal to 0.0$0.0$ to indicate that the residual sum of squares is to be calculated by the function.

Optional Input Parameters

1:     tol – double scalar
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 tol = 0.0${\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.
Default: 0.000001$0.000001$
Constraint: tol0.0${\mathbf{tol}}\ge 0.0$.

ldq wk

Output Parameters

If rss0.0${\mathbf{rss}}\le 0.0$ on entry, then on exit rss will contain the residual sum of squares as calculated by nag_correg_linregm_update (g02dd).
If rss was positive on entry, it will be unchanged.
2:     idf – int64int32nag_int scalar
The degrees of freedom associated with the residual sum of squares.
3:     b(ip) – double array
The estimates of the p$p$ parameters, β̂$\stackrel{^}{\beta }$.
4:     se(ip) – double array
The standard errors of the p$p$ parameters given in b.
5:     cov(ip × (ip + 1) / 2${\mathbf{ip}}×\left({\mathbf{ip}}+1\right)/2$) – double array
The upper triangular part of the variance-covariance matrix of the p$p$ parameter estimates given in b. They are stored packed by column, i.e., the covariance between the parameter estimate given in b(i)${\mathbf{b}}\left(i\right)$ and the parameter estimate given in b(j)${\mathbf{b}}\left(j\right)$, ji$j\ge i$, is stored in cov(j × (j1) / 2 + i)${\mathbf{cov}}\left(j×\left(j-1\right)/2+i\right)$.
6:     svd – logical scalar
If a singular value decomposition has been performed, svd = true${\mathbf{svd}}=\mathbf{true}$, otherwise svd = false${\mathbf{svd}}=\mathbf{false}$.
7:     irank – int64int32nag_int scalar
The rank of the independent variables.
If svd = false${\mathbf{svd}}=\mathbf{false}$, ${\mathbf{irank}}={\mathbf{ip}}$.
If svd = true${\mathbf{svd}}=\mathbf{true}$, irank is an estimate of the rank of the independent variables.
irank is calculated as the number of singular values greater than tol × ${\mathbf{tol}}×\text{}$ (largest singular value). It is possible for the SVD to be carried out but irank to be returned as ip.
8:     p(ip × ip + 2 × ip${\mathbf{ip}}×{\mathbf{ip}}+2×{\mathbf{ip}}$) – double array
Contains details of the singular value decomposition if used.
If svd = false${\mathbf{svd}}=\mathbf{false}$, p is not referenced.
If svd = true${\mathbf{svd}}=\mathbf{true}$, the first ip elements of p will not be referenced, the next ip values contain the singular values. The following ip × ip${\mathbf{ip}}×{\mathbf{ip}}$ values contain the matrix P*${P}^{*}$ stored by columns.
9:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, n < 1${\mathbf{n}}<1$, or ip < 1${\mathbf{ip}}<1$, or ldq < ip$\mathit{ldq}<{\mathbf{ip}}$, or ldq < n$\mathit{ldq}<{\mathbf{n}}$, or tol < 0.0${\mathbf{tol}}<0.0$.
ifail = 2${\mathbf{ifail}}=2$
The degrees of freedom for error are less than or equal to 0$0$. In this case the estimates of β$\beta$ are returned but not the standard errors or covariances.
ifail = 3${\mathbf{ifail}}=3$
The singular value decomposition, if used, has failed to converge, see nag_eigen_real_triang_svd (f02wu). This is an unlikely error exit.

Accuracy

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

None.

Example

```function nag_correg_linregm_update_example
n = int64(12);
ip = int64(4);
q = [-62.35960257517148, -1.732050807568877, 0, 0, 0;
64.60549512231913, 0, 1.732050807568877, 0, 0;
72.0590870975572, 0, -0.5773502691896258, 1.732050807568877, 0;
-65.60431108801717, 0, -0, -0.5773502691896258, -1.732050807568877;
-0.3146182873523283, 0, -0, -0, 0.5287121214812434;
-0.7278845221914594, 0, -0.5773502691896258, -0, 0.305252085661014;
-2.34461828735233, 0, -0, -0, 0.5287121214812434;
1.44536695831506, 0.4597008433809831, -0, -0, 0;
2.253195474436084, 0, -0, -0.5773502691896258, 0.1762373738270812;
2.665366958315059, 0.4597008433809831, -0, -0, 0;
-0.2368045255639181, 0, -0, -0.5773502691896258, 0.1762373738270812;
1.332115477808543, 0, -0.5773502691896258, -0, 0.305252085661014];
[rssOut, idf, b, se, covar, svd, irank, p, ifail] = nag_correg_linregm_update(n,ip, q, rss)
```
```

22.2268

idf =

8

b =

36.0033
37.3000
41.6033
37.8767

se =

0.9623
0.9623
0.9623
0.9623

covar =

0.9261
0
0.9261
0
0
0.9261
0
0
0
0.9261

svd =

0

irank =

4

p =

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

ifail =

0

```
```function g02dd_example
n = int64(12);
ip = int64(4);
q = [-62.35960257517148, -1.732050807568877, 0, 0, 0;
64.60549512231913, 0, 1.732050807568877, 0, 0;
72.0590870975572, 0, -0.5773502691896258, 1.732050807568877, 0;
-65.60431108801717, 0, -0, -0.5773502691896258, -1.732050807568877;
-0.3146182873523283, 0, -0, -0, 0.5287121214812434;
-0.7278845221914594, 0, -0.5773502691896258, -0, 0.305252085661014;
-2.34461828735233, 0, -0, -0, 0.5287121214812434;
1.44536695831506, 0.4597008433809831, -0, -0, 0;
2.253195474436084, 0, -0, -0.5773502691896258, 0.1762373738270812;
2.665366958315059, 0.4597008433809831, -0, -0, 0;
-0.2368045255639181, 0, -0, -0.5773502691896258, 0.1762373738270812;
1.332115477808543, 0, -0.5773502691896258, -0, 0.305252085661014];
[rssOut, idf, b, se, covar, svd, irank, p, ifail] = g02dd(n,ip, q, rss)
```
```

22.2268

idf =

8

b =

36.0033
37.3000
41.6033
37.8767

se =

0.9623
0.9623
0.9623
0.9623

covar =

0.9261
0
0.9261
0
0
0.9261
0
0
0
0.9261

svd =

0

irank =

4

p =

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

ifail =

0

```