bootstrapMean function
The mean of values and its 95 % percentile bootstrap interval over
resamples resamples from a generator seeded with seed.
Implementation
(double, double, double) bootstrapMean(
List<double> values, {
int resamples = 10000,
int seed = 0,
}) {
if (values.isEmpty) throw ArgumentError('no values');
final n = values.length;
final mean = values.reduce((a, b) => a + b) / n;
final random = math.Random(seed);
final means = Float64List(resamples);
for (var r = 0; r < resamples; r++) {
var sum = 0.0;
for (var i = 0; i < n; i++) {
sum += values[random.nextInt(n)];
}
means[r] = sum / n;
}
means.sort();
return (
mean,
means[(0.025 * (resamples - 1)).round()],
means[(0.975 * (resamples - 1)).round()],
);
}