Activity: Bootstrapping a Percentile
Advanced Monte Carlo Activities
We write this code together: the instructor types the code, and you type along. Before each run, write down a prediction; then run and check it.
The situation. The file pharmacy-service-times.csv holds 200 service times, in minutes, at a pharmacy’s drive-through window. The manager wants to post a promise: “90% of our customers are served within \(x\) minutes.” Let \(x_{0.9}\) represent the 90th percentile of the service time. Estimate \(x_{0.9}\) from the sample, with a 95% confidence interval, and recommend the \(x\) to post.
Setup. Get the starter file BootstrapPercentile.kt from the code/ folder beside this activity, and the data file pharmacy-service-times.csv from the data/ folder. Put the starter in src/main/kotlin/student/activities in your KSL project, the package the file declares; create the folder if you do not have it. The first lines of main give the path to the data file: change it to where you saved the file. Run main: it reports the sample, and the three parts marked TODO are what we write.
1. The sample
Run. Write down the sample average, its t-based confidence interval, and the sample 90th percentile.
Why can we not use the t-based interval, or a formula like it, for \(x_{0.9}\)?
Predict: will the confidence interval for \(x_{0.9}\) be wider or narrower than the interval for the mean? By about how much?
2. Bootstrapping the mean
TODO 1. We make a
Bootstrapon the data with the estimatorBSEstimatorIfc.Average(), generate 400 bootstrap samples, and print it. Before you run, predict how its percentile interval will compare with the t-based interval of 1a.Run. Compare the bootstrap standard error with \(s/\sqrt{n}\), where \(s\) is the sample standard deviation and \(n = 200\). Why do the two agree?
3. Bootstrapping the 90th percentile
TODO 2. A
BSEstimatorIfcis a function from a sample to one number. We write one that returns the sample’s 90th percentile withStatistic.percentile(), and bootstrap it as in TODO 1. Run. What is the percentile interval for \(x_{0.9}\)? How does its width compare with your prediction in 1c?Is the interval symmetric about the estimate? What does that say about the sampling distribution of the sample 90th percentile?
What \(x\) would you recommend that the manager post, and why?
The instructor will tell you the distribution the data came from, and its 90th percentile. Does your interval contain it?
4. More bootstrap samples
Predict: if we generate 4000 bootstrap samples instead of 400, how will the interval for \(x_{0.9}\) change?
Change
numBootstrapSamplesto 4000 and run. What changed, and what did not? What would make the interval narrower?
5. The longest service time
TODO 3. We bootstrap the maximum with
BSEstimatorIfc.Maximum(). Before you run, predict: can a bootstrap sample have a maximum larger than the sample’s maximum?Run. Look at the upper limit of the percentile interval. Explain it.
What fraction of the bootstrap samples contain the sample’s largest observation at least once? What does that do to the bootstrap distribution of the maximum?
When does the bootstrap work well, and when does it fail?