NAG Library Routine Document
G02EAF
1 Purpose
G02EAF calculates the residual sums of squares for all possible linear regressions for a given set of independent variables.
2 Specification
SUBROUTINE G02EAF ( |
MEAN, WEIGHT, N, M, X, LDX, VNAME, ISX, Y, WT, NMOD, MODL, LDMODL, RSS, NTERMS, MRANK, WK, IFAIL) |
INTEGER |
N, M, LDX, ISX(M), NMOD, LDMODL, NTERMS(LDMODL), MRANK(LDMODL), IFAIL |
REAL (KIND=nag_wp) |
X(LDX,M), Y(N), WT(*), RSS(LDMODL), WK(N*(M+1)) |
CHARACTER(*) |
VNAME(M), MODL(LDMODL,M) |
CHARACTER(1) |
MEAN, WEIGHT |
|
3 Description
For a set of
possible independent variables there are
linear regression models with from zero to
independent variables in each model. For example if
and the variables are
,
and
then the possible models are:
(i) |
null model |
(ii) |
|
(iii) |
|
(iv) |
|
(v) |
and |
(vi) |
and |
(vii) |
and |
(viii) |
, and . |
G02EAF calculates the residual sums of squares from each of the
possible models. The method used involves a
decomposition of the matrix of possible independent variables. Independent variables are then moved into and out of the model by a series of Givens rotations and the residual sums of squares computed for each model; see
Clark (1981) and
Smith and Bremner (1989).
The computed residual sums of squares are then ordered first by increasing number of terms in the model, then by decreasing size of residual sums of squares. So the first model will always have the largest residual sum of squares and the th will always have the smallest. This aids you in selecting the best possible model from the given set of independent variables.
G02EAF allows you to specify some independent variables that must be in the model, the forced variables. The other independent variables from which the possible models are to be formed are the free variables.
4 References
Clark M R B (1981) A Givens algorithm for moving from one linear model to another without going back to the data Appl. Statist. 30 198–203
Smith D M and Bremner J M (1989) All possible subset regressions using the decomposition Comput. Statist. Data Anal. 7 217–236
Weisberg S (1985) Applied Linear Regression Wiley
5 Parameters
- 1: – 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 .
- 2: – 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 .
- 3: – INTEGERInput
-
On entry: , the number of observations.
Constraints:
- ;
- , is the number of independent variables to be considered (forced plus free plus mean if included), as specified by MEAN and ISX.
- 4: – INTEGERInput
-
On entry: the number of variables contained in
X.
Constraint:
.
- 5: – REAL (KIND=nag_wp) arrayInput
-
On entry: must contain the th observation for the th independent variable, for and .
- 6: – INTEGERInput
-
On entry: the first dimension of the array
X as declared in the (sub)program from which G02EAF is called.
Constraint:
.
- 7: – CHARACTER(*) arrayInput
-
On entry:
must contain the name of the variable in column
of
X, for
.
- 8: – INTEGER arrayInput
-
On entry: indicates which independent variables are to be considered in the model.
- The variable contained in the th column of X is included in all regression models, i.e., is a forced variable.
- The variable contained in the th column of X is included in the set from which the regression models are chosen, i.e., is a free variable.
- The variable contained in the th column of X is not included in the models.
Constraints:
- , for ;
- at least one value of .
- 9: – REAL (KIND=nag_wp) arrayInput
-
On entry: must contain the th observation on the dependent variable, , for .
- 10: – 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 .
- 11: – INTEGEROutput
-
On exit: the total number of models for which residual sums of squares have been calculated.
- 12: – CHARACTER(*) arrayOutput
-
On exit: the first
elements of the
th row of
MODL contain the names of the independent variables, as given in
VNAME, that are included in the
th model.
Constraint:
the length of
MODL should be greater or equal to the length of
VNAME.
- 13: – INTEGERInput
-
On entry: the first dimension of the array
MODL and the dimension of the arrays
RSS,
NTERMS and
MRANK as declared in the (sub)program from which G02EAF is called.
Constraints:
- ;
- , is the number of free variables in the model as specified in ISX, and hence is the total number of models to be generated.
-
On exit: contains the residual sum of squares for the th model, for .
- 15: – INTEGER arrayOutput
-
On exit: contains the number of independent variables in the th model, not including the mean if one is fitted, for .
- 16: – INTEGER arrayOutput
-
On exit: contains the rank of the residual sum of squares for the th model.
- 17: – REAL (KIND=nag_wp) arrayWorkspace
-
- 18: – 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 , |
or | or . |
-
On entry, |
and a value of . |
-
On entry, | a value of , |
or | there are no free variables, i.e., no element of . |
-
On entry,
the number of possible models
, where
is the number of free independent variables from
ISX.
-
On entry, the number of independent variables to be considered (forced plus free plus mean if included) is greater or equal to the effective number of observations.
-
The full model is not of full rank, i.e., some of the independent variables may be linear combinations of other independent variables. Variables must be excluded from the model in order to give full rank.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
For a discussion of the improved accuracy obtained by using a method based on the
decomposition see
Smith and Bremner (1989).
8 Parallelism and Performance
G02EAF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02EAF 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.
G02ECF may be used to compute
and
-values from the results of G02EAF.
If a mean has been included in the model and no variables are forced in then contains the total sum of squares and in many situations a reasonable estimate of the variance of the errors is given by .
10 Example
The data for this example is given in
Weisberg (1985). The independent variables and the dependent variable are read, as are the names of the variables. These names are as given in
Weisberg (1985). The residual sums of squares computed and printed with the names of the variables in the model.
10.1 Program Text
Program Text (g02eafe.f90)
10.2 Program Data
Program Data (g02eafe.d)
10.3 Program Results
Program Results (g02eafe.r)