naginterfaces.library.correg.linregm_​rssq

naginterfaces.library.correg.linregm_rssq(x, vname, isx, y, mean='M', wt=None)[source]

linregm_rssq calculates the residual sums of squares for all possible linear regressions for a given set of independent variables.

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

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

Parameters
xfloat, array-like, shape

must contain the th observation for the th independent variable, for , for .

vnamestr, array-like, shape

must contain the name of the variable in column of , for .

isxint, array-like, shape

Indicates which independent variables are to be considered in the model.

The variable contained in the th column of is included in all regression models, i.e., is a forced variable.

The variable contained in the th column of 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 is not included in the models.

yfloat, array-like, shape

must contain the th observation on the dependent variable, , for .

meanstr, length 1, optional

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.

wtNone or float, array-like, shape , optional

If provided 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 is not provided the effective number of observations is .

Returns
nmodint

The total number of models for which residual sums of squares have been calculated.

modlstr, ndarray, shape

The first elements of the th row of contain the names of the independent variables, as given in , that are included in the th model.

rssfloat, ndarray, shape

contains the residual sum of squares for the th model, for .

ntermsint, ndarray, shape

contains the number of independent variables in the th model, not including the mean if one is fitted, for .

mrankint, ndarray, shape

contains the rank of the residual sum of squares for the th model.

Raises
NagValueError
(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: or .

(errno )

On entry, .

Constraint: or .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: , for .

(errno )

On entry, .

Constraint: , for .

(errno )

There are no free variables, i.e., no element of .

(errno )

On entry, and number of possible models is .

Constraint: the number of possible models.

(errno )

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.

(errno )

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.

Notes

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:

  1. null model

  2. and

  3. and

  4. and

  5. , and .

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

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

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