In [ ]:
library(ISLR)

In [ ]:
# (a)

In [ ]:
pairs(Auto)

In [ ]:
summary(Auto)

In [ ]:
names(Auto)

In [ ]:
cor(subset(Auto, select = -name))

In [ ]:
# (c)
# i. From the following, there is a relation
# ii. It's suprising cylinders have no significant relation, but this is because
#     weight presents
# iii. newer cars have better efficiency
fit <- lm(mpg ~ .-name, data = Auto)
summary(fit)

In [ ]:
fit2 <- lm(mpg ~ cylinders, data = Auto)
summary(fit2)

In [ ]:
# (d)
par(mfrow = c(2,2))
plot(fit)

In [ ]:
# (e)
fit <- lm(mpg ~ cylinders*displacement+displacement*weight, data = Auto)
summary(fit)

In [ ]:
# lm.fit3 <- lm(mpg~log(weight)+sqrt(horsepower)+poly(acceleration, 2), data = Auto)
lm.fit3 = lm(mpg~log(weight)+sqrt(horsepower)+acceleration+I(acceleration^2), data = Auto)
summary(lm.fit3)

In [ ]:
lm.fit3 = lm(mpg~acceleration+I(acceleration^2), data = Auto)
#lm.fit3 = lm(mpg~poly(acceleration, 3), data = Auto)
summary(lm.fit3)