Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

**Class: **LinearModel

Create linear regression model by stepwise regression

`LinearModel.stepwise`

will be removed in a
future release. Use `stepwiselm`

instead.

`mdl = LinearModel.stepwise(tbl,modelspec)`

mdl = LinearModel.stepwise(X,y,modelspec)

mdl = LinearModel.stepwise(___,modelspec,Name,Value)

returns
a linear model of a table or dataset array `mdl`

= LinearModel.stepwise(`tbl`

,`modelspec`

)`tbl`

,
using stepwise regression to add or remove predictors. `modelspec`

is
the starting model for the stepwise procedure.

creates
a linear model of the responses `mdl`

= LinearModel.stepwise(`X`

,`y`

,`modelspec`

)`y`

to a data matrix `X`

,
using stepwise regression to add or remove predictors. `modelspec`

is
the starting model for the stepwise procedure.

creates
a linear model for any of the inputs in the previous syntaxes, with
additional options specified by one or more `mdl`

= LinearModel.stepwise(___,`modelspec`

,`Name,Value`

)`Name,Value`

pair
arguments.

For example, you can specify the categorical variables, the
smallest or largest set of terms to use in the model, the maximum
number of steps to take, or the criterion `LinearModel.stepwise`

uses
to add or remove terms.

You cannot use robust regression with stepwise regression. Check your data for outliers before using

`LinearModel.stepwise`

.For other methods or properties of the

`LinearModel`

object, see`LinearModel`

.

*Stepwise regression* is a systematic method
for adding and removing terms from a linear or generalized linear
model based on their statistical significance in explaining the response
variable. The method begins with an initial model, specified using `modelspec`

,
and then compares the explanatory power of incrementally larger and
smaller models.

MATLAB^{®} uses forward and backward stepwise regression to
determine a final model. At each step, the method searches for terms
to add to or remove from the model based on the value of the `'Criterion'`

argument.
The default value of `'Criterion'`

is `'sse'`

,
and in this case, `stepwiselm`

uses the *p*-value
of an *F*-statistic to test models with and without
a potential term at each step. If a term is not currently in the model,
the null hypothesis is that the term would have a zero coefficient
if added to the model. If there is sufficient evidence to reject the
null hypothesis, the term is added to the model. Conversely, if a
term is currently in the model, the null hypothesis is that the term
has a zero coefficient. If there is insufficient evidence to reject
the null hypothesis, the term is removed from the model.

Here is how stepwise proceeds when `'Criterion'`

is `'sse'`

:

Fit the initial model.

Examine a set of available terms not in the model. If any of these terms have

*p*-values less than an entrance tolerance (that is, if it is unlikely that they would have zero coefficient if added to the model), add the one with the smallest*p*-value and repeat this step; otherwise, go to step 3.If any of the available terms in the model have

*p*-values greater than an exit tolerance (that is, the hypothesis of a zero coefficient cannot be rejected), remove the one with the largest*p*-value and go to step 2; otherwise, end.

At any stage, the function will not add a higher-order term
if the model does not also include all lower-order terms that are
subsets of it. For example, it will not try to add the term `X1:X2^2`

unless
both `X1`

and `X2^2`

are already
in the model. Similarly, the function will not remove lower-order
terms that are subsets of higher-order terms that remain in the model.
For example, it will not examine to remove `X1`

or `X2^2`

if `X1:X2^2`

stays
in the model.

The default for `stepwiseglm`

is `'Deviance'`

and
it follows a similar procedure for adding or removing terms.

There are several other criteria available, which you can specify
using the `'Criterion'`

argument. You can use the
change in the value of the Akaike information criterion, Bayesian
information criterion, R-squared, adjusted R-squared as a criterion
to add or remove terms.

Depending on the terms included in the initial model and the order in which terms are moved in and out, the method might build different models from the same set of potential terms. The method terminates when no single step improves the model. There is no guarantee, however, that a different initial model or a different sequence of steps will not lead to a better fit. In this sense, stepwise models are locally optimal, but might not be globally optimal.

You can also construct a stepwise linear model using `stepwiselm`

.

You can construct a model using `fitlm`

,
then manually adjust the model using `step`

, `addTerms`

, or `removeTerms`

.
Use `fitlm`

for robust regression.
You cannot use robust regression and stepwise regression together.

[1] Draper, N. R., and H. Smith. *Applied
Regression Analysis*. Hoboken, NJ: Wiley-Interscience,
pp. 307–312, 1998.

Was this topic helpful?