CallCenter<-read.csv("calls80 copy.csv", 
                     header=TRUE)
head(CallCenter)
##   length
## 1     77
## 2    289
## 3    128
## 4     59
## 5     19
## 6    148
hist(CallCenter$length)

mean(CallCenter$length)
## [1] 196.575
nsim=1000
bootStrapCI1<-function(data, nsim){
  n<-length(data)
  bootCI<-c()
  
  for(i in 1:nsim){
    bootSamp<-sample(1:n, n, replace=TRUE)
    thisXbar<-mean(data[bootSamp])
    bootCI<-c(bootCI, thisXbar)
  }
  return(bootCI)
}

# By hand
xbar<-mean(CallCenter$length) #196.575
sd<-sd(CallCenter$length) #342.0215
sd
## [1] 342.0215
n<-length(CallCenter$length) #80
n
## [1] 80
se<-sd/sqrt(n) #19.32248
se
## [1] 38.23917
mu_0<-130 # One-sided upper alternative I do not know why it is 130

test_stat<-(xbar-mu_0)/se
test_stat #1.74016
## [1] 1.741016
# Bootstrap confidence interval for the mean
lengthBootCI<-bootStrapCI1(CallCenter$length, nsim=1000)

# Approximated sampling distribution
hist(lengthBootCI)

qqnorm(lengthBootCI)
qqline(lengthBootCI)

#10 object sample new bootstrap
###104 102 35 211 56 325 67 9 179 59

SRS<-c(104, 102, 35, 211, 56, 325, 67, 179, 59)


# Function for bootstrap confidence interval 
# for one sample mean
bootStrapCI1<-function(data, nsim){
  n<-length(data)
  bootCI<-c()
  
  for(i in 1:nsim){
    bootSamp<-sample(1:n, n, replace=TRUE)
    thisXbar<-mean(data[bootSamp])
    bootCI<-c(bootCI, thisXbar)
  }
  return(bootCI)
}

# By hand
xbarr<-mean(SRS) #126.44
sdd<-sd(SRS) #94.76565
nn<-length(SRS) #9
see<-sdd/sqrt(nn) #31.59955
mu_00<-130 # One-sided upper alternative 

test_statss<-(xbarr-mu_00)/see 
test_statss #-0.11255
## [1] -0.1125584
SRSBootCI<-bootStrapCI1(SRS, nsim=1000)
# Approximated sampling distribution
hist(SRSBootCI)