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.

Create generalized linear regression model by stepwise regression

`mdl = stepwiseglm(tbl,modelspec)`

`mdl = stepwiseglm(X,y,modelspec)`

`mdl = stepwiseglm(...,modelspec,Name,Value)`

creates
a generalized linear model with additional options specified by one
or more `mdl`

= stepwiseglm(...,`modelspec`

,`Name,Value`

)`Name,Value`

pair arguments.

The generalized linear model

`mdl`

is a standard linear model unless you specify otherwise with the`Distribution`

name-value pair.For other methods such as

`devianceTest`

, or properties of the`GeneralizedLinearModel`

object, see`GeneralizedLinearModel`

.After training a

`GeneralizedLinearModel`

model object by using`stepwiseglm`

, use the function`predict`

and the trained model object to generate C code that predicts responses for new data. For details, see Code Generation.

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

Use `fitglm`

to create a
model with a fixed specification. Use `step`

, `addTerms`

,
or `removeTerms`

to adjust a fitted model.

[1] Collett, D. *Modeling Binary
Data*. New York: Chapman & Hall, 2002.

[2] Dobson, A. J. *An Introduction
to Generalized Linear Models*. New York: Chapman &
Hall, 1990.

[3] McCullagh, P., and J. A. Nelder. *Generalized
Linear Models*. New York: Chapman & Hall, 1990.

Was this topic helpful?