You have one small sample and you want to know how much its mean could have wobbled. The bootstrap answers that without any formula: pretend your sample is the population, draw new samples from it with replacement, and look at how much the mean moves around.
Here the draws are handed to you so the answer is reproducible. resample_indices is a list of draws, and each draw is a list of positions into values — the same position may appear more than once, which is what "with replacement" means.
Task: write bootstrap_ci(values, resample_indices, confidence) returning [centre, lower, upper], each rounded to 4 decimal places:
centre is the mean of all those bootstrap means.lower and upper are the percentile edges that leave confidence percent in the middle. With confidence = 90, you cut 5% off each end, so you want the 5th and 95th percentiles of the bootstrap means.For those two percentiles, use the same sliding rule as the percentile problem, on the sorted bootstrap means:
where m is how many bootstrap means you have, interpolating between neighbours when the position isn't a whole number.
(100 - confidence) / 2 percent, so the two percentiles are at tail and 100 - tail.values.The width of that interval is the real output here: a narrow one means the mean is pinned down, a wide one means your sample is too small to say much.