Chapter 3- Linear Regression, Question 8
Auto= read.csv("../../datasets/Auto.csv",header=T,na.strings="?")
Auto=na.omit(Auto)
lm.model = lm(mpg~horsepower, data=Auto)
summary(lm.model)
The large F-statistic and its small p-value shows that there is a strong relationship between predictor and response. We can reject the null hypothesis that the predictor is equal to zero.
mean(Auto$mpg)
The residual standard error 4.906 and mean response is 23.446 which gives a percentage error of 20.9%. The R-squared value is 0.6059. This indicates that 60.59% of the variability in the response has been explained (removed) by the model.
The coefficient of horsepower is negative. The response "mpg" decreases with the increase in "horsepower." Therefore the relationship is negative.
predict(lm.model,data.frame(horsepower=98))
#95% confidence interval
predict(lm.model,data.frame(horsepower=98),interval="confidence")
#95% prediction interval
predict(lm.model,data.frame(horsepower=98),interval="prediction")
plot(Auto$horsepower, Auto$mpg)
abline(lm.model)
par(mfrow=c(2,2))
plot(lm.model)
Residuals vs Fitted values graph forms a pattern which indicates nonlinearity between the response and predictor.