Session Ready
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.
    • Use np.empty() to initialize the slope and intercept replicate arrays to be of size size.
    • Write a for loop to:
      • Resample the indices inds. Use np.random.choice() to do this.
      • Make new \(x\) and \(y\) arrays bs_x and bs_y using the the resampled indices bs_inds. To do this, slice x and y with bs_inds.
      • 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.