Hi Azarang,
As per my understanding, you would like to know how to do either forward or backward elimination in stepwise regression.
You can control the direction of selection by setting the Probability to Enter(‘PEnter’) and Probability to Remove(‘PRemove’) values to control the significance level of adding or removing feature respectively.
- For Forward elimination - You can set larger values for Probability to Remove(‘PRemove’) such as ‘PRemove=1’
mdl = stepwiselm(X,y,’constant’,’Upper’,’linear’,’PRemove’,1);
- For Backward elimination - You can set smaller values for Probability to Enter(‘PEnter’)such as ‘PEnter=0.05’
mdl = stepwiselm(X,y,’constant’,’Upper’,’linear’,’PEnter’,0.05);
This means that only features with a Probability value (p-value) less than 0.05 will be considered for addition, effectively turning off the forward selection step.
Note that if you set both 'PEnter’ and ‘PRemove’ to small values, you may end up with no selected features or all features selected, depending on the significance level and the strength of the relationships between the features and the response variable.
For further reference, to check more about ‘stepwiselm’ function please go through this link:
I hope this resolves the issue you were facing.