Bootstrap Mean & Confidence Interval
Bootstrap Mean & Confidence Interval
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∗=N1i=1∑NXi∗,b=1,2,…,Bwhere 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ˉ∗)]where α=1−ci and Qp pdenotes the p-th quantile.
Function Arguments
x: 1D array-like, shape (N,)- input observationsn_bootstrap: int- number of bootstrap samplesci: float- confidence level (e.g., 0.95 for 95%)rng: np.random.Generator or None- random number generator for reproducibility
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, elsenp.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
Log in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number
Accepts: number
Bootstrap Mean & Confidence Interval
Bootstrap Mean & Confidence Interval
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∗=N1i=1∑NXi∗,b=1,2,…,Bwhere 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ˉ∗)]where α=1−ci and Qp pdenotes the p-th quantile.
Function Arguments
x: 1D array-like, shape (N,)- input observationsn_bootstrap: int- number of bootstrap samplesci: float- confidence level (e.g., 0.95 for 95%)rng: np.random.Generator or None- random number generator for reproducibility
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, elsenp.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
Log in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number
Accepts: number