#### Minucci et al. | Mathematical Modeling of Ventilator-Induced Lung Inflammation #### random forest with LHS data - run several and find average importance values require(randomForest) ######################################## ######### LHSproc should have 87 columns ######################################## parnames=c('dp','da','dm0','dm1','dm2','xm0pb','xm0ab','xm0pd','xm0ad','xm1p', 'kpm1','kpe','kam1','kam2','xm0p','xm0a','km1m2','xer','kep ', 'km2r','km2a','xnup','kpn','kn','kman','kan','knn','kanm1', 'kanm2','km0pb','km0ab','km0pd','km0ad','km1p','km0p','km0a','krm2','ker', 'kem1','knup','abinf','ainf','mupb','muab','mum0b','mum1b','mum2b','mup', 'mua','mum0','mum1','mum2','muR','munu','muna','sm','sn', 'bd','br','bp','sd','kmne','sp','sa','xmne', 'xm2r','xm2a','ken','starting.state','M2.percent.at.t=10','max.M1.percent','max.M2.percent', 'min.M1.percent','min.M2.percent','max.M1','max.M2','min.M1', 'min.M2','M1.peak.time','M2.peak.time','M1.peak.ratio','Eh.difference', 'Eh.ratio.0.5h','Eh.ratio 2h','Eh.ratio.6h','Eh.end.value','outcome') params<-read.table(file=file.choose(), header=FALSE, sep=",", quote="", col.names = parnames) params$starting.state <- factor(params$starting.state) params$outcome <- factor(params$outcome) # remove some predictors related to classification partest=params partest$Eh.difference <- NULL partest$km1m2 <- NULL # dummy parameter partest$sd <- NULL # not varied partest$Eh.end.value <- NULL partest$starting.state <- NULL ################################################################### nchar<-81; # total columns minus one (outcome is response variable) #set.seed(29) # set number of runs and create arrays for saving data nruns=1000 # will take the average of nruns importance values importance.all<-array(0, dim=c(nchar,nruns)) for(i in 1:nruns){ print(i) # tells what iteration you're on (out of nruns) train = sample(1:nrow(partest), 10000) # train with 10,000 sets rf.par = randomForest(outcome~., data = partest, subset = train) # default mtry importance.rf=importance(rf.par) importance.all[,i]<-round(importance(rf.par), 2) # look at variable importance } # save this file and import into MATLAB script to make plot # write.table(importance.all,"FILE PATH/importance_values_from_R.txt",sep="\t",row.names=FALSE)