NAG Library Function Document
nag_regsn_mult_linear_add_var (g02dec)
1 Purpose
nag_regsn_mult_linear_add_var (g02dec) adds a new independent variable to a general linear regression model.
2 Specification
#include <nag.h> |
#include <nagg02.h> |
void |
nag_regsn_mult_linear_add_var (Integer n,
Integer ip,
double q[],
Integer tdq,
double p[],
const double wt[],
const double x[],
double *rss,
double tol,
NagError *fail) |
|
3 Description
A linear regression model may be built up by adding new independent variables to an existing model. nag_regsn_mult_linear_add_var (g02dec) updates the
decomposition used in the computation of the linear regression model. The
decomposition may come from
nag_regsn_mult_linear (g02dac) or a previous call to nag_regsn_mult_linear_add_var (g02dec). The general linear regression model is defined by:
where
is a vector of
observations on the dependent variable,
is an
by
matrix of the independent variables of column rank
,
is a vector of length
of unknown arguments, and
is a vector of length
of unknown random errors such that var
, where
is a known diagonal matrix.
If , the identity matrix, then least squares estimation is used.
If , then for a given weight matrix , weighted least squares estimation is used.
The least squares estimates, of the arguments minimize while the weighted least squares estimates minimize .
The parameter estimates may be found by computing a
decomposition of
(or
in the weighted case), i.e.,
where
and
is a
by
upper triangular matrix and
is an
by
orthogonal matrix. If
is of full rank, then
is the solution to:
where
(or
) and
is the first
elements of
.
If is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of .
To add a new independent variable, , and have to be updated. The matrix is found such that (or ) is upper triangular. The vector is then updated by multiplying by .
The new independent variable is tested to see if it is linearly related to the existing independent variables by checking that at least one of the values , for is nonzero.
The new parameter estimates,
, can then be obtained by a call to
nag_regsn_mult_linear_upd_model (g02ddc).
The function can be used with , in which case and are initialized.
4 References
Draper N R and Smith H (1985) Applied Regression Analysis (2nd Edition) Wiley
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
McCullagh P and Nelder J A (1983) Generalized Linear Models Chapman and Hall
Searle S R (1971) Linear Models Wiley
5 Arguments
- 1:
– IntegerInput
-
On entry: the number of observations, .
Constraint:
.
- 2:
– IntegerInput
-
On entry: the number of independent variables already in the model, .
Constraint:
and .
- 3:
– doubleInput/Output
-
Note: the th element of the matrix is stored in .
On entry: if
, then
q must contain the results of the
decomposition for the model with
arguments as returned by
nag_regsn_mult_linear (g02dac) or a previous call to nag_regsn_mult_linear_add_var (g02dec).
If
, then the first column of
q should contain the
values of the dependent variable,
.
On exit: the results of the
decomposition for the model with
arguments: the first column of
q contains the updated value of
, the columns 2 to
are unchanged, the first
elements of column
contain the new column of
R, while the remaining
elements contain details of the matrix
.
- 4:
– IntegerInput
-
On entry: the stride separating matrix column elements in the array
q.
Constraint:
.
- 5:
– doubleInput/Output
-
On entry:
p contains further details of the
decomposition used. The first
ip elements of
p
must contain details of the Householder vector from the
decomposition. The first
ip elements of array
p are provided by
nag_regsn_mult_linear (g02dac) or by previous calls to nag_regsn_mult_linear_add_var (g02dec).
On exit: the first
ip elements of
p are unchanged and the (
)th element contains details of the Householder vector related to the new independent variable.
- 6:
– const doubleInput
-
On entry: optionally, the weights to be used in the weighted regression.
If , then the th observation is not included in the model, in which case the effective number of observations is the number of observations with nonzero weights.
If weights are not provided then
wt must be set to
NULL and the effective number of observations is
n.
Constraint:
if , , for .
- 7:
– const doubleInput
-
On entry: the new independent variable, .
-
On exit: the residual sum of squares for the new fitted model.
Note: this will only be valid if the model is of full rank, see
Section 9.
- 9:
– doubleInput
-
On entry: the value of
tol is used to decide if the new independent variable is linearly related to independent variables already included in the model. If the new variable is linearly related then
is not updated. The smaller the value of
tol the stricter the criterion for deciding if there is a linear relationship.
Suggested value:
.
Constraint:
.
- 10:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_2_INT_ARG_GE
-
On entry, while . These arguments must satisfy .
- NE_2_INT_ARG_LT
-
On entry, while . These arguments must satisfy .
- NE_INT_ARG_LT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_NVAR_NOT_IND
-
The new independent variable is a linear combination of existing variables. The
th column of
q is, therefore,
NULL.
- NE_REAL_ARG_LE
-
On entry,
tol must not be less than or equal to 0.0:
.
- NE_REAL_ARG_LT
-
On entry, must not be less than 0.0: .
7 Accuracy
The accuracy is closely related to the accuracy of the decomposition.
8 Parallelism and Performance
Not applicable.
It should be noted that the residual sum of squares produced by nag_regsn_mult_linear_add_var (g02dec) may not be correct if the model to which the new independent variable is added is not of full rank. In such a case
nag_regsn_mult_linear_upd_model (g02ddc) should be used to calculate the residual sum of squares.
10 Example
A dataset consisting of 12 observations is read in. The four independent variables are stored in the array
x while the dependent variable is read into the first column of
q. If the character variable
meanc indicates that a mean should be included in the model, a variable taking the value 1.0 for all observations is set up and fitted. Subsequently, one variable at a time is selected to enter the model as indicated by the input value of
indx. After the variable has been added the parameter estimates are calculated by
nag_regsn_mult_linear_upd_model (g02ddc) and the results printed. This is repeated until the input value of
indx is 0.
10.1 Program Text
Program Text (g02dece.c)
10.2 Program Data
Program Data (g02dece.d)
10.3 Program Results
Program Results (g02dece.r)