bootstrapConfidenceIntervals method
Bootstrap confidence intervals for statistics.
Example:
final petalWidth = petals.numericColumns["petal_width"]!,
species = petals.categoricColumns["species"]!;
print("Petal width:");
for (final MapEntry(:key, :value) in
(await petalWidth.bootstrapConfidenceIntervals(
simulations: 10000,
confidence: 0.9,
)).entries) {
final (lower, upper) = value;
print("$key: "
"(${lower.toStringAsFixed(2)}, ${upper.toStringAsFixed(2)})");
}
print("\nSpecies:");
for (final MapEntry(:key, :value) in
(await species.bootstrapConfidenceIntervals(
simulations: 10000,
confidence: 0.9,
)).entries) {
final (lower, upper) = value;
print("$key: "
"(${lower.toStringAsFixed(2)}, ${upper.toStringAsFixed(2)})");
}
Petal width:
sum: (10.30, 19.40)
sumOfSquares: (15.34, 37.10)
mean: (0.86, 1.62)
variance: (0.32, 0.83)
inferredVariance: (0.35, 0.91)
standardDeviation: (0.57, 0.91)
inferredStandardDeviation: (0.59, 0.95)
skewness: (-0.30, 0.15)
meanAbsoluteDeviation: (0.41, 0.84)
lowerQuartile: (0.20, 1.45)
median: (0.20, 1.80)
upperQuartile: (1.42, 2.10)
interQuartileRange: (0.40, 1.85)
maximum: (1.90, 2.50)
maximumNonOutlier: (1.80, 2.50)
minimum: (0.20, 0.20)
minimumNonOutlier: (0.20, 1.40)
range: (1.70, 2.30)
Species:
impurity: (0.49, 0.67)
entropy: (0.82, 1.10)
Implementation
Future<Map<String, (num, num)>> bootstrapConfidenceIntervals({
int simulations = 1000,
num confidence = 0.95,
}) async {
final sample = {
for (final key in (this is NumericColumn
? NumericStat.values
: CategoricStat.values))
key.name: NumericColumn([])
};
while (simulations > 0) {
for (final MapEntry(:key, :value) in bootstrap().summary.entries) {
sample[key]!.add(value);
}
simulations--;
}
if (confidence > 1) {
confidence /= 100;
}
if (confidence < 0 || confidence > 1) {
throw PackhorseError.badArgument("Confidence $confidence expected to be"
"a proportion in [0, 1] or a percentage in [0, 100]");
}
final lower = (1 - confidence) / 2, upper = 1 - lower;
return {
for (final MapEntry(:key, :value) in sample.entries)
key: (value.tile(lower), value.tile(upper)),
};
}