

#######################
# Building the forest #
#######################
#load("my.data.selected.imputed.RData")
#library(randomForest)
#my.rf<-randomForest(y=my.data.selected.imputed[,1],x=my.data.selected.imputed[,-1],ntree=100000,importance=TRUE)
#my.importance<-importance(my.rf,scale=FALSE)
#save(my.rf,file="my.rf.RData")
#save(my.importance,file="my.importance.RData")


###################
## small forests ##
###################
#load("my.data.selected.imputed.RData")

#prand<-50
#niter<-200
#my.gini<-matrix(0,niter,prand)
#my.perm<-matrix(0,niter,prand)
#p<-ncol(my.data.selected.imputed)-1

#my.maf3<-matrix(0,niter,prand)
#my.freq2<-matrix(0,niter,prand)

#freq2<-function(x)
#{
#tab<-table(x)
#return(min(tab)/sum(tab))
#}

#maf3<-function(x)
#{
#tab<-table(x)
#return((tab[2]+2*min(tab[1],tab[3]))/(2*sum(tab)))
#}

#library(randomForest)


#nlevelsSNPs<-sapply(my.data.selected.imputed[,-1],FUN=function(x) nlevels(factor(x)))

#for (i in 1:niter)
#{
#set.seed(i)
#print(i)
#randi<-sample(p,prand)
#my.freq2[i,]<-sapply(my.data.selected.imputed[,randi+1],FUN=freq2)
#my.maf3[i,]<-sapply(my.data.selected.imputed[,randi+1],FUN=maf3)
#my.freq2[i,which(nlevelsSNPs[randi]==3)]<-NA
#my.maf3[i,which(nlevelsSNPs[randi]==2)]<-NA
#my.rfi<-randomForest(y=my.data.selected.imputed[,1],x=my.data.selected.imputed[,randi+1],ntree=500,importance=TRUE)
#my.impi<-importance(my.rfi,scale=FALSE)
#my.gini[i,]<-my.impi[,4]
#my.perm[i,]<-my.impi[,3]
#}

#save(my.gini,file="my.gini.RData")
#save(my.perm,file="my.perm.RData")
#save(my.freq2,file="my.perm.RData")
#save(my.maf3,file="my.perm.RData")