#setwd("Z:/Manuskripte/Papers/Preparation/Gini/Analysen_Section2")

########################################################
# Bias in variable importance measure: null case study #
########################################################
library(randomForest)
library(party)
source("fun.r")

gini0.05n50<-c()
gini0.1n50<-c()
gini0.25n50<-c()
gini0.4n50<-c()

perm0.05n50<-c()
perm0.1n50<-c()
perm0.25n50<-c()
perm0.4n50<-c()

for (i in 1:100)
 {
 set.seed(i)
 print(i)
 my.data<-simSNP(n.snp=200,n.obs=50,maf=rep(c(0.05,0.1,0.25,0.4),each=50),beta0=0)
 my.rf<-randomForest(x=my.data[,-1],y=my.data[,1],importance=TRUE)
 my.importance<-importance(my.rf,scale=FALSE)
 gini0.05n50<-c(gini0.05n50,my.importance[1:50,4])
 gini0.1n50<-c(gini0.1n50,my.importance[51:100,4])
 gini0.25n50<-c(gini0.25n50,my.importance[101:150,4])
 gini0.4n50<-c(gini0.4n50,my.importance[151:200,4])
 perm0.05n50<-c(perm0.05n50,my.importance[1:50,3])
 perm0.1n50<-c(perm0.1n50,my.importance[51:100,3])
 perm0.25n50<-c(perm0.25n50,my.importance[101:150,3])
 perm0.4n50<-c(perm0.4n50,my.importance[151:200,3])
 rm(my.rf)
 rm(my.importance)
  

save(gini0.05n50,file="nullcase_n50/gini0.05n50.RData")
save(gini0.1n50,file="nullcase_n50/gini0.1n50.RData")
save(gini0.25n50,file="nullcase_n50/gini0.25n50.RData")
save(gini0.4n50,file="nullcase_n50/gini0.4n50.RData")

save(perm0.05n50,file="nullcase_n50/perm0.05n50.RData")
save(perm0.1n50,file="nullcase_n50/perm0.1n50.RData")
save(perm0.25n50,file="nullcase_n50/perm0.25n50.RData")
save(perm0.4n50,file="nullcase_n50/perm0.4n50.RData")

}