1. Learn
  2. /
  3. Courses
  4. /
  5. Statistical Thinking in Python (Part 2)

Connected

Exercise

A function to do pairs bootstrap

As discussed in the video, pairs bootstrap involves resampling pairs of data. Each collection of pairs fit with a line, in this case using np.polyfit(). We do this again and again, getting bootstrap replicates of the parameter values. To have a useful tool for doing pairs bootstrap, you will write a function to perform pairs bootstrap on a set of x,y data.

Instructions

100 XP
  • Define a function with call signature draw_bs_pairs_linreg(x, y, size=1) to perform pairs bootstrap estimates on linear regression parameters.
    • Use np.arange() to set up an array of indices going from 0 to len(x). These are what you will resample and use them to pick values out of the x and y arrays.
    • Initialize the slope and intercept replicate arrays.
    • Write a for loop to:
      • Resample the indices.
      • Make new \(x\) and \(y\) arrays using the indices you resampled.
      • Use np.polyfit() on the new \(x\) and \(y\) arrays and store the computed slope and intercept.
    • Return the pair bootstrap replicates of the slope and intercept.