# NOT RUN {
# load data
data(airquality)
# remove observations with missing predictor variable values
airquality <- airquality[complete.cases(airquality), ]
# get number of observations and the response column index
n <- nrow(airquality)
response.col <- 1
# split data into training and test sets
train.ind <- sample(1:n, n * 0.9, replace = FALSE)
Xtrain <- airquality[train.ind, -response.col]
Ytrain <- airquality[train.ind, response.col]
Xtest <- airquality[-train.ind, -response.col]
Ytest <- airquality[-train.ind, response.col]
# fit random forest to the training data
rf <- randomForest::randomForest(Xtrain, Ytrain, nodesize = 5,
ntree = 500,
keep.inbag = TRUE)
# estimate conditional mean squared prediction errors,
# biases, prediction intervals, and error distribution
# functions for the test observations
output <- quantForestError(rf, Xtrain, Xtest,
alpha = 0.05)
# do the same as above but in parallel
output <- quantForestError(rf, Xtrain, Xtest, alpha = 0.05,
n.cores = 2)
# estimate just the conditional mean squared prediction errors
# and prediction intervals for the test observations
output <- quantForestError(rf, Xtrain, Xtest,
what = c("mspe", "interval"),
alpha = 0.05)
# estimate just the conditional error distribution
# functions for the test observations
output <- quantForestError(rf, Xtrain, Xtest,
what = c("p.error", "q.error"))
# }
Run the code above in your browser using DataLab