── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Code
library(alr4)
Loading required package: car
Loading required package: carData
Attaching package: 'car'
The following object is masked from 'package:purrr':
some
The following object is masked from 'package:dplyr':
recode
Loading required package: effects
lattice theme set by effectsTheme()
See ?effectsTheme for details.
We can find that \(R^2\) from the model 1 is 0.6326149, \(R^2\) from the model 2 is 0.4637387 and \(R^2\) from the full model is 0.6773765. Certainly \(R^2\) from the model 1 much more closer to full model. So we can find that trks and acpt are more important in model. Slim does not significantly improve the model.
How much additional variation is explained by the addition of slim to model 1?
Code
0.6773765-0.6326149
[1] 0.0447616
Almost 0.0447616 additional variation is explained by the addition of slim to model 1.
Create an added variable plot for slim and add the best fitting line. (Hint: unlike the example in class, there are two other regressors in the problem besides slim.)
Code
rate_y <-residuals(lm(rate ~ trks + acpt, data = Highway))slim_x <-residuals(lm(slim ~ trks + acpt, data = Highway))avp_data <-data.frame(rate_y, slim_x)ggplot(avp_data, aes(x = slim_x, y = rate_y)) +geom_point(alpha =0.7) +geom_smooth(method ="lm", color ="lightblue") +theme_bw()