g02 Chapter Contents
g02 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_regsn_mult_linear_upd_model (g02ddc)

## 1  Purpose

nag_regsn_mult_linear_upd_model (g02ddc) calculates the regression arguments for a general linear regression model. It is intended to be called after nag_regsn_mult_linear_addrem_obs (g02dcc), nag_regsn_mult_linear_add_var (g02dec) or nag_regsn_mult_linear_delete_var (g02dfc).

## 2  Specification

 #include #include
 void nag_regsn_mult_linear_upd_model (Integer n, Integer ip, const double q[], Integer tdq, double *rss, double *df, double b[], double se[], double cov[], Nag_Boolean *svd, Integer *rank, double p[], double tol, NagError *fail)

## 3  Description

A general linear regression model fitted by nag_regsn_mult_linear (g02dac) may be adjusted by adding or deleting an observation using nag_regsn_mult_linear_addrem_obs (g02dcc), adding a new independent variable using nag_regsn_mult_linear_add_var (g02dec) or deleting an existing independent variable using nag_regsn_mult_linear_delete_var (g02dfc). These functions compute the vector $c$ and the upper triangular matrix $R$. nag_regsn_mult_linear_upd_model (g02ddc) 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 β ^ = c 1 ,$
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
 $β ^ = P 1 D -1 Q * 1 T c 1$
${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_regsn_mult_linear_tran_model (g02dkc) after calling nag_regsn_mult_linear_upd_model (g02ddc). Only certain linear combinations of the arguments will have unique estimates, these are known as estimable functions. These can be estimated using nag_regsn_mult_linear_est_func (g02dnc).
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.
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  Arguments

1:    $\mathbf{n}$IntegerInput
On entry: number of observations.
Constraint: ${\mathbf{n}}\ge 1$.
2:    $\mathbf{ip}$IntegerInput
On entry: the number of terms in the regression model, $p$.
Constraint: ${\mathbf{ip}}\ge 1$.
3:    $\mathbf{q}\left[{\mathbf{n}}×{\mathbf{tdq}}\right]$const doubleInput
Note: the $\left(i,j\right)$th element of the matrix $Q$ is stored in ${\mathbf{q}}\left[\left(i-1\right)×{\mathbf{tdq}}+j-1\right]$.
On entry: q must be the array q as output by nag_regsn_mult_linear_addrem_obs (g02dcc), nag_regsn_mult_linear_add_var (g02dec) or nag_regsn_mult_linear_delete_var (g02dfc). If on entry ${\mathbf{rss}}\le 0.0$ then all n elements of $c$ are needed. This is provided by functions nag_regsn_mult_linear_add_var (g02dec) or nag_regsn_mult_linear_delete_var (g02dfc).
4:    $\mathbf{tdq}$IntegerInput
On entry: the stride separating matrix column elements in the array q.
Constraint: ${\mathbf{tdq}}\ge {\mathbf{ip}}+1$.
5:    $\mathbf{rss}$double *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 function.
On exit: if ${\mathbf{rss}}\le 0.0$ on entry, then on exit rss will contain the residual sum of squares as calculated by nag_regsn_mult_linear_upd_model (g02ddc).
If rss was positive on entry, then it will be unchanged.
6:    $\mathbf{df}$double *Output
On exit: the degrees of freedom associated with the residual sum of squares.
7:    $\mathbf{b}\left[{\mathbf{ip}}\right]$doubleOutput
On exit: the estimates of the $p$ arguments, $\stackrel{^}{\beta }$.
8:    $\mathbf{se}\left[{\mathbf{ip}}\right]$doubleOutput
On exit: the standard errors of the $p$ arguments given in b.
9:    $\mathbf{cov}\left[{\mathbf{ip}}×\left({\mathbf{ip}}+1\right)/2\right]$doubleOutput
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[\mathit{i}\right]$ and the parameter estimate given in ${\mathbf{b}}\left[\mathit{j}\right]$, $\mathit{j}\ge \mathit{i}$, is stored in ${\mathbf{cov}}\left[\mathit{j}\left(\mathit{j}+1\right)/2+\mathit{i}\right]$, for $\mathit{i}=0,1,\dots ,{\mathbf{ip}}-1$ and $\mathit{j}=\mathit{i},\dots ,{\mathbf{ip}}-1$.
10:  $\mathbf{svd}$Nag_Boolean *Output
On exit: if a singular value decomposition has been performed, then ${\mathbf{svd}}=\mathrm{Nag_TRUE}$, otherwise ${\mathbf{svd}}=\mathrm{Nag_FALSE}$.
11:  $\mathbf{rank}$Integer *Output
On exit: the rank of the independent variables.
If ${\mathbf{svd}}=\mathrm{Nag_FALSE}$, ${\mathbf{rank}}={\mathbf{ip}}$.
If ${\mathbf{svd}}=\mathrm{Nag_TRUE}$, rank is an estimate of the rank of the independent variables.
rank is calculated as the number of singular values greater than ${\mathbf{tol}}×$ (largest singular value). It is possible for the singular value decomposition to be carried out but rank to be returned as ip.
12:  $\mathbf{p}\left[{\mathbf{ip}}×{\mathbf{ip}}+2×{\mathbf{ip}}\right]$doubleOutput
On exit: p contains details of the singular value decomposition if used.
If ${\mathbf{svd}}=\mathrm{Nag_FALSE}$, p is not referenced.
If ${\mathbf{svd}}=\mathrm{Nag_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 rows.
13:  $\mathbf{tol}$doubleInput
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$, then 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{fail}$NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

## 6  Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ while ${\mathbf{ip}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{n}}\ge {\mathbf{ip}}$.
On entry, ${\mathbf{tdq}}=〈\mathit{\text{value}}〉$ while ${\mathbf{ip}}+1=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{tdq}}\ge {\mathbf{ip}}+1$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_DOF_LE_ZERO
The degrees of freedom for error are less than or equal to 0. In this case the estimates, $\stackrel{^}{\beta }$, are returned but not the standard errors or covariances.
NE_INT_ARG_LT
On entry, ${\mathbf{ip}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ip}}\ge 1$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
NE_REAL_ARG_LT
On entry, tol must not be less than 0.0: ${\mathbf{tol}}=〈\mathit{\text{value}}〉$.
NE_SVD_NOT_CONV
The singular value decomposition has failed to converge. 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.

## 8  Parallelism and Performance

nag_regsn_mult_linear_upd_model (g02ddc) is not threaded in any implementation.

None.

## 10  Example

A dataset consisting of 12 observations and four independent variables is input and a regression model fitted by calls to nag_regsn_mult_linear_add_var (g02dec). The arguments are then calculated by nag_regsn_mult_linear_upd_model (g02ddc) and the results printed.

### 10.1  Program Text

Program Text (g02ddce.c)

### 10.2  Program Data

Program Data (g02ddce.d)

### 10.3  Program Results

Program Results (g02ddce.r)