Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

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.

step

Class: LinearModel

Improve linear regression model by adding or removing terms

Syntax

mdl1 = step(mdl)
mdl1 = step(mdl,Name,Value)

Description

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) returns an improved linear model using additional options specified by one or more Name,Value pair arguments. For example, you can specify the criterion to use to add or remove terms.

Input Arguments

expand all

Full, fitted linear regression model, specified as a LinearModel object constructed using fitlm or stepwiselm.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

expand all

Criterion for selecting terms to add or remove, specified as the comma-separated pair consisting of 'Criterion' and one of the following.

CriterionPEnterPRemoveCompared Against
'SSE'0.05< 0.1p-value for F test
'AIC'0< 0.01Change in AIC
'BIC'0< 0.01Change in BIC
'Rsquared'0.1> 0.05Increase in R-squared
'AdjRsquared'0> -0.05Increase in adjusted R-squared

Example: 'Criterion','BIC'

Model specification describing terms that cannot be removed from the model, specified as the comma-separated pair consisting of 'Lower' and one of the options for modelspec naming the model.

Example: 'Lower','linear'

Number of steps to take, specified as the comma-separated pair consisting of 'NSteps' and a positive integer.

Data Types: single | double

Improvement measure for adding a term, specified as the comma-separated pair consisting of 'PEnter' and a scalar value. The default values are below.

CriterionDefault valueDecision
'Deviance'0.05If the p-value of F or chi-squared statistic is smaller than PEnter, add the term to the model.
'SSE'0.05If the SSE of the model is smaller than PEnter, add the term to the model.
'AIC'0If the change in the AIC of the model is smaller than PEnter, add the term to the model.
'BIC'0If the change in the BIC of the model is smaller than PEnter, add the term to the model.
'Rsquared'0.1If the increase in the R-squared of the model is larger than PEnter, add the term to the model.
'AdjRsquared'0If the increase in the adjusted R-squared of the model is larger than PEnter, add the term to the model.

For more information on the criteria, see Criterion name-value pair argument.

Example: 'PEnter',0.075

Improvement measure for removing a term, specified as the comma-separated pair consisting of 'PRemove' and a scalar value.

CriterionDefault valueDecision
'Deviance'0.10If the p-value of F or chi-squared statistic is larger than PRemove, remove the term from the model.
'SSE'0.10If the p-value of the F statistic is larger than PRemove, remove the term from the model.
'AIC'0.01If the change in the AIC of the model is larger than PRemove, remove the term from the model.
'BIC'0.01If the change in the BIC of the model is larger than PRemove, remove the term from the model.
'Rsquared'0.05If the increase in the R-squared value of the model is smaller than PRemove, remove the term from the model.
'AdjRsquared'-0.05If the increase in the adjusted R-squared value of the model is smaller than PRemove, remove the term from the model.

At each step, stepwise algorithm also checks whether any term is redundant (linearly dependent) with other terms in the current model. When any term is linearly dependent with other terms in the current model, it is removed, regardless of the criterion value.

For more information on the criteria, see Criterion name-value pair argument.

Example: 'PRemove',0.05

Model specification describing the largest set of terms in the fit, specified as the comma-separated pair consisting of 'Upper' and one of the character vector options for modelspec naming the model.

Example: 'Upper','quadratic'

Control for display of information, specified as the comma-separated pair consisting of 'Verbose' and one of the following:

  • 0 — Suppress all display.

  • 1 — Display the action taken at each step.

  • 2 — Also display the actions evaluated at each step.

Example: 'Verbose',2

Output Arguments

expand all

Improved linear regression model, returned as a LinearModel object. To overwrite mdl, set mdl1 equal to mdl.

Examples

expand all

Fit a linear model to car data. Use step to evaluate whether a quadratic model improves the fit quality.

Load carsmall data, and create a table using weight and model year predictors with MPG response.

load carsmall
tbl = table(MPG,Weight);
tbl.Year = categorical(Model_Year);

Make a linear model of MPG as a function of Year and Weight.

mdl = fitlm(tbl,'MPG ~ Year + Weight')
mdl = 


Linear regression model:
    MPG ~ 1 + Weight + Year

Estimated Coefficients:
                    Estimate         SE         tStat       pValue  
                   __________    __________    _______    __________

    (Intercept)         40.11        1.5418     26.016    1.2024e-43
    Weight         -0.0066475    0.00042802    -15.531    3.3639e-27
    Year_76            1.9291       0.74761     2.5804      0.011488
    Year_82            7.9093       0.84975     9.3078    7.8681e-15


Number of observations: 94, Error degrees of freedom: 90
Root Mean Squared Error: 2.92
R-squared: 0.873,  Adjusted R-Squared 0.868
F-statistic vs. constant model: 206, p-value = 3.83e-40

Use step to adjust the model to potentially include full quadratic terms.

mdl1 = step(mdl,'upper','quadratic')
1. Adding Weight^2, FStat = 9.9164, pValue = 0.0022303

mdl1 = 


Linear regression model:
    MPG ~ 1 + Weight + Year + Weight^2

Estimated Coefficients:
                    Estimate         SE         tStat       pValue  
                   __________    __________    _______    __________

    (Intercept)        54.206        4.7117     11.505    2.6648e-19
    Weight          -0.016404     0.0031249    -5.2493    1.0283e-06
    Year_76            2.0887       0.71491     2.9215     0.0044137
    Year_82            8.1864       0.81531     10.041    2.6364e-16
    Weight^2       1.5573e-06    4.9454e-07      3.149     0.0022303


Number of observations: 94, Error degrees of freedom: 89
Root Mean Squared Error: 2.78
R-squared: 0.885,  Adjusted R-Squared 0.88
F-statistic vs. constant model: 172, p-value = 5.52e-41

Algorithms

expand all

Alternatives

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.

Was this topic helpful?