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 coolection 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<-sorted[975]-sorted[25]
percentileCI
## [1] 859.5 951.0
widthpCI
## [1] 91.5

Classical 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<-2*tcritical*SExbar
ClassicalCI
## [1] 859.89 958.11
widthCCI
## [1] 98.2138