#Rcode4output.txt & #This is the unix command to run this code in the background and save the output in the file code4output.txt postscript("code4plot.ps") par(mfrow=c(1,1),cex=1.5,cex.axis=1.5,cex.lab=1.5) set.seed(4444, kind = NULL) repeat.times<-100 q<-.2 iterations<-1000 n<-5000 d<-20 m<-1000 #m is the size of the hold-out sample (i.e., the test sample) misclass.store<-matrix(0,repeat.times,iterations) bayeserror.store<-rep(0,repeat.times) nnerror.store<-rep(0,repeat.times) rferror.store<-rep(0,repeat.times) library(class) library(rpart) #You can also try using Random Forests for comparison by uncommenting the code provided later #I commented it out because Random Forests is not part of the basic R package and must be installed separately #I put mine in the directory "temp" using the following commands (from within R) #options(CRAN = "http://cran.us.r-project.org/") #install.packages("randomForest",lib="temp") #library(randomForest, lib.loc="temp") for (iui in 1:repeat.times){ x<-matrix(0,n,d) for (ddd in 1:d){ x[,ddd]<-runif(n) } hold.out.x<-matrix(0,m,d) for (k in 1:d) { hold.out.x[,k]<-runif(m) } y<-rep(0,n) for (i in 1:n){ y[i]<-1*(runif(1)0)/repeat.times)