NAG Library Function Document
nag_full_step_regsn (g02efc)
1 Purpose
nag_full_step_regsn (g02efc) calculates a full stepwise selection from variables by using Clarke's sweep algorithm on the correlation matrix of a design and data matrix, . The (weighted) variance-covariance, (weighted) means and sum of weights of must be supplied.
2 Specification
#include <nag.h> |
#include <nagg02.h> |
void |
nag_full_step_regsn (Integer m,
Integer n,
const double wmean[],
const double c[],
double sw,
Integer isx[],
double fin,
double fout,
double tau,
double b[],
double se[],
double *rsq,
double *rms,
Integer *df,
Nag_Comm *comm,
NagError *fail) |
|
3 Description
The general multiple linear regression model is defined by
where
- is a vector of observations on the dependent variable,
- is an intercept coefficient,
- is an by matrix of explanatory variables,
- is a vector of unknown coefficients, and
- is a vector of length of unknown, Normally distributed, random errors.
nag_full_step_regsn (g02efc) employs a full stepwise regression to select a subset of explanatory variables from the available variables (the intercept is included in the model) and computes regression coefficients and their standard errors, and various other statistical quantities, by minimizing the sum of squares of residuals. The method applies repeatedly a forward selection step followed by a backward elimination step and halts when neither step updates the current model.
The criterion used to update a current model is the variance ratio of residual sum of squares. Let
and
be the residual sum of squares of the current model and this model after undergoing a single update, with degrees of freedom
and
, respectively. Then the condition:
must be satisfied if a variable
will be considered for entry to the current model, and the condition:
must be satisfied if a variable
will be considered for removal from the current model, where
and
are user-supplied values and
.
In the entry step the entry statistic is computed for each variable not in the current model. If no variable is associated with a test value that exceeds then this step is terminated; otherwise the variable associated with the largest value for the entry statistic is entered into the model.
In the removal step the removal statistic is computed for each variable in the current model. If no variable is associated with a test value less than then this step is terminated; otherwise the variable associated with the smallest value for the removal statistic is removed from the model.
The data values and are not provided as input to the function. Instead, summary statistics of the design and data matrix are required.
Explanatory variables are entered into and removed from the current model by using sweep operations on the correlation matrix
of
, given by:
where
is the correlation between the explanatory variables
and
, for
and
, and
(and
) is the correlation between the response variable
and the
th explanatory variable, for
.
A sweep operation on the
th row and column (
) of
replaces:
The
th explanatory variable is eligible for entry into the current model if it satisfies the collinearity tests:
and
for a user-supplied value (
) of
and where the index
runs over explanatory variables in the current model. The sweep operation is its own inverse, therefore pivoting on an explanatory variable
in the current model has the effect of removing it from the model.
Once the stepwise model selection procedure is finished, the function calculates:
(a) |
the least squares estimate for the th explanatory variable included in the fitted model; |
(b) |
standard error estimates for each coefficient in the final model; |
(c) |
the square root of the mean square of residuals and its degrees of freedom; |
(d) |
the multiple correlation coefficient. |
The function makes use of the symmetry of the sweep operations and correlation matrix which reduces by almost one half the storage and computation required by the sweep algorithm, see
Clarke (1981) for details.
4 References
Clarke M R B (1981) Algorithm AS 178: the Gauss–Jordan sweep operator with detection of collinearity Appl. Statist. 31 166–169
Dempster A P (1969) Elements of Continuous Multivariate Analysis Addison–Wesley
Draper N R and Smith H (1985) Applied Regression Analysis (2nd Edition) Wiley
5 Arguments
- 1:
m – IntegerInput
On entry: the number of explanatory variables available in the design matrix, .
Constraint:
.
- 2:
n – IntegerInput
On entry: the number of observations used in the calculations.
Constraint:
.
- 3:
wmean[] – const doubleInput
On entry: the mean of the design matrix, .
- 4:
c[] – const doubleInput
-
Note: the dimension,
dim, of the array
c
must be at least
.
On entry: the upper-triangular variance-covariance matrix packed by column for the design matrix,
. Because the function computes the correlation matrix
from
c, the variance-covariance matrix need only be supplied up to a scaling factor.
- 5:
sw – doubleInput
On entry: if weights were used to calculate
c then
sw is the sum of positive weight values; otherwise
sw is the number of observations used to calculate
c.
Constraint:
.
- 6:
isx[m] – IntegerInput/Output
On entry: the value of
determines the set of variables used to perform full stepwise model selection, for
.
- To exclude the variable corresponding to the th column of from the final model.
- To consider the variable corresponding to the th column of for selection in the final model.
- To force the inclusion of the variable corresponding to the th column of in the final model.
Constraint:
, for .
On exit: the value of
indicates the status of the
th explanatory variable in the model.
- Forced exclusion.
- Excluded.
- Selected.
- Forced selection.
- 7:
fin – doubleInput
On entry: the value of the variance ratio which an explanatory variable must exceed to be included in a model.
Suggested value:
Constraint:
.
- 8:
fout – doubleInput
On entry: the explanatory variable in a model with the lowest variance ratio value is removed from the model if its value is less than
fout.
fout is usually set equal to the value of
fin; a value less than
fin is occasionally preferred.
Suggested value:
Constraint:
.
- 9:
tau – doubleInput
On entry: the tolerance, , for detecting collinearities between variables when adding or removing an explanatory variable from a model. Explanatory variables deemed to be collinear are excluded from the final model.
Suggested value:
Constraint:
.
- 10:
b[] – doubleOutput
On exit: contains the estimate for the intercept term in the fitted model. If then contains the estimate for the th explanatory variable in the fitted model; otherwise .
- 11:
se[] – doubleOutput
On exit: contains the standard error for the estimate of , for .
- 12:
rsq – double *Output
On exit: the -statistic for the fitted regression model.
- 13:
rms – double *Output
On exit: the mean square of residuals for the fitted regression model.
- 14:
df – Integer *Output
On exit: the number of degrees of freedom for the sum of squares of residuals.
- 15:
monfun – function, supplied by the userExternal Function
You may define your own function or specify the NAG defined default function nag_full_step_regsn_monfun (g02efh).
If this facility is not required then the NAG defined null function macro NULLFN can be substituted.
The specification of
monfun is:
void |
monfun (Nag_FullStepwise flag,
Integer var,
double val,
Nag_Comm *comm)
|
|
- 1:
flag – Nag_FullStepwiseInput
On entry: the value of
flag indicates the stage of the stepwise selection of explanatory variables.
- Variable var was added to the current model.
- Beginning the backward elimination step.
- Variable var failed the collinearity test and is excluded from the model.
- Variable var was dropped from the current model.
- Beginning the forward selection step
- Backward elimination did not remove any variables from the current model.
- Starting stepwise selection procedure.
- The variance ratio for variable var takes the value val.
- Finished stepwise selection procedure.
- 2:
var – IntegerInput
On entry: the index of the explanatory variable in the design matrix
to which
flag pertains.
- 3:
val – doubleInput
On entry: if
,
val is the variance ratio value for the coefficient associated with explanatory variable index
var.
- 4:
comm – Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to
monfun.
- user – double *
- iuser – Integer *
- p – Pointer
The type Pointer will be
void *. Before calling nag_full_step_regsn (g02efc) you may allocate memory and initialize these pointers with various quantities for use by
monfun when called from nag_full_step_regsn (g02efc) (see
Section 3.2.1.1 in the Essential Introduction).
- 16:
comm – Nag_Comm *Communication Structure
-
The NAG communication argument (see
Section 3.2.1.1 in the Essential Introduction).
- 17:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_FREE_VARS
-
No free variables from which to select.
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_ARRAY_ELEM_CONS
-
On entry, invalid value for .
- NE_INTERNAL_ERROR
-
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
- NE_MODEL_INFEASIBLE
-
All variables are collinear, no model to select.
- NE_NOT_POS_DEF
-
Matrix not positive definite, results may be inaccurate.
- NE_REAL
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_REAL_2
-
On entry, ; .
Constraint: .
- NE_ZERO_DIAG
-
On entry at least one diagonal element of .
7 Accuracy
nag_full_step_regsn (g02efc) returns a warning if the design and data matrix is not positive definite.
8 Parallelism and Performance
Not applicable.
Although the condition for removing or adding a variable to the current model is based on a ratio of variances, these values should not be interpreted as
-statistics with the usual interpretation of significance unless the probability levels are adjusted to account for correlations between variables under consideration and the number of possible updates (see, e.g.,
Draper and Smith (1985)).
nag_full_step_regsn (g02efc) allocates internally of double storage.
10 Example
This example calculates a full stepwise model selection for the Hald data described in
Dempster (1969). Means, the upper-triangular variance-covariance matrix and the sum of weights are calculated by
nag_sum_sqs (g02buc). The NAG defined default monitor function nag_full_step_regsn_monfun (g02efh) is used to print information at each step of the model selection process.
10.1 Program Text
Program Text (g02efce.c)
10.2 Program Data
Program Data (g02efce.d)
10.3 Program Results
Program Results (g02efce.r)