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

2 ビュー (過去 30 日間)
Boyi Jiang
Boyi Jiang 2015 年 7 月 24 日
編集済み: darova 2020 年 4 月 11 日
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 件のコメント
yafei huang
yafei huang 2018 年 7 月 13 日
Hi Jiang, do you know how to do the backwards selection only in matlab now?
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 Center および File ExchangeModel Building and Assessment についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by