# naginterfaces.library.correg.linregm_​fit_​stepwise¶

naginterfaces.library.correg.linregm_fit_stepwise(n, wmean, c, sw, isx, fin=4.0, fout=None, tau=1e-06, monlev=0, monfun=None, data=None, io_manager=None)[source]

linregm_fit_stepwise 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.

For full information please refer to the NAG Library document for g02ef

https://www.nag.com/numeric/nl/nagdoc_27.1/flhtml/g02/g02eff.html

Parameters
nint

The number of observations used in the calculations.

wmeanfloat, array-like, shape

The mean of the design matrix, .

cfloat, array-like, shape

The upper-triangular variance-covariance matrix packed by column for the design matrix, . Because the function computes the correlation matrix from , the variance-covariance matrix need only be supplied up to a scaling factor.

swfloat

If weights were used to calculate then is the sum of positive weight values; otherwise is the number of observations used to calculate .

isxint, array-like, shape

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.

finfloat, optional

The value of the variance ratio which an explanatory variable must exceed to be included in a model.

foutNone or float, optional

Note: if this argument is None then a default value will be used, determined as follows: .

The explanatory variable in a model with the lowest variance ratio value is removed from the model if its value is less than . is usually set equal to the value of ; a value less than is occasionally preferred.

taufloat, optional

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.

monlevint, optional

A value of for enables monitoring of the model selection process; a value of disables it.

monfunNone or callable monfun(flag, var, val, data=None), optional

Note: if this argument is None then a NAG-supplied facility will be used.

The function for monitoring the model selection process.

Parameters
flagstr, length 1

The value of indicates the stage of the stepwise selection of explanatory variables.

Variable was added to the current model.

Beginning the backward elimination step.

Variable failed the collinearity test and is excluded from the model.

Variable 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 takes the value .

Finished stepwise selection procedure.

varint

The index of the explanatory variable in the design matrix to which pertains.

valfloat

If , is the variance ratio value for the coefficient associated with explanatory variable index .

dataarbitrary, optional, modifiable in place

User-communication data for callback functions.

dataarbitrary, optional

User-communication data for callback functions.

io_managerFileObjManager, optional

Manager for I/O in this routine.

Returns
isxint, ndarray, shape

The value of indicates the status of the th explanatory variable in the model.

Forced exclusion.

Excluded.

Selected.

Forced selection.

bfloat, ndarray, shape

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 .

sefloat, ndarray, shape

contains the standard error for the estimate of , for .

rsqfloat

The -statistic for the fitted regression model.

rmsfloat

The mean square of residuals for the fitted regression model.

dfint

The number of degrees of freedom for the sum of squares of residuals.

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, ; .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: or .

(errno )

On entry at least one diagonal element of .

Constraint: must be positive definite.

(errno )

On entry, .

Constraint: , or , for .

(errno )

On entry, , for all .

Constraint: there must be at least one free variable.

(errno )

All variables are collinear, no model to select.

Warns
NagAlgorithmicWarning
(errno )

Matrix not positive definite, results may be inaccurate.

Notes

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 matrix of explanatory variables,

is a vector of unknown coefficients, and

is a vector of length of unknown, Normally distributed, random errors.

linregm_fit_stepwise 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 , for , 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:

1. the least squares estimate for the th explanatory variable included in the fitted model;

2. standard error estimates for each coefficient in the final model;

3. the square root of the mean square of residuals and its degrees of freedom;

4. 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.

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