Skip to main content

bootstrap_median

Function bootstrap_median 

Source
pub fn bootstrap_median(
    values: &[f64],
    level_bp: u32,
    resamples: u32,
    seed: u64,
    min_n: usize,
) -> Option<EconomicsInterval>
Expand description

A percentile bootstrap interval of the median: resample the values with replacement resamples times, take each resample’s median, and report the quantiles of those medians at the requested confidence. The values are sorted first, so the interval depends on the set of values and the seed, never on the order they were listed in. None below min_n values: an interval over two pairs would be precision nobody has.

Resampling each value on its own assumes the values are independent. That holds for the context suite’s seeds, each a separate compilation; it does not hold for the repetitions of one task, which is what bootstrap_median_clustered is for.

use majordomus_cli::economics::stats::{bootstrap_median, INDEPENDENT_METHOD};
let v = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6];
let a = bootstrap_median(&v, 9500, 2000, 7, 5).unwrap();
let b = bootstrap_median(&[0.6, 0.5, 0.4, 0.3, 0.2, 0.1], 9500, 2000, 7, 5).unwrap();
assert_eq!(a, b, "order does not matter");
assert!(a.low <= 0.35 && 0.35 <= a.high);
assert_eq!(a.method, INDEPENDENT_METHOD);
assert!(bootstrap_median(&v[..3], 9500, 2000, 7, 5).is_none());