mcframework.stats_engine.ci_mean_bootstrap#

mcframework.stats_engine.ci_mean_bootstrap(x: ndarray, ctx: StatsContext) dict[str, float | str] | None[source]#

Bootstrap confidence interval for \(\mathbb{E}[X]\) via resampling.

Generates n_bootstrap bootstrap samples by drawing with replacement from the input data, computes the mean of each sample, and returns the percentile-based confidence interval from the resulting bootstrap distribution.

The CI is constructed as

\[\left[\,Q_{\alpha/2}(\bar X^*),\; Q_{1-\alpha/2}(\bar X^*)\,\right],\]

where \(\bar X^*\) denotes the bootstrap means and \(\alpha = 1 - \text{confidence}\).

Parameters:
xndarray

Input sample.

ctxStatsContext or Mapping

Configuration that may specify:

  • confidence

    Confidence level \(\in (0, 1)\).

  • n_bootstrap

    Number of bootstrap resamples (default 10_000).

  • nan_policy

    Whether to omit non-finite values before bootstrapping.

  • bootstrap

    Flavor ("percentile" or "bca").

  • rng

    Seed or generator for reproducibility.

Returns:
dict or None

Mapping with keys:

  • confidence : float The requested confidence level.

  • method : str "bootstrap-percentile" or "bootstrap-bca".

  • low : float Lower bound of the CI.

  • high : float Upper bound of the CI.

Returns None if the sample is empty after cleaning.

See also

ci_mean

Parametric CI using z/t critical values.

ci_mean_chebyshev

Distribution-free CI via Chebyshev’s inequality.

Notes

The bootstrap percentile method is distribution-free and asymptotically valid under mild regularity conditions. For small samples, it may have lower coverage than the nominal confidence level.

Examples

>>> x = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
>>> result = ci_mean_bootstrap(x, {"confidence": 0.9, "n_bootstrap": 5000, "rng": 42})
>>> result["method"]
'bootstrap-percentile'
>>> 1.5 < result["low"] < result["high"] < 4.5
True