Pairs bootstrap of literacy/fertility data
Using the function you just wrote, perform pairs bootstrap to plot a histogram describing the estimate of the slope from the illiteracy/fertility data. Also report the 95% confidence interval of the slope. The data is available to you in the NumPy arrays illiteracy
and fertility
.
As a reminder, draw_bs_pairs_linreg()
has a function signature of draw_bs_pairs_linreg(x, y, size=1)
, and it returns two values: bs_slope_reps
and bs_intercept_reps
.
This exercise is part of the course
Statistical Thinking in Python (Part 2)
Exercise instructions
- Use your
draw_bs_pairs_linreg()
function to take1000
bootstrap replicates of the slope and intercept. The x-axis data isilliteracy
and y-axis data isfertility
. - Compute and print the 95% bootstrap confidence interval for the slope.
- Plot and show a histogram of the slope replicates. Be sure to label your axes. This has been done for you, so click submit to see your histogram!
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Generate replicates of slope and intercept using pairs bootstrap
bs_slope_reps, bs_intercept_reps = ____
# Compute and print 95% CI for slope
print(np.percentile(____, ____))
# Plot the histogram
_ = plt.hist(bs_slope_reps, bins=50, normed=True)
_ = plt.xlabel('slope')
_ = plt.ylabel('PDF')
plt.show()