t value Pr(>|t|)(Intercept) -2.601
speed 9.464 \(1.49e^{-12}\)
Residual standard error: 15.38 on 48 degrees of freedom
Multiple R-squared: 0.6511
F-statistic: 89.57 on 1 and 49 DF, p-value: \(1.49e^{-12}\)
anova(mod)
Mean Sq F value Pr(>F)
speed 21186 89.5656 \(1.49e^{-12}\)
Residuals 236.54
Auto <- read.table("http://faculty.marshall.usc.edu/gareth-james/ISL/Auto.data",
header=TRUE,
na.strings = c("?","NA"))
model <- lm(mpg ~ horsepower, data = Auto)
summary(model)
##
## Call:
## lm(formula = mpg ~ horsepower, data = Auto)
##
## Residuals:
## Min 1Q Median 3Q Max
## -13.5710 -3.2592 -0.3435 2.7630 16.9240
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 39.935861 0.717499 55.66 <2e-16 ***
## horsepower -0.157845 0.006446 -24.49 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.906 on 390 degrees of freedom
## (5 observations deleted due to missingness)
## Multiple R-squared: 0.6059, Adjusted R-squared: 0.6049
## F-statistic: 599.7 on 1 and 390 DF, p-value: < 2.2e-16
ai. There is a strong relationship between the predictor and the response, as evident by the p value being almost 0.
aii. Since the p value is <2e-16, we can say the relationsip between the predictor and the response is very strong.
aiii. The relationship between the two is negative, as evident by the estimate for the slope being about -0.15.
aiv.
newdata = data.frame(horsepower = 98)
predict(model, newdata, interval = "confidence")
## fit lwr upr
## 1 24.46708 23.97308 24.96108
predict(model, newdata, interval = "prediction")
## fit lwr upr
## 1 24.46708 14.8094 34.12476
Therefore the predicted mpg is 24.46, and the associated confidence and prediction intervals are listed above.
plot(Auto$horsepower, Auto$mpg)
abline(model)
plot(model)
The linear fit does not seem like a good fit for the data. As we can see from the residuals plot, there is a clear pattern that indicates non-linearity, and the mean appears to be above 0. Additionally, the qqplot has many values that do not fall on the line, indicating non-linearity.