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 arguments 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, covar, svd, irank, p, ifail] = g02dd(n, ip, q, rss, 'tol', tol)
[rss, idf, b, se, covar, 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:
 At Mark 23: n was made a compulsory input parameter; p was made output only At Mark 22: n was made optional

## 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$ and the upper triangular matrix $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$ 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 arguments. 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 arguments 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$ 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:     $\mathrm{n}$int64int32nag_int scalar
The number of observations.
Constraint: ${\mathbf{n}}\ge 1$.
2:     $\mathrm{ip}$int64int32nag_int scalar
$p$, the number of terms in the regression model.
Constraint: ${\mathbf{ip}}\ge 1$.
3:     $\mathrm{q}\left(\mathit{ldq},{\mathbf{ip}}+1\right)$ – double array
ldq, the first dimension of the array, must satisfy the constraint
• if ${\mathbf{rss}}\le 0.0$, $\mathit{ldq}\ge {\mathbf{n}}$;
• otherwise $\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 ${\mathbf{rss}}\le 0.0$ then all n elements of $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).
4:     $\mathrm{rss}$ – double scalar
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 function.

### Optional Input Parameters

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

### Output Parameters

1:     $\mathrm{rss}$ – double scalar
If ${\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:     $\mathrm{idf}$int64int32nag_int scalar
The degrees of freedom associated with the residual sum of squares.
3:     $\mathrm{b}\left({\mathbf{ip}}\right)$ – double array
The estimates of the $p$ parameters, $\stackrel{^}{\beta }$.
4:     $\mathrm{se}\left({\mathbf{ip}}\right)$ – double array
The standard errors of the $p$ parameters given in b.
5:     $\mathrm{covar}\left({\mathbf{ip}}×\left({\mathbf{ip}}+1\right)/2\right)$ – double array
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{covar}}\left(j×\left(j-1\right)/2+i\right)$.
6:     $\mathrm{svd}$ – logical scalar
If a singular value decomposition has been performed, ${\mathbf{svd}}=\mathit{true}$, otherwise ${\mathbf{svd}}=\mathit{false}$.
7:     $\mathrm{irank}$int64int32nag_int scalar
The rank of the independent variables.
If ${\mathbf{svd}}=\mathit{false}$, ${\mathbf{irank}}={\mathbf{ip}}$.
If ${\mathbf{svd}}=\mathit{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.
8:     $\mathrm{p}\left({\mathbf{ip}}×{\mathbf{ip}}+2×{\mathbf{ip}}\right)$ – double array
Contains details of the singular value decomposition if used.
If ${\mathbf{svd}}=\mathit{false}$, p is not referenced.
If ${\mathbf{svd}}=\mathit{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.
9:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}<1$, or ${\mathbf{ip}}<1$, or $\mathit{ldq}<{\mathbf{ip}}$, or $\mathit{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 nag_eigen_real_triang_svd (f02wu). This is an unlikely error exit.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

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

## Example

A dataset consisting of $12$ observations and four independent variables is input and a regression model fitted by calls to nag_correg_linregm_var_add (g02de). The arguments are then calculated by nag_correg_linregm_update (g02dd) and the results printed.
```function g02dd_example

fprintf('g02dd example results\n\n');

x = [1, 0, 0, 0;
0, 0, 0, 1;
0, 1, 0, 0;
0, 0, 1, 0;
0, 0, 0, 1;
0, 1, 0, 0;
0, 0, 0, 1;
1, 0, 0, 0;
0, 0, 1, 0;
1, 0, 0, 0;
0, 0, 1, 0;
0, 1, 0, 0];
y = [33.63;     39.62;     38.18;     41.46;     38.02;     35.83;
35.99;     36.58;     42.92;     37.80;     40.43;     37.89];

[n,m]  = size(x);
isx    = ones(m,1,'int64');
ip     = int64(0);
q      = zeros(n,m+1);
lp     = (m*(m+1))/2;
p      = zeros(lp,1);
q(:,1) = y;

% Fit general linear regression model, adding each variable in turn
for j = 1:m
[q, p, rss, ifail] = g02de( ...
ip, q, p, x(:,j));
ip = ip + 1;
end

[rss, idf, b, se, covar, svd, irank, p, ifail] = ...

% Display results
if svd
fprintf('Model not of full rank, rank = %4d\n\n', irank);
end
fprintf('Residual sum of squares = %12.4e\n', rss);
fprintf('Degrees of freedom      = %4d\n', idf);
fprintf('\nVariable   Parameter estimate   Standard error\n\n');
ivar = double([1:ip]');
fprintf('%6d%20.4e%20.4e\n',[ivar b se]');

```
```g02dd example results

Residual sum of squares =   2.2227e+01
Degrees of freedom      =    8

Variable   Parameter estimate   Standard error

1          3.6003e+01          9.6235e-01
2          3.7300e+01          9.6235e-01
3          4.1603e+01          9.6235e-01
4          3.7877e+01          9.6235e-01
```