Packages

speed<-c(850,740,900,1070,930,850,950,980,980,880,1000,980,930,650,760,810,1000,1000,960,960)
summary(speed)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     650     850     940     909     980    1070

bootstrap stat:: obsereved stat as observed stat: true value

trying to generate a collection of bootstrap means

bstraps<-c()

b<-1000
for (i in 1:b){
  bsample<-sample(speed,length(speed),replace=T)
 # bstraps<-c(mean(bsample),bsample)
   bstraps<-c(mean(bsample),bstraps)
}
#bstraps
hist(speed) # histogram of orginal sample

hist (bsample)

hist(bstraps)

Confidence Interval

Percentile Based

sorted<-sort(bstraps)
percentileCI<-sorted[c(25,975)]
widthpCI<-round(sorted[975]-sorted[25],2)
percentileCI
## [1] 864.5 953.5
widthpCI
## [1] 89

Classical or traditional t based CI estimation Method

xbar<-mean(speed)
n<-length(speed)
SExbar<-sd(speed)/sqrt(n)
tcritical<-qt(.975,n-1)
ClassicalCI<-c(xbar-tcritical*SExbar,xbar+tcritical*SExbar)
ClassicalCI<-round(ClassicalCI,2)
widthCCI<-round(2*tcritical*SExbar,2)
ClassicalCI
## [1] 859.89 958.11
widthCCI
## [1] 98.21

Bootstrap based CI method

sstar<-sd(bstraps)
BootstrapCI<-c(xbar-tcritical*sstar,xbar+tcritical*sstar)
widthBootstrapCI<-round(2*tcritical*sstar,2)
BootstrapCI
## [1] 860.6617 957.3383
widthBootstrapCI
## [1] 96.68