bs.slr.plot<-function(x,y) { n<-length(y) par(mfrow=c(1,2)) fit<-lm(y~x) ### Do many BSs ### plot(x,y,pch='') legend('topleft',legend=c('BS estimate','LS estimate'),col=1:2,lty=1) nbs<-1000 b<-rep(0,nbs) for( i in 1:nbs ) { y1<-sample(y,n,replace=T) fit1<-lm(y1~x) abline(fit1) b[i]<-fit1$coef[2] } abline(fit,col=2) hist(b, main='Histogram of 1000 Boostrap Estimates of Slope') }