Exercise 1: Fitting a Line to Sleep and Bugs — Possible Solution ==================================================================== GIVEN ------------------------------ sleep = [7, 5, 8, 4, 6, 7] bugs = [1, 4, 0, 6, 3, 2] STEP 1: THE MEANS ------------------------------ sleep-bar = 37/6 ~= 6.167 bugs-bar = 16/6 ~= 2.667 STEP 2: THE SLOPE ------------------------------ Applying this chapter's own least-squares formula (the same numerator as Chapter 7's own Pearson r calculation) to the sleep/bugs data: m ~= -1.446 STEP 3: THE INTERCEPT ------------------------------ b = bugs-bar - m x sleep-bar ~= 2.667 - (-1.446)(6.167) ~= 11.585 STEP 4: THE FITTED LINE ------------------------------ bugs ~= -1.446 x sleep + 11.585 STEP 5: PREDICTING AT sleep = 6.5 ------------------------------ bugs ~= -1.446(6.5) + 11.585 ~= -9.399 + 11.585 ~= 2.185 So the model predicts approximately 2.19 bugs (roughly 2 bugs) on a day following 6.5 hours of sleep. WHY THIS WORKS AS AN ANSWER ------------------------------ The slope and intercept are computed directly using this chapter's own least-squares formulas, and the prediction is made by plugging the requested sleep value into the resulting fitted line, matching exactly the method demonstrated in this chapter's own CPU/response-time worked example.