
####################################################
#   Function definitions for Chapter 4


################################################
# Function to check the actual coverage of 
# confidence intervals memoryless property of 

CheckCoverage <- function(ev,nRuns,SampleSize,funSample){
  # note that the last input argument to this function
  # is a function itself, used for sample generation
  count <- 0
  for (i in 1:nRuns){
    X <- funSample(sampleSize, ev)
    CI <- t.test(X, conf.level = 1-alpha)$conf.int
    # count the cases in which we fail to include the
    # true expected value
    if (ev < CI[1] || ev > CI[2]) count <- count+1
  }
  return(1-count/nRuns)
}

