Page 102 - Applied Statistics with R
P. 102

102                      CHAPTER 7. SIMPLE LINEAR REGRESSION


                                 7.2.2   Residuals

                                 If we think of our model as “Response = Prediction + Error,” we can then write
                                 it as


                                                                  = ̂ +   .
                                                                     

                                 We then define a residual to be the observed value minus the predicted value.


                                                                         
                                                                  =    − ̂   
                                                                 
                                                                      
                                 Let’s calculate the residual for the prediction we made for a car traveling 8 miles
                                 per hour. First, we need to obtain the observed value of    for this    value.
                                 which(cars$speed == 8)



                                 ## [1] 5

                                 cars[5, ]



                                 ##   speed dist
                                 ## 5      8   16

                                 cars[which(cars$speed == 8), ]



                                 ##   speed dist
                                 ## 5      8   16


                                 We can then calculate the residual.


                                                             = 16 − 13.88 = 2.12


                                 16 - (beta_0_hat + beta_1_hat * 8)


                                 ## [1] 2.119825


                                 The positive residual value indicates that the observed stopping distance is
                                 actually 2.12 feet more than what was predicted.
   97   98   99   100   101   102   103   104   105   106   107