NAG Library Routine Document
g02def
(linregm_var_add)
1
Purpose
g02def adds a new independent variable to a general linear regression model.
2
Specification
Fortran Interface
Subroutine g02def ( |
weight,
n,
ip,
q,
ldq,
p,
wt,
x,
rss,
tol,
ifail) |
Integer, Intent (In) | :: |
n,
ip,
ldq | Integer, Intent (Inout) | :: |
ifail | Real (Kind=nag_wp), Intent (In) | :: |
wt(*),
x(n),
tol | Real (Kind=nag_wp), Intent (Inout) | :: |
q(ldq,ip+2),
p(ip+1) | Real (Kind=nag_wp), Intent (Out) | :: |
rss | Character (1), Intent (In) | :: |
weight |
|
C Header Interface
#include nagmk26.h
void |
g02def_ (
const char *weight,
const Integer *n,
const Integer *ip,
double q[],
const Integer *ldq,
double p[],
const double wt[],
const double x[],
double *rss,
const double *tol,
Integer *ifail,
const Charlen length_weight) |
|
3
Description
A linear regression model may be built up by adding new independent variables to an existing model.
g02def updates the
decomposition used in the computation of the linear regression model. The
decomposition may come from
g02daf or a previous call to
g02def. 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 , 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
g02ddf.
The routine 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: – Character(1)Input
-
On entry: indicates if weights are to be used.
- Least squares estimation is used.
- Weighted least squares is used and weights must be supplied in array wt.
Constraint:
or .
- 2: – IntegerInput
-
On entry: , the number of observations.
Constraint:
.
- 3: – IntegerInput
-
On entry: , the number of independent variables already in the model.
Constraint:
and .
- 4: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: if
,
q must contain the results of the
decomposition for the model with
arguments as returned by
g02daf or a previous call to
g02def.
If
, 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 to are unchanged;
- the first elements of column contain the new column of , while the remaining elements contain details of the matrix .
- 5: – IntegerInput
-
On entry: the first dimension of the array
q as declared in the (sub)program from which
g02def is called.
Constraint:
.
- 6: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: contains further details of the
decomposition used. The first
ip elements of
p must contain the zeta values for the
decomposition (see
f08aef (dgeqrf) for details).
The first
ip elements of array
p are provided by
g02daf or by previous calls to
g02def.
On exit: the first
ip elements of
p are unchanged and the
th element contains the zeta value for
.
- 7: – Real (Kind=nag_wp) arrayInput
-
Note: the dimension of the array
wt
must be at least
if
, and at least
otherwise.
On entry: if
,
wt must contain the weights to be used.
If , 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
,
wt is not referenced and the effective number of observations is
.
Constraint:
if , , for .
- 8: – Real (Kind=nag_wp) arrayInput
-
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.
- 10: – Real (Kind=nag_wp)Input
-
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:
.
- 11: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Note: g02def may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
-
On entry, .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: or .
-
On entry, .
Constraint: , for .
-
x variable is a linear combination of existing model terms.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The accuracy is closely related to the accuracy of
f08agf (dormqr) which should be consulted for further details.
8
Parallelism and Performance
g02def is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g02def makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
It should be noted that the residual sum of squares produced by
g02def may not be correct if the model to which the new independent variable is added is not of full rank. In such a case
g02ddf should be used to calculate the residual sum of squares.
10
Example
A dataset consisting of
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
indicates that a mean should be included in the model a variable taking the value
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
. After the variable has been added the parameter estimates are calculated by
g02ddf and the results printed. This is repeated until the input value of
is
.
10.1
Program Text
Program Text (g02defe.f90)
10.2
Program Data
Program Data (g02defe.d)
10.3
Program Results
Program Results (g02defe.r)