mn.vs.md<-function(sample.size=25,num.samples=1000,mu0=2.3,sigma0=1.4) { # generate all the samples - one sample per row of the matrix x<-matrix(rnorm(sample.size*num.samples,mu0,sigma0),num.samples,sample.size) # compute mean, median and midrange of each sample xmean<-apply(x,1,mean) xmed<-apply(x,1,median) xmidr<-0.5*(apply(x,1,max)+apply(x,1,min)) # display as a boxplot, with 'truth' mu0 boxplot(list(xmean,xmed,xmidr),names=c('mean','median','midrange')) abline(h=mu0,col='blue') # print summary statistics print(summary(xmean)) print(summary(xmed)) print(summary(xmidr)) # pause for mouse click dummy<-locator(1) # display histograms par(mfrow=c(3,1)) xlim=range(xmean,xmed) bbb<-pretty(c(xmean,xmed,xmidr),100) hist(xmean,breaks=bbb,prob=T,xlim=xlim) hist(xmed,breaks=bbb,prob=T,xlim=xlim) hist(xmidr,breaks=bbb,prob=T,xlim=xlim) par(mfrow=c(1,1)) }