library(ISLR2) data(“Carseats”)
model_full <- lm(Sales ~ Price + Urban + US, data = Carseats)
summary(model_full)
Coefficients: (Intercept) 13.043 Price -0.054 UrbanYes -0.021 USYes 1.200
coef(model_full)
Intercept Price UrbanYes USYes 13.043 -0.054 -0.021 1.200
Sales= 13.043 − 0.054 ⋅ Price − 0.02 2 ⋅UrbanYe s + 1 .20 1 ⋅USYes
model_reduced <- lm(Sales ~ Price + US, data = Carseats) summary(model_reduced)
summary(model_full)\(adj.r.squared summary(model_reduced)\)adj.r.squared
anova(model_reduced, model_full)
confint(model_reduced) 2.5 % 97.5 % (Intercept) 11.763698 14.323239 Price -0.064617 -0.044300 USYes 0.688997 1.712149
par(mfrow = c(2, 2)) plot(model_reduced)
influence.measures(model_reduced)
hatvalues <- hatvalues(model_reduced) plot(hatvalues, main=“Leverage Values”) abline(h = 2 * mean(hatvalues), col = “red”)