0

I'm trying to construct a random forest for ecological data but keep getting the error

"no applicable method for 'importance' applied to an object of class "logical".

The code I have is:

fit2 <- randomForest(sv ~ salinity + temp + Depthbin +  cdistance + oxygen + 
                      type + diel, data=d.omit, importance(TRUE), ntree=2000)

The variable of interest (sv) is continuous, so I'm not sure if that impacts things. When I remove the importance(TRUE) portion of the code, I can run the random forest but the IncNodePurity values I obtain are ridiculously high (some values over 100,000!!). I'm hoping the importance(TRUE) addition will fix that, but if not, does anyone know of a better way to examine the importance of each variable?

jkrainer
  • 413
  • 5
  • 10
vbar
  • 1
  • It is easier to help if you provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick May 18 '17 at 04:57
  • Great advice MrFlick. Will make sure to do next time. – vbar May 19 '17 at 06:11

1 Answers1

1

try this instead:

fit2 <- randomForest(sv ~ salinity + temp + Depthbin + cdistance + oxygen + type + diel, data=d.omit, importance=TRUE, ntree=2000)

With importance(fit2) you should be able to see the variable importance.

jkrainer
  • 413
  • 5
  • 10
  • That worked! Thank you so much. When looking at the output, I receive both %IncMSE and IncNodePurity. Do you know if one is recommended over the other for interpretation/analysis? – vbar May 19 '17 at 06:10
  • Glad it helped. Maybe [this link](https://stats.stackexchange.com/questions/162465/in-a-random-forest-is-larger-incmse-better-or-worse) can help you answer your question with IncMSE and IncNodePurity – jkrainer May 19 '17 at 07:16