How can I specify "forward" or "backward" model selection in stepwiselm function?

12 次查看(过去 30 天)
Hi,all,
I am using *stepwiselm* function in Matlab statistics and machine learning toolbox. The documentation says "stepwiselm uses forward and backward stepwise regression to determine a final model". But how can I explicitly inform forward or backward direction?

回答(1 个)

Cindy Solomon
Cindy Solomon 2015-7-27
Hi Boyi,
To do a forward selection, you can start with a model with no variables.
For example:
>> rng('default')
>> X = rand(20,7);
>> y = [ones(20,1),X(:,1),X(:,3),X(:,5)]*rand(4,1) + 0.1*randn(20,1);
>> stepwiselm(X,y,'Constant')
If there is a set of predictors that must be included in the model, you can use the 'Lower' name/value pair to specify it, and "stepwiselm" will add terms in addition to that, such as starting with the form:
>> lowerMdl = 'y ~ 1 + x1 + x2';
>> stepwiselm(X,y,lowerMdl,'lower',lowerMdl)
As an additional note, if you want to prevent "stepwiselm" from going backwards, you can set the 'PRemove' value to 1 in the Name/ Value pair arguments for "stepwiselm". Generally both forward and backward stepwise regression are both used to determine a final model- it terminates when no single step improves the model according to your criterion.
Hope this helps! -Cindy
  3 个评论
Carly Cocke
Carly Cocke 2020-4-11
Hello Yajei, I am not 100% sure but it seems that the best way to allow only backwards movement in the model is to set the PEnter value to 0. By setting the PEnter value to zero, only p-values less than 0 can be added therefore no new predictors can be added. This should do the converse of Cindy's solution. I haven't tested it, so please take this advice as an idea instead of a solution.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Model Building and Assessment 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by