# Note: more examples can be found at
# https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-017-1650-8
# \donttest{
library(mlbench)
# data used by Breiman, L.: Random forests. Machine Learning 45(1), 5--32 (2001)
data(PimaIndiansDiabetes2)
Diabetes <- na.omit(PimaIndiansDiabetes2)
set.seed(2016)
require(randomForest)
ri<- randomForest(diabetes ~ ., data = Diabetes, ntree = 500, importance = TRUE,
keep.inbag = TRUE, replace = FALSE)
# GVIM and PVIM (CART-RF)
im = importance(ri)
im
# rank
ii = apply(im, 2, rank)
ii
# IPM based on CART-RF (randomForest package)
da = Diabetes[, 1:8]
ntree = 500
# IPM case-wise computed with OOB
pupf = ipmrf(ri, da, ntree)
# global IPM
pua = apply(pupf, 2, mean)
pua
# IPM by classes
attach(Diabetes)
puac = matrix(0, nrow = 2, ncol = dim(da)[2])
puac[1, ] = apply(pupf[diabetes == 'neg', ], 2, mean)
puac[2, ] = apply(pupf[diabetes == 'pos', ], 2, mean)
colnames(puac) = colnames(da)
rownames(puac) = c('neg', 'pos')
puac
# rank IPM
# global rank
rank(pua)
# rank by class
apply(puac, 1, rank)
# }
Run the code above in your browser using DataLab