Problems
Loading...
1 / 1

Bootstrap Mean & Confidence Interval

Probability and Statistics
Medium

Estimate the mean of a 1D dataset using bootstrap resampling. Repeatedly sample with replacement from the array, compute the mean for each resample, and use these bootstrap means to estimate a confidence interval.

Mathematical Definition

Bootstrap Mean Distribution:

Xˉb=1Ni=1NXi,b=1,2,,B\bar{X}^{*}_{b} = \frac{1}{N} \sum_{i=1}^{N} X^{*}_{i}, \qquad b = 1, 2, \ldots, B

where Xi∗ are sampled with replacement from the original data, and B is the number of bootstrap samples.

Confidence Interval:

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

where α=1−ci and Qp pdenotes the p-th quantile.

Function Arguments

  • x: 1D array-like, shape (N,) - input observations
  • n_bootstrap: int - number of bootstrap samples
  • ci: float - confidence level (e.g., 0.95 for 95%)
  • rng: np.random.Generator or None - random number generator for reproducibility
Loading visualization...

Examples

Input: x = [1.0, 2.0, 3.0, 4.0], n_bootstrap=1000, ci=0.90

Output: boot_means.shape = (1000,), lower ≈ 1.5, upper ≈ 3.5

Input: x = [5.0], n_bootstrap=1000, ci=0.95

Output: boot_means.shape = (1000,), lower = 5.0, upper = 5.0

Hint 1

Use rng.integers() to generate bootstrap indices for each iteration.

Hint 2

For 95% CI, use quantiles at 0.025 and 0.975. For general ci, use alpha = (1 - ci) / 2.

Requirements

  • Return tuple: (boot_means, lower, upper)
  • boot_means: NumPy array of shape (n_bootstrap,)
  • lower, upper: scalars with lower < upper
  • Use rng.integers() if rng provided, else np.random
  • Use np.quantile() for confidence bounds

Constraints

  • 1 ≤ len(x) ≤ 10,000
  • 100 ≤ n_bootstrap ≤ 10,000
  • Use NumPy only
  • Time limit: 2s
Try Similar Problems