Documentation |
mdl1 = step(mdl)
mdl1 = step(mdl,Name,Value)
mdl1 = step(mdl) returns an improved linear model based on mdl, with one predictor added or removed.
Note: You can use step only if mdl.Robust = []. This holds when you create mdl with fitlm having the RobustOpts name-value pair set to the default 'off'. |
mdl1 = step(mdl,Name,Value) improves a linear model with additional options specified by one or more Name,Value pair arguments.
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.
If any terms not in the model 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 terms in the model have p-values greater than an exit tolerance (that is, the hypothesis of a zero coefficient can be rejected), remove the one with the largest p-value and go to step 2; otherwise, end.
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 stepwiselm to select a model from a starting model, continuing until no single step is beneficial.
Use addTerms or removeTerms to add or remove particular terms.