NAG FL Interface
g02eaf (linregm_rssq)
1
Purpose
g02eaf calculates the residual sums of squares for all possible linear regressions for a given set of independent variables.
2
Specification
Fortran Interface
Subroutine g02eaf ( |
mean, weight, n, m, x, ldx, vname, isx, y, wt, nmod, modl, ldmodl, rss, nterms, mrank, wk, ifail) |
Integer, Intent (In) |
:: |
n, m, ldx, isx(m), ldmodl |
Integer, Intent (Inout) |
:: |
ifail |
Integer, Intent (Out) |
:: |
nmod, nterms(ldmodl), mrank(ldmodl) |
Real (Kind=nag_wp), Intent (In) |
:: |
x(ldx,m), y(n), wt(*) |
Real (Kind=nag_wp), Intent (Out) |
:: |
rss(ldmodl), wk(n*(m+1)) |
Character (*), Intent (In) |
:: |
vname(m) |
Character (*), Intent (Inout) |
:: |
modl(ldmodl,m) |
Character (1), Intent (In) |
:: |
mean, weight |
|
C Header Interface
#include <nag.h>
void |
g02eaf_ (const char *mean, const char *weight, const Integer *n, const Integer *m, const double x[], const Integer *ldx, const char vname[], const Integer isx[], const double y[], const double wt[], Integer *nmod, char modl[], const Integer *ldmodl, double rss[], Integer nterms[], Integer mrank[], double wk[], Integer *ifail, const Charlen length_mean, const Charlen length_weight, const Charlen length_vname, const Charlen length_modl) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
g02eaf_ (const char *mean, const char *weight, const Integer &n, const Integer &m, const double x[], const Integer &ldx, const char vname[], const Integer isx[], const double y[], const double wt[], Integer &nmod, char modl[], const Integer &ldmodl, double rss[], Integer nterms[], Integer mrank[], double wk[], Integer &ifail, const Charlen length_mean, const Charlen length_weight, const Charlen length_vname, const Charlen length_modl) |
}
|
The routine may be called by the names g02eaf or nagf_correg_linregm_rssq.
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
Arguments
-
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:
– Integer
Input
-
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:
– Integer
Input
-
On entry: the number of variables contained in
x.
Constraint:
.
-
5:
– Real (Kind=nag_wp) array
Input
-
On entry: must contain the th observation for the th independent variable, for and .
-
6:
– Integer
Input
-
On entry: the first dimension of the array
x as declared in the (sub)program from which
g02eaf is called.
Constraint:
.
-
7:
– Character(*) array
Input
-
On entry:
must contain the name of the variable in column
of
x, for
.
-
8:
– Integer array
Input
-
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) array
Input
-
On entry: must contain the th observation on the dependent variable, , for .
-
10:
– Real (Kind=nag_wp) array
Input
-
Note: the dimension of the array
wt
must be at least
if
.
On entry: if
wt must contain the weights to be used with the model.
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 .
-
11:
– Integer
Output
-
On exit: the total number of models for which residual sums of squares have been calculated.
-
12:
– Character(*) array
Output
-
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:
– Integer
Input
-
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.
Constraint:
,
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 array
Output
-
On exit: contains the number of independent variables in the th model, not including the mean if one is fitted, for .
-
16:
– Integer array
Output
-
On exit: contains the rank of the residual sum of squares for the th model.
-
17:
– Real (Kind=nag_wp) array
Workspace
-
-
18:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or 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, and .
Constraint: .
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: or .
On entry, .
Constraint: .
On entry, .
Constraint: or .
-
On entry, .
Constraint: , for .
-
On entry, .
Constraint: , for .
There are no free variables, i.e., no element of .
-
On entry, and number of possible models is .
Constraint: the number of possible models.
-
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 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface 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
10.2
Program Data
10.3
Program Results