How can I specify "forward" or "backward" model selection in stepwiselm function?
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (1)
Cindy Solomon
le 27 Juil 2015
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 commentaires
yafei huang
le 13 Juil 2018
Hi Jiang, do you know how to do the backwards selection only in matlab now?
Carly Cocke
le 11 Avr 2020
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.
Voir également
Catégories
En savoir plus sur Model Building and Assessment dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!