If you do not give a model specification, the default starting model is 'constant', and the default upper bounding model is 'interactions'. If you do not give a model specification, the default is 'linear'.įor stepwiselm, the model specification you give is the starting model, which the stepwise procedure tries to improve. Use whichever you find most convenient.įor fitlm, the model specification you give is the model that is fit. There are several ways of specifying a model for linear regression. So after a stepwise fit, examine your model for outliers (see Examine Quality and Adjust Fitted Model). You cannot use robust options along with stepwise fitting. See Compare large and small stepwise models. Starting with more terms can lead to a more complex model, but one that has lower mean squared error. Usually, starting with a constant model leads to a small model.
The result depends on the starting model.
Use stepwise fitting to find a good model, which is one that has only relevant terms. stepwiselm starts from one model, such as a constant, and adds or subtracts terms one at a time, choosing an optimal term each time in a greedy fashion, until it cannot improve further. Use stepwiselm to find a model, and fit parameters to the model. This means that when you use robust fitting, you cannot search stepwise for a good model. However, step does not work with robust fitting. Robust fitting saves you the trouble of manually discarding outliers. Use fitlm with the RobustOpts name-value pair to create a model that is little affected by outliers. The method requires you to examine the data manually to discard outliers, though there are techniques to help (see Examine Quality and Adjust Fitted Model). This method is also useful when you want to explore a few models. This method is best when you are reasonably certain of the model’s form, and mainly need to find its parameters. Use fitlm to construct a least-squares fit of a model to the data.
There are three ways to fit a model to data: Notice that the nonnumeric entries, such as sex, do not appear in X. Y = X(:,4) % response y is systolic pressure