# How do I calculate prediction intervals for random forest predictions?

In regression problems random forests yield a prediction for each case by averaging the results of each single tree in the forest. I would like to draw a 95% prediction interval around each prediction. There is a nice option interval="prediction" for the prediction method of linear models, but there's no such thing for random forests (at least in the R package randomForest). Can I presume that the casewise predictions of the single trees are normally distributed and apply the formula http://mathurl.com/bbvuvx9 or should I determine it by bootstrapping? If so, how can this be done?

## 2 Answers

I'm assuming you're talking about the continuous response case. If so, I'd recommend the quantregForest package that layers on top of the basic randomForest package and gives conditional quantile predictions. The documentation is quite good. Instead of assuming a gaussian distribution, it build an empirical density function from the terminal nodes.

• stats.ox.ac.uk/~meinshau/quantregforests.pdf describes the technique. – B_Miner Feb 11 '13 at 17:30
• @Shea Parkes: I did not know this package, thanks for the hint. – user7417 Feb 12 '13 at 10:00
• @B_Miner: I already downloaded the pdf and shall dig into it... Certainly I'll come back with more questions ;-) – user7417 Feb 12 '13 at 10:00

The ranger package supports quantile predictions and hence prediction intervals: predict(ranger_fit, type = "quantile", quantiles = c(0.025, 0.975)).