package student.activities import ksl.utilities.statistic.BSEstimatorIfc import ksl.utilities.statistic.Bootstrap import ksl.utilities.statistic.Statistic import java.nio.file.Path import kotlin.io.path.readLines /** * Bootstrapping the mean and the 90th percentile of 200 service times * (minutes) at the pharmacy's window. The activity writes the parts marked * TODO. As given, the file compiles and runs, and reports the sample. */ fun main() { val numBootstrapSamples = 400 // the data file: change the path to where you saved pharmacy-service-times.csv val file = Path.of("docs/activities/advanced-monte-carlo/data/pharmacy-service-times.csv") // the first line of the file is its header val data = file.readLines().drop(1).map { it.trim().toDouble() }.toDoubleArray() // Part 1: the sample val stat = Statistic("Service times", data) println("n = %d, average = %.4f, std. dev. = %.4f".format(data.size, stat.average, stat.standardDeviation)) println("t-based 95% c.i. for the mean = ${stat.confidenceInterval(0.95)}") // percentile() sorts the array it is given, so give it a copy println("sample 90th percentile = %.4f".format(Statistic.percentile(data.copyOf(), 0.90))) println() // TODO 1: bootstrap the mean. Make a Bootstrap on the data with the // estimator BSEstimatorIfc.Average() and stream 3, generate // numBootstrapSamples samples, and print it. // TODO 2: bootstrap the 90th percentile. Write a BSEstimatorIfc that returns // the 90th percentile of the sample it is given, and bootstrap it as in // TODO 1, with stream 4. // TODO 3: bootstrap the maximum, with BSEstimatorIfc.Maximum() and stream 5. }