My goal is to create CI for the CART prediction of new_x
Consider the following code:
require(rpart)
set.seed(147830)
n <- 100
x1 <- runif(n)
x2 <- rnorm(n)
y <- x1 + 2*x2 + rnorm(n, 0, .5)
DAT <- data.frame(y,x1,x2)
fit <- rpart(y ~ x1 + x2, data = DAT)
new_x <- data.frame(x1 = .5 , x2 = .25)
predict(fit, newdata = new_x) # 1.353142 # "should" be ~1
The only way I can think of at the moment is to bootstrap on x1/x2 from DAT, build many prediction models with them, for each predict new_x, and then use the lower/upper percentiles.
Is there some other way to do it? What are the advantages/disadvantages of it?
Thanks.