Page 108 - Applied Statistics with R
P. 108

108                      CHAPTER 7. SIMPLE LINEAR REGRESSION


                                           SSReg (Sum of Squares Regression)   SSE (Sum of Squares Error)

                                    10                                10

                                    0                                 0

                                    -10                               -10
                                  y                                 y
                                    -20                               -20


                                    -30                               -30

                                      0    2    4     6    8    10      0     2    4    6    8    10
                                                   x                                 x
                                             SST (Sum of Squares Total)        SST (Sum of Squares Total)

                                    10                                10

                                    0                                 0

                                    -10                               -10
                                  y                                 y
                                    -20                               -20

                                    -30                               -30

                                      0    2    4     6    8    10      0     2    4    6    8    10
                                                   x                                 x




                                 7.4 The lm Function


                                 So far we have done regression by deriving the least squares estimates, then
                                 writing simple R commands to perform the necessary calculations. Since this is
                                 such a common task, this is functionality that is built directly into R via the
                                 lm() command.
                                 The lm() command is used to fit linear models which actually account for
                                 a broader class of models than simple linear regression, but we will use SLR
                                 as our first demonstration of lm(). The lm() function will be one of our most
                                 commonly used tools, so you may want to take a look at the documentation by
                                 using ?lm. You’ll notice there is a lot of information there, but we will start
                                 with just the very basics. This is documentation you will want to return to
                                 often.
   103   104   105   106   107   108   109   110   111   112   113