data(“mtcars”)

summary(mtcars)

Q1.2

The cars with the highest MPG also have the lowest weight, descending in a linear fashion

Q1.3

To that end the most noticeable variables correlated with MPG is weight and number of cylinders

colSums(is.na(mtcars))

Q2.1 & 2.2

Using function colsums shows that non of the columns have missing data values

model_1 <- lm(mpg ~ wt + hp, data = mtcars) summary(model_1)

Q3.2 Interpretation

HP constant, for every increase of 1000 lbs in weight, the car’s efficiency will decrease by ~3.88 mpg. And with WT constant, for each increase in horsepower by one unit, efficiency drops by ~0.032 mpg.

Q3.4

error <- model_1$residuals

mse <- mean(error^2)

mse

Q3.4/Q3.5 Continued

model_2 <- lm(mpg ~ wt * hp, data = mtcars)

summary(model_2)

Q3.5 Interpretation

The p value for the interaction is below 0.05, implying significance in the prediction of MPG. There was a change in R^2 that implied that the model fit improved as well. All to say that for cars with higher WT, the MPG is altered less by higher HP

Q3.6

boxplot(mtcars, main = ‘mtcars Boxplot’)

Q3.7

lower <- quantile(mtcars\(hp, 0.05) upper <- quantile(mtcars\)hp, 0.95) mtcars\(hp_wins <- pmin(pmax(mtcars\)hp, lower), upper)

summary(mtcars\(hp) summary(mtcars\)hp_wins)