NAG Library Routine Document
G02DEF adds a new independent variable to a general linear regression model.
|SUBROUTINE G02DEF (
||WEIGHT, N, IP, Q, LDQ, P, WT, X, RSS, TOL, IFAIL)
||N, IP, LDQ, IFAIL
||Q(LDQ,IP+2), P(IP+1), WT(*), X(N), RSS, TOL
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
|| 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 parameters,
|| 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 parameters minimize while the weighted least squares estimates, minimize .
The parameter estimates may be found by computing a
in the weighted case), i.e.,
upper triangular matrix and
is of full rank, then
is the solution to
is the first
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.
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
- 1: WEIGHT – CHARACTER(1)Input
: 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.
- 2: N – INTEGERInput
On entry: , the number of observations.
- 3: IP – INTEGERInput
On entry: , the number of independent variables already in the model.
- 4: Q(LDQ,) – REAL (KIND=nag_wp) arrayInput/Output
must contain the results of the
decomposition for the model with
parameters as returned by G02DAF
or a previous call to G02DEF.
, the first column of Q
should contain the
values of the dependent variable,
: the results of the
decomposition for the model with
- 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: LDQ – INTEGERInput
: the first dimension of the array Q
as declared in the (sub)program from which G02DEF is called.
- 6: P() – REAL (KIND=nag_wp) arrayInput/Output
: contains further details of the
decomposition used. The first IP
elements of P
must contain the zeta values for the
decomposition (see F08AEF (DGEQRF)
The first IP
elements of array P
are provided by G02DAF
or by previous calls to G02DEF.
: the first IP
elements of P
are unchanged and the
th element contains the zeta value for
- 7: WT() – REAL (KIND=nag_wp) arrayInput
the dimension of the array WT
must be at least
, and at least
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.
is not referenced and the effective number of observations is
if , , for .
- 8: X(N) – REAL (KIND=nag_wp) arrayInput
On entry: , the new independent variable.
: the residual sum of squares for the new fitted model.
this will only be valid if the model is of full rank, see Section 8
- 10: TOL – REAL (KIND=nag_wp)Input
: 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.
- 11: IFAIL – INTEGERInput/Output
must be set to
. If you are unfamiliar with this parameter you should refer to Section 3.3
in the Essential Introduction 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 parameters 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.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, 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:
|or|| or .|
and a value of .|
The new independent variable is a linear combination of existing variables. The
th column of Q
will therefore be null.
The accuracy is closely related to the accuracy of F08AGF (DORMQR)
which should be consulted for further details.
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.
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
9.1 Program Text
Program Text (g02defe.f90)
9.2 Program Data
Program Data (g02defe.d)
9.3 Program Results
Program Results (g02defe.r)