I'm trying to generate bootstrap confidence 'intervals' for particular split(s) of a regression tree using
rpart
(to generate tree) and boot
(to bootstrap) - elaborating on this question/answer.
Example:
data(iris)
library(rpart)
r1<-rpart(Sepal.Length ~ ., cp = 0.05, data=iris)
plot(r1)
text(r1)
library(boot)
trainData <- iris[-150L, ]
predictData <- iris[150L, ]
rboot <- boot(trainData, function(data, idx) {
bootstrapData <- data[idx, ]
r1 <- rpart(Sepal.Length ~ ., bootstrapData, cp = 0.05)
predict(r1, newdata = predictData)
}, 1000L)
Generate quantiles, as rpart
has no CI function:
quantile(rboot$t, c(0.025, 0.975))
2.5% 97.5%
5.871393 6.766842
That's ok, BUT, how can I obtain 'quantile' estimates per split in terms of the predictor. For example, quantiles for either side of "Petal.Length<3.4"?