[R] use "caret" to rank predictors by random forest model

Xiaoqi Cui xcui at mtu.edu
Mon Mar 7 21:27:24 CET 2011


Hi,

I'm using package "caret" to rank predictors using random forest model and draw predictors importance plot. I used below commands:

rf.fit<-randomForest(x,y,ntree=500,importance=TRUE) 
## "x" is matrix whose columns are predictors, "y" is a binary resonse vector
## Then I got the ranked predictors by ranking "rf1$importance[,"MeanDecreaseAccuracy"]"
## Then draw the importance plot
varImpPlot(rf.fit)

As you can see, all the functions I used are directly from the package "randomForest", instead of from "caret". so I'm wondering if the package "caret" has some functions who can do the above ranking and ploting.

In fact, I tried functions "train", "varImp" and "plot" from package "caret", the random forest model that built by "train" can not be input correctly to "varImp", which gave error message like "subscripts out of bounds". Also function "plot" doesn't work neither.

So I'm wondering if anybody has encountered the same problem before, and could shed some light on this. I would really appreciate your help.

Thanks,
Xiaoqi



More information about the R-help mailing list