NAG Library Routine Document
G02EEF
1 Purpose
G02EEF carries out one step of a forward selection procedure in order to enable the ‘best’ linear regression model to be found.
2 Specification
SUBROUTINE G02EEF ( |
ISTEP, MEAN, WEIGHT, N, M, X, LDX, VNAME, ISX, MAXIP, Y, WT, FIN, ADDVAR, NEWVAR, CHRSS, F, MODEL, NTERM, RSS, IDF, IFR, FREE, EXSS, Q, LDQ, P, WK, IFAIL) |
INTEGER |
ISTEP, N, M, LDX, ISX(M), MAXIP, NTERM, IDF, IFR, LDQ, IFAIL |
REAL (KIND=nag_wp) |
X(LDX,M), Y(N), WT(*), FIN, CHRSS, F, RSS, EXSS(MAXIP), Q(LDQ,MAXIP+2), P(MAXIP+1), WK(2*MAXIP) |
LOGICAL |
ADDVAR |
CHARACTER(*) |
VNAME(M), NEWVAR, MODEL(MAXIP), FREE(MAXIP) |
CHARACTER(1) |
MEAN, WEIGHT |
|
3 Description
One method of selecting a linear regression model from a given set of independent variables is by forward selection. The following procedure is used:
(i) |
Select the best fitting independent variable, i.e., the independent variable which gives the smallest residual sum of squares. If the -test for this variable is greater than a chosen critical value, , then include the variable in the model, else stop. |
(ii) |
Find the independent variable that leads to the greatest reduction in the residual sum of squares when added to the current model. |
(iii) |
If the -test for this variable is greater than a chosen critical value, , then include the variable in the model and go to (ii), otherwise stop. |
At any step the variables not in the model are known as the free terms.
G02EEF allows you to specify some independent variables that must be in the model, these are known as forced variables.
The computational procedure involves the use of decompositions, the and the matrices being updated as each new variable is added to the model. In addition the matrix , where is the matrix of variables not included in the model, is updated.
G02EEF computes one step of the forward selection procedure at a call. The results produced at each step may be printed or used as inputs to
G02DDF, in order to compute the regression coefficients for the model fitted at that step. Repeated calls to G02EEF should be made until
is indicated.
4 References
Draper N R and Smith H (1985) Applied Regression Analysis (2nd Edition) Wiley
Weisberg S (1985) Applied Linear Regression Wiley
5 Parameters
Note: after the initial call to G02EEF with
all parameters except
FIN must not be changed by you between calls.
- 1: ISTEP – INTEGERInput/Output
On entry: indicates which step in the forward selection process is to be carried out.
- The process is initialized.
Constraint:
.
On exit: is incremented by .
- 2: MEAN – CHARACTER(1)Input
On entry: indicates if a mean term is to be included.
- A mean term, intercept, will be included in the model.
- The model will pass through the origin, zero-point.
Constraint:
or .
- 3: WEIGHT – 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 .
- 4: N – INTEGERInput
On entry: , the number of observations.
Constraint:
.
- 5: M – INTEGERInput
On entry: , the total number of independent variables in the dataset.
Constraint:
.
- 6: X(LDX,M) – REAL (KIND=nag_wp) arrayInput
On entry: must contain the th observation for the th independent variable, for and .
- 7: LDX – INTEGERInput
On entry: the first dimension of the array
X as declared in the (sub)program from which G02EEF is called.
Constraint:
.
- 8: VNAME(M) – CHARACTER(*) arrayInput
On entry:
must contain the name of the independent variable in column
of
X, for
.
- 9: ISX(M) – INTEGER arrayInput
On entry: indicates which independent variables could be considered for inclusion in the regression.
- The variable contained in the
th column of X is automatically included in the regression model, for .
- The variable contained in the
th column of X is considered for inclusion in the regression model, for .
- The variable in the
th column is not considered for inclusion in the model, for .
Constraint:
and at least one value of , for .
- 10: MAXIP – INTEGERInput
On entry: the maximum number of independent variables to be included in the model.
Constraints:
- if , number of values of ;
- if , number of values of .
- 11: Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the dependent variable.
- 12: WT() – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array
WT
must be at least
if
.
On entry: if
,
WT must contain the weights to be used in the weighted regression,
.
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
N.
Constraint:
if , , for .
- 13: FIN – REAL (KIND=nag_wp)Input
On entry: the critical value of the statistic for the term to be included in the model, .
Suggested value:
is a commonly used value in exploratory modelling.
Constraint:
.
- 14: ADDVAR – LOGICALOutput
On exit: indicates if a variable has been added to the model.
- A variable has been added to the model.
- No variable had an value greater than and none were added to the model.
- 15: NEWVAR – CHARACTER(*)Output
On exit: if
,
NEWVAR contains the name of the variable added to the model.
Constraint:
the declared size of
NEWVAR must be greater than or equal to the declared size of
VNAME.
On exit: if
,
CHRSS contains the change in the residual sum of squares due to adding variable
NEWVAR.
- 17: F – REAL (KIND=nag_wp)Output
On exit: if
,
F contains the
statistic for the inclusion of the variable in
NEWVAR.
- 18: MODEL(MAXIP) – CHARACTER(*) arrayInput/Output
On entry: if
,
MODEL need not be set.
If
,
MODEL must contain the values returned by the previous call to G02EEF.
Constraint:
the declared size of
MODEL must be greater than or equal to the declared size of
VNAME.
On exit: the names of the variables in the current model.
- 19: NTERM – INTEGERInput/Output
On entry: if
,
NTERM need not be set.
If
,
NTERM must contain the value returned by the previous call to G02EEF.
Constraint:
if , .
On exit: the number of independent variables in the current model, not including the mean, if any.
On entry: if
,
RSS need not be set.
If
,
RSS must contain the value returned by the previous call to G02EEF.
Constraint:
if , .
On exit: the residual sums of squares for the current model.
- 21: IDF – INTEGERInput/Output
On entry: if
,
IDF need not be set.
If
,
IDF must contain the value returned by the previous call to G02EEF.
On exit: the degrees of freedom for the residual sum of squares for the current model.
- 22: IFR – INTEGERInput/Output
On entry: if
,
IFR need not be set.
If
,
IFR must contain the value returned by the previous call to G02EEF.
On exit: the number of free independent variables, i.e., the number of variables not in the model that are still being considered for selection.
- 23: FREE(MAXIP) – CHARACTER(*) arrayInput/Output
On entry: if
,
FREE need not be set.
If
,
FREE must contain the values returned by the previous call to G02EEF.
Constraint:
the declared size of
FREE must be greater than or equal to the declared size of
VNAME.
On exit: the first
IFR values of
FREE contain the names of the free variables.
- 24: EXSS(MAXIP) – REAL (KIND=nag_wp) arrayOutput
On exit: the first
IFR values of
EXSS contain what would be the change in regression sum of squares if the free variables had been added to the model, i.e., the extra sum of squares for the free variables.
contains what would be the change in regression sum of squares if the variable
had been added to the model.
- 25: Q(LDQ,) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if
,
Q need not be set.
If
,
Q must contain the values returned by the previous call to G02EEF.
On exit: the results of the
decomposition for the current model:
- the first column of Q contains (or where is the vector of weights if used);
- the upper triangular part of columns to contain the matrix;
- the strictly lower triangular part of columns to contain details of the matrix;
- the remaining to columns of contain (or ),
where
, or
if
.
- 26: LDQ – INTEGERInput
On entry: the first dimension of the array
Q as declared in the (sub)program from which G02EEF is called.
Constraint:
.
- 27: P() – REAL (KIND=nag_wp) arrayInput/Output
On entry: if
,
P need not be set.
If
,
P must contain the values returned by the previous call to G02EEF.
On exit: the first
elements of
P contain details of the
decomposition, where
, or
if
.
- 28: WK() – REAL (KIND=nag_wp) arrayWorkspace
- 29: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL 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, if you are not familiar with this parameter, 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).
Errors or warnings detected by the routine:
On entry, | , |
or | , |
or | , |
or | , |
or | , |
or | and , |
or | and , |
or | , |
or | or , |
or | or . |
-
On entry, |
and a value of . |
On entry, the degrees of freedom will be zero if a variable is selected, i.e., the number of variables in the model plus is equal to the effective number of observations.
On entry, | a value of , |
or | there are no forced or free variables, i.e., no element of , |
or | the value of MAXIP is too small for number of variables indicated by ISX. |
On entry, the variables forced into the model are not of full rank, i.e., some of these variables are linear combinations of others.
On entry, | there are no free variables, i.e., no element of . |
The value of the change in the sum of squares is greater than the input value of
RSS. This may occur due to rounding errors if the true residual sum of squares for the new model is small relative to the residual sum of squares for the previous model.
7 Accuracy
As G02EEF uses a transformation the results will often be more accurate than traditional algorithms using methods based on the cross-products of the dependent and independent variables.
None.
9 Example
The data, from an oxygen uptake experiment, is given by
Weisberg (1985). The names of the variables are as given in
Weisberg (1985). The independent and dependent variables are read and G02EEF is repeatedly called until
. At each step the
statistic, the free variables and their extra sum of squares are printed; also, except for when
, the new variable, the change in the residual sum of squares and the terms in the model are printed.
9.1 Program Text
Program Text (g02eefe.f90)
9.2 Program Data
Program Data (g02eefe.d)
9.3 Program Results
Program Results (g02eefe.r)