← 返回 pinterest 的题目列表Implement Bootstrap Confidence Interval and Jackknife Standard Error for a Two-Group Metric
类型:online_judge
Problem: Implement Bootstrap and Jackknife
You are given an experimental dataset. Each row contains a group id and a numeric metric. The group id is either 0 or 1.
Compute:
The observed metric: mean of group=1 minus mean of group=0;
A percentile confidence interval using stratified bootstrap:
In each bootstrap iteration, sample with replacement within each group separately;
Keep the original sample size of each group;
Use random seed 0;
The jackknife standard error of the same difference-in-means estimator:
Each jackknife sample removes one row and recomputes the difference in means;
Use the formula:
[ SE = \sqrt{\frac{n-1}{n}\sum_{i=1}^{n}(\theta_i - \bar{\theta})^2} ]
where theta_i is the estimate after removing row i, and bar(theta) is the average of all leave-one-out estimates.
Input Format
The first line contains:
n B alpha
n: number of rows;
B: number of bootstrap resamples;
alpha: significance level, e.g. 0.05 means a 95% confidence interval.
The next n lines each contain:
group value
where group is 0 or 1, and value is a float.
Output Format
Print four floating point numbers rounded to 6 decimals:
observed_diff ci_lower ci_upper jackknife_se
Constraints
4 <= n <= 10^5
1 <= B <= 5000
Each group contains at least 2 rows
-10^9 <= value <= 10^9
Example
Input:
4 10 0.05
0 1
0 1
1 3
1 3
Output:
2.000000 2.000000 2.000000 0.000000
Example
Input
4 10 0.05
0 1
0 1
1 3
1 3
Output
2.000000 2.000000 2.000000 0.000000