bbmedci<-function(x,conflevel=0.95,nboots=120){ #This function will calculate the "basic bootstrap"# # confidence interval for the population median. # #nboots = B = number of bootstrap samples to take# #tstar will contain the median calculated for each bootstrap# # sample # alpha<-1-conflevel tstar<-rep(0,nboots) for (b in 1:nboots){ tstar[b]<-median(sample(x,replace=T)) } tstar<-sort(tstar) mtstar<-mean(tstar) biasest<-mtstar-median(x) lowtstar<-0.5*(tstar[floor(nboots*alpha/2)]+tstar[ceiling(nboots*alpha/2)]) hitstar<-0.5*(tstar[floor(nboots*(1-alpha/2))]+tstar[ceiling(nboots*(1-alpha/2))]) ucl<-median(x)-(lowtstar-median(x)) lcl<-median(x)-(hitstar-median(x)) c(lcl,ucl) } stbmedci<-function(x,conflevel=0.95,nboots=120){ #This function will calculate the "studentized bootstrap"# # confidence interval for the population median. # #It uses the simple variance estimate and so should agree# # with the basic bootstrap except for the bias correction.# #nboots = B = number of bootstrap samples to take# #tstar will contain the median calculated for each bootstrap# # sample # #This version has the zstars in the right order.# alpha<-1-conflevel tstar<-rep(0,nboots) for (b in 1:nboots){ tstar[b]<-median(sample(x,replace=T)) } tstar<-sort(tstar) mtstar<-mean(tstar) vtstar<-var(tstar) biasest<-mtstar-median(x) zstar<-(tstar-median(x))/sqrt(vtstar) lowzstar<-0.5*(zstar[floor(nboots*alpha/2)]+zstar[ceiling(nboots*alpha/2)]) hizstar<-0.5*(zstar[floor(nboots*(1-alpha/2))]+zstar[ceiling(nboots*(1-alpha/2))]) lcl<-(median(x)-biasest)-hizstar*sqrt(vtstar) ucl<-(median(x)-biasest)-lowzstar*sqrt(vtstar) c(lcl,ucl) }