g02 Chapter Contents
g02 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_regsn_mult_linear_delete_var (g02dfc)

## 1  Purpose

nag_regsn_mult_linear_delete_var (g02dfc) deletes an independent variable from a general linear regression model.

## 2  Specification

 #include #include
 void nag_regsn_mult_linear_delete_var (Integer ip, double q[], Integer tdq, Integer indx, double *rss, NagError *fail)

## 3  Description

When selecting a linear regression model it is sometimes useful to drop independent variables from the model and to examine the resulting sub-model. nag_regsn_mult_linear_delete_var (g02dfc) updates the $QR$ decomposition used in the computation of the linear regression model. The $QR$ decomposition may come from nag_regsn_mult_linear (g02dac), nag_regsn_mult_linear_addrem_obs (g02dcc), nag_regsn_mult_linear_add_var (g02dec) or a previous call to nag_regsn_mult_linear_delete_var (g02dfc).
For the general linear regression model with $p$ independent variables fitted, nag_regsn_mult_linear (g02dac) or nag_regsn_mult_linear_add_var (g02dec) computes a $QR$ decomposition of the (weighted) independent variables and forms an upper triangular matrix $R$ and a vector $c$. To remove an independent variable $R$ and $c$ have to be updated. The column of $R$ corresponding to the variable to be dropped is removed and the matrix is then restored to upper triangular form by applying a series of Givens rotations. The rotations are then applied to $c$. Note that only the first $p$ elements of $c$ are affected.
The method used means that while the updated values of $R$ and $c$ are computed an updated value of $Q$ from the $QR$ decomposition is not available so a call to nag_regsn_mult_linear_add_var (g02dec) cannot be made after a call to nag_regsn_mult_linear_delete_var (g02dfc).
nag_regsn_mult_linear_upd_model (g02ddc) can be used to calculate the parameter estimates, $\stackrel{^}{\beta }$, from the information provided by nag_regsn_mult_linear_delete_var (g02dfc).

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

## 5  Arguments

1:     ipIntegerInput
On entry: the number of independent variables already in the model, $p$.
Constraint: ${\mathbf{ip}}\ge 1$.
2:     q[${\mathbf{ip}}×{\mathbf{tdq}}$]doubleInput/Output
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: the results of the $QR$ decomposition as returned by nag_regsn_mult_linear (g02dac), nag_regsn_mult_linear_addrem_obs (g02dcc), nag_regsn_mult_linear_add_var (g02dec) or previous calls to nag_regsn_mult_linear_delete_var (g02dfc).
On exit: the updated $QR$ decomposition. The first ip elements of the first column of q contain the updated value of $c$, the upper triangular part of columns 2 to ip contain the updated $R$ matrix.
3:     tdqIntegerInput
On entry: the stride separating matrix column elements in the array q.
Constraint: ${\mathbf{tdq}}\ge {\mathbf{ip}}+1$.
4:     indxIntegerInput
On entry: indicates which independent variable is to be deleted from the model.
Constraint: $1\le {\mathbf{indx}}\le {\mathbf{ip}}$.
On entry: the residual sum of squares for the full regression.
Constraint: ${\mathbf{rss}}\ge 0.0$.
On exit: the residual sum of squares with the (indx)th variable removed. Note that the residual sum of squares will only be valid if the regression is of full rank.
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_INT_ARG_GT
On entry, ${\mathbf{indx}}=〈\mathit{\text{value}}〉$ while ${\mathbf{ip}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{indx}}\le {\mathbf{ip}}$.
NE_2_INT_ARG_LT
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_DIAG_ELEM_ZERO
On entry, a diagonal element, $〈\mathit{\text{value}}〉$, of $R$ is zero.
NE_INT_ARG_LT
On entry, ${\mathbf{indx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{indx}}\ge 1$.
On entry, ${\mathbf{ip}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ip}}\ge 1$.
NE_REAL_ARG_LT
On entry, rss must not be less than 0.0: ${\mathbf{rss}}=〈\mathit{\text{value}}〉$.

## 7  Accuracy

There will inevitably be some loss in accuracy in fitting a model by dropping terms from a more complex model rather than fitting it afresh using nag_regsn_mult_linear (g02dac).

None.

## 9  Example

A dataset consisting of 12 observations on four independent variables and one dependent variable is read in. The full model, including a mean term, is fitted using nag_regsn_mult_linear (g02dac). The value of indx is read in and that variable dropped from the regression. The parameter estimates are calculated by nag_regsn_mult_linear_upd_model (g02ddc) and printed. This process is repeated until indx is 0.

### 9.1  Program Text

Program Text (g02dfce.c)

### 9.2  Program Data

Program Data (g02dfce.d)

### 9.3  Program Results

Program Results (g02dfce.r)