1b. ## Based on the boxplot I created, it appears that cars with less cylinders tend to have a higher mpg.
1c. cor(mtcars$mpg, mtcars) ## The variables that are most stongly correlated with mpg are weight and the number of cylinders. Both of these variables show a negative correlation.
2b. boxplot(mtcars) ## There does not appear to be any inconsistent data in the mtcars dataset.
3b. ## This regression model looks at the effect on different car characteristics on mpg. Weight (wt) has the strongest negative effect on mpg, Other variables, such as horsepower (hp) and displacement (disp) have insignificant effects on mpg.
3c. par(mfrow = c(2,2)) plot(model1) ## residuals v fitted- shows a slight curve, showing that the relationship may not be exactly linear. ## QQ plot- most residuals lie close to the line, showing that residuals are mostly normal. ## scale location- the plots are very scattered, showing that residuals may not have much correlation. ## residuals v leverage- shows a few points of high leverage, but no influential values.
3d. mean(model1$residuals^2) ## mean standard error = 4.609201
3e. model2 <- lm(mpg ~ wt * hp + cyl + disp + drat + qsec + vs + am + gear + carb, data = mtcars) summary(model2) ## Like the original model, weight has the largest effect on mpg. Horsepower and weight also appeared to be signifigant, and it can be observed that the effect on weight on mpg changes depending on horsepower.
3f. model2 <- lm(mpg ~ wt * hp + cyl + disp + drat + qsec + vs + am + gear + carb, data = mtcars) par(mfrow = c(2, 2)) plot(model2) mtcars_clean <- mtcars[-15, ] model3 <- lm(mpg ~ wt * hp + cyl + disp + drat + qsec + vs + am + gear + carb, data = mtcars_clean) summary(model3) summary(model2)\(r.squared summary(model3)\)r.squared ## After visualizing my observations, the Residuals v Leverage plot showed both high leverage and a large residual. I removed this point and refit the model, and as a result R^2 increased.