Correlation of offspring and parental data
In an effort to quantify the correlation between offspring and parent beak depths, we would like to compute statistics, such as the Pearson correlation coefficient, between parents and offspring. To get confidence intervals on this, we need to do a pairs bootstrap.
You have already written a function to do pairs bootstrap to get estimates for parameters derived from linear regression. Your task in this exercise is to modify that function to make a new function with call signature draw_bs_pairs(x, y, func, size=1) that performs pairs bootstrap and computes a single statistic on the pairs samples defined by func(bs_x, bs_y). In the next exercise, you will use pearson_r for func.
This exercise is part of the course
Statistical Thinking in Python (Part 2)
Exercise instructions
- We have provided your original
draw_bs_pairs_linreg()function (named asdraw_bs_pairs()). Modify this function to make thedraw_bs_pairs()function described above. Be sure to adjust the doc string appropriately, and remember that in this modified function, you only need to return a single statistic. - Things to keep in mind: The modified function requires an additional
funcparameter and returns onlybs_replicates, as opposed tobs_slope_repsandbs_intercept_repsas the function in the sample code does.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
def draw_bs_pairs(x, y, size=1):
"""Perform pairs bootstrap for linear regression."""
# Set up array of indices to sample from: inds
inds = ____
# Initialize replicates
bs_slope_reps = ____
bs_intercept_reps = ____
# Generate replicates
for i in range(size):
bs_inds = ____
bs_x, bs_y = ____
bs_slope_reps[i], bs_intercept_reps[i] = ____
return bs_slope_reps, bs_intercept_reps