Page 177 - Applied Statistics with R
P. 177

9.5. SIMULATION                                                   177


                      # SSE (For Full)
                      sum(resid(full_mpg_model) ^ 2)


                      ## [1] 4530.466

                      # SST (For Null)
                      sum(resid(null_mpg_model) ^ 2)


                      ## [1] 4556.646

                      # Degrees of Freedom: Diff
                      length(coef(full_mpg_model)) - length(coef(null_mpg_model))



                      ## [1] 4

                      # Degrees of Freedom: Full
                      length(resid(full_mpg_model)) - length(coef(full_mpg_model))


                      ## [1] 383


                      # Degrees of Freedom: Null
                      length(resid(null_mpg_model)) - length(coef(null_mpg_model))


                      ## [1] 387



                      9.5 Simulation

                      Since we ignored the derivation of certain results, we will again use simulation to
                      convince ourselves of some of the above results. In particular, we will simulate
                      samples of size n = 100 from the model


                                        = 5 + −2   + 6   +    ,     = 1, 2, … ,   
                                        
                                                   1
                                                              
                                                         2
                                      2
                      where    ∼   (0,    = 16). Here we have two predictors, so    = 3.
                               
                      set.seed(1337)
                      n = 100 # sample size
                      p = 3
   172   173   174   175   176   177   178   179   180   181   182