All problems
Bootstrap Confidence Interval
Problem
Compute a bootstrap confidence interval for the mean. Call random.seed(seed) and draw num_samples bootstrap resamples of size n with replacement using random.randrange(n), recording each resample mean.
Sort the means, then take the values at indices int((1 - confidence) / 2 * num_samples) and int((1 + confidence) / 2 * num_samples), clamping both to num_samples - 1. Return [lower, upper]. Empty data returns [0.0, 0.0].
Hint
Build the sorted list of resample means, then index it at the two percentile positions.
Test cases
case 1
in: [[1,2,3,4,5,6,7,8],200,0.95,42]
expected: [3,6.25]
case 2
in: [[10,12,11,13,12],100,0.9,7]
expected: [10.8,12.2]
case 3
in: [[10,20,30],50,0.8,1]
expected: [16.666666666666668,26.666666666666668]
case 4
in: [[5,5,5,5],20,0.5,0]
expected: [5,5]
Starter codePython
import random
def bootstrap_mean_ci(data, num_samples, confidence, seed):
# Returns [lower, upper]
# Your code here
pass4 test cases · run your code against them in the editor