Jackknife confidence interval for the median
In this exercise, we will calculate the jackknife 95% CI for a non-standard estimator. Here, we will look at the median. Keep in mind that the variance of a jackknife estimator is n-1
times the variance of the individual jackknife sample estimates where n
is the number of observations in the original sample.
Returning to the wrench factory, you are now interested in estimating the median length of the wrenches along with a 95% CI to ensure that the wrenches are within tolerance.
Let's revisit the code from the previous exercise, but this time in the context of median lengths. By the end of this exercise, you will have a much better idea of how to use jackknife resampling to calculate confidence intervals for non-standard estimators.
This is a part of the course
“Statistical Simulation in Python”
Exercise instructions
- Append the median length of each jackknife sample to
median_lengths
. - Calculate the mean of the jackknife estimate of
median_length
and assign tojk_median_length
. - Calculate the upper 95% confidence interval
jk_upper_ci
and lower 95% confidence intervals of the medianjk_lower_ci
using1.96*np.sqrt(jk_var)
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Leave one observation out to get the jackknife sample and store the median length
median_lengths = []
for i in range(n):
jk_sample = wrench_lengths[index != i]
median_lengths.append(____)
median_lengths = np.array(median_lengths)
# Calculate jackknife estimate and it's variance
jk_median_length = ____
jk_var = (n-1)*np.var(median_lengths)
# Assuming normality, calculate lower and upper 95% confidence intervals
jk_lower_ci = jk_median_length - ____
jk_upper_ci = jk_median_length + ____
print("Jackknife 95% CI lower = {}, upper = {}".format(jk_lower_ci, jk_upper_ci))
This exercise is part of the course
Statistical Simulation in Python
Learn to solve increasingly complex problems using simulations to generate and analyze data.
In this chapter, we will get a brief introduction to resampling methods and their applications. We will get a taste of bootstrap resampling, jackknife resampling, and permutation testing. After completing this chapter, students will be able to start applying simple resampling methods for data analysis.
Exercise 1: Introduction to resampling methodsExercise 2: Sampling with replacementExercise 3: Probability exampleExercise 4: BootstrappingExercise 5: Running a simple bootstrapExercise 6: Non-standard estimatorsExercise 7: Bootstrapping regressionExercise 8: Jackknife resamplingExercise 9: Basic jackknife estimation - meanExercise 10: Jackknife confidence interval for the medianExercise 11: Permutation testingExercise 12: Generating a single permutationExercise 13: Hypothesis testing - Difference of meansExercise 14: Hypothesis testing - Non-standard statisticsWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.