bootstrap#

rojak.atmosphere.feature_composite.bootstrap(counts, statistic, *, n_samples=1000, quantiles=(0.025, 0.5, 0.975), seed=None)[source]#

Quantiles of any statistic of the counts, from a block bootstrap over the chunks.

Observations in the same chunk are not independent: they come from the same flights and the same features. The chunks are therefore the independent unit, and each sample draws n_chunks whole chunks with replacement. The same draw is used for every variable, so the counts of a chunk stay together, and every other dimension (control, the bins) is left untouched. Features that last longer than a chunk are still split between chunks, so chunks that are long compared to the life of a feature give more conservative intervals.

statistic is called once per sample, on a resampled Dataset with the same dimensions and sizes as counts, so it may be any function of the counts, e.g. impact_statistics() or a functools.partial of it.

Parameters:
  • counts (xarray.Dataset) – Per-chunk counts with a chunk dimension, as returned by the pipeline. Computed once here if lazy, rather than once per sample.

  • statistic (Callable[[xarray.Dataset], xarray.Dataset]) – Function from counts to the statistics to bootstrap.

  • n_samples (int) – Number of bootstrap samples. At least 1. Memory scales as n_samples times the size of one result of statistic.

  • quantiles (Sequence[float]) – Quantiles to return, each within [0, 1].

  • seed (int | None) – Seed of numpy.random.default_rng(). None draws a fresh seed.

Returns:

The quantiles of each variable of statistic over the samples, with a quantile dimension in addition to the dimensions of the variable.

Return type:

xarray.Dataset

Raises:

ValueError – If n_samples is below 1 or a quantile is outside [0, 1].