[R] Forward stepwise regression using lmStepAIC in Caret
Allan Engelhardt
allane at cybaea.com
Mon Mar 5 11:01:12 CET 2012
Not sure I really like stepwise variable selection, but the function
should work, of course. Compare
data(BostonHousing, package = "mlbench")
lmFit <- train(medv ~ ., data = BostonHousing, "lmStepAIC", scope =
list(lower = ~., upper = ~.^2), direction = "forward")
with
lmFit <- train(medv ~ ., data = BostonHousing, "lmStepAIC", scope =
list(lower = ~., upper = ~.^2), direction = "backward")
and also the version without the "direction" argument where the code
tries to do the right thing.
In summary, my understanding is that your call first fits a y ~ . type
model from which you cannot step backwards with constraints and then it
tries to do 'what you might have meant'.
Hope this helps a little.
Allan
On 05/03/12 01:14, Dan Putka wrote:
> I'm looking for guidance on how to implement forward stepwise regression
> using lmStepAIC in Caret.
>
> The stepwise "direction" appears to default to "backward". When I try to
> use "scope" to provide a lower and upper model, Caret still seems to
> default to "backward".
>
> Any thoughts on how I can make this work?
>
> Here is what I tried:
>
> itemonly<- susbstitute(~i1+i2+i3+i4+i5+i6+i7+i8+i9+i10) #this is my full
> model
> #I want my "lower" model to consist of the intercept only
>
> stepLmFit.i<- train(xtraindata.i, ytraindata,"lmStepAIC",
> scope=list(upper=itemonly,lower=~1),direction="forward")
>
> Any guidance on how I can make this work would be greatly appreciated.
>
> Dan
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list