



####################
# Loading the data #
####################

load("my.data.selected.imputed.RData")
n<-nrow(my.data.selected.imputed)
p<-ncol(my.data.selected.imputed)-1

library(randomForest)


niter<-10
my.gini.perm<-matrix(0,p,niter)
my.perm.perm<-matrix(0,p,niter)


############################
## VIM with permuted data ##
############################

# For niter permutations:
for (j in 1:niter)
 {
 print(j)
 set.seed(j)
 # Build a random forest based on class-permuted data
 my.rf<-randomForest(y=my.data.selected.imputed[sample(n,n),1],x=my.data.selected.imputed[,-1],ntree=100000,importance=TRUE)
 # Compute VIM
 my.importance<-importance(my.rf,scale=FALSE)
 rm(rf)
 # Put VIM into the results matrices
 my.gini.perm[,j]<-my.importance[,4]
 my.perm.perm[,j]<-my.importance[,3]
 save(my.gini.perm,file="my.gini.perm.RData")
 save(my.perm.perm,file="my.perm.perm.RData")
 }
