BootRF {shipunov} | R Documentation |
How to bootstrap with 'randomForest()'
BootRF(data, classes, sub="none", nsam=4, nboot=1000, misclass=TRUE, ...)
data |
Data frame to classify |
classes |
Character vector of class names |
sub |
Subsample to use (see example) |
nsam |
Number of training items from each level of grouping factor, default 4 |
nboot |
Number of iterations |
misclass |
Calculate misclassification table? |
... |
Further options to randomForest() |
Note that as randomForest::randomForest() is based on sampling, BootRF() is the kind of second-level bootstrap.
BootRF() is very simple and does not interact with Random Forest algorithms. It is stratified, i.e. samples equal numbers ('nsam') of training items from the each level of grouping factor.
Also, it allows to use the subset of data which will be in turn used for sub-sampling of training data.
Returns all predictions as character matrix, each boot is a column
Alexey Shipunov
randomForest::randomForest
iris.sub <- 1:nrow(iris) %in% seq(1, nrow(iris), 5)
## could be slow
iris.bootrf <- BootRF(iris[, -5], iris[, 5], sub=iris.sub)
iris.bootrf <- BootRF(iris[, -5], iris[, 5]) # naturally, lower
## calculate and plot stability
st <- apply(iris.bootrf, 1, function(.x) var(as.numeric(as.factor(.x))))
plot(prcomp(iris[, -5])$x, col=iris$Species, pch=ifelse(st == 0, 19, 1))