Bootstrap CI: Standard Error and Confidence Interval
Xem dạng PDF
Gửi bài giải
Điểm:
100,00
Giới hạn thời gian:
2.0s
Giới hạn bộ nhớ:
256M
Tác giả:
Dạng bài
Ngôn ngữ cho phép
Python
Problem Statement
Given a dataset X of n values, perform a bootstrap analysis of the sample mean and return:
- The bootstrap standard error of the mean (std of bootstrap means,
ddof=0) - The 2.5th percentile of bootstrap means (lower CI bound)
- The 97.5th percentile of bootstrap means (upper CI bound)
- The width of the 95% CI (upper - lower)
Use numpy.random.default_rng(seed) and rng.choice(n, size=n, replace=True) for sampling.
Function signature:
def bootstrap_analysis(X: np.ndarray, b: int, seed: int) -> tuple:
# returns (se, lo, hi, width)
Input Format
Line 1: n b seed — number of data points, bootstrap resamples, random seed
Line 2: n space-separated floats — the data values
Output Format
Four lines (8 decimal places each):
- Bootstrap standard error
- 2.5th percentile (lower bound)
- 97.5th percentile (upper bound)
- CI width
Example
Input:
5 200 42
1.0 2.0 3.0 4.0 5.0
Output:
0.59268794
1.80000000
4.00500000
2.20500000
Derivation
The bootstrap estimates the sampling distribution of the mean empirically. With b resamples, each of size n:
- Each resample mean
m_i = mean(X[resample_i]) - SE = std({m_i})
- The percentile bootstrap CI directly uses the α/2 and 1-α/2 quantiles of {m_i}
This is valid even when the underlying distribution is unknown, relying only on the data.
Notes
- Use
numpy.random.default_rng(new-style RNG), notnumpy.random.seed. - The standard error decreases as
ngrows; the CI width reflects estimation uncertainty. - With only 5 points and 200 resamples, variability is high.
Bình luận