Linear regressions
Perform a linear regression for both the 1975 and 2012 data. Then, perform pairs bootstrap estimates for the regression parameters. Report 95% confidence intervals on the slope and intercept of the regression line.
You will use the draw_bs_pairs_linreg()
function you wrote back in chapter 2.
As a reminder, its call signature is draw_bs_pairs_linreg(x, y, size=1)
, and it returns bs_slope_reps
and bs_intercept_reps
. The beak length data are stored as bl_1975
and bl_2012
, and the beak depth data is stored in bd_1975
and bd_2012
.
This exercise is part of the course
Statistical Thinking in Python (Part 2)
Exercise instructions
- Compute the slope and intercept for both the 1975 and 2012 data sets.
- Obtain 1000 pairs bootstrap samples for the linear regressions using your
draw_bs_pairs_linreg()
function. - Compute 95% confidence intervals for the slopes and the intercepts.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Compute the linear regressions
slope_1975, intercept_1975 = ____
slope_2012, intercept_2012 = ____
# Perform pairs bootstrap for the linear regressions
bs_slope_reps_1975, bs_intercept_reps_1975 = \
____
bs_slope_reps_2012, bs_intercept_reps_2012 = \
____
# Compute confidence intervals of slopes
slope_conf_int_1975 = ____
slope_conf_int_2012 = ____
intercept_conf_int_1975 = ____
intercept_conf_int_2012 = ____
# Print the results
print('1975: slope =', slope_1975,
'conf int =', slope_conf_int_1975)
print('1975: intercept =', intercept_1975,
'conf int =', intercept_conf_int_1975)
print('2012: slope =', slope_2012,
'conf int =', slope_conf_int_2012)
print('2012: intercept =', intercept_2012,
'conf int =', intercept_conf_int_2012)