do.it<-function(n) { # R function written/started 'live' during class to run simple simulation ans1<-ans2<-numeric(500) for (i in 1:500){ x=runif(n,0,5) # generate some data from a uniform distribution ans1[i]=max(x) # use the max of all data to estimate the upperbound ans2[i]=2*mean(x) # use twice the average of data to estimate the same } # prepare to make plots par(mfrow=c(2,1)) # look at statistical properties of the 1st 'algorithm' (max) hist(ans1,xlim=c(0,10), # xlim revised AFTER class # following line added AFTER class to make plot look better main='',xlab='max',ylab='',border=FALSE ) # superimpose ground truth (here, 5) onto the plot for comparison abline(v=5,col='red') # add title to plot, slightly revised AFTER class title(main=paste('n =',n)) # look at statistical properties of the 2nd 'algorithm' (twice the average) hist(ans2,xlim=c(0,10), # xlim revised AFTER class # following line added AFTER class to make plot look better main='',xlab='twice the average',ylab='',border=FALSE ) # superimpose ground truth (as above) onto the plot for comparison abline(v=5,col='red') }