In the lab, a classification tree was applied to the Carseats data set after converting Sales into a qualitative response variable. Now we will seek to predict Sales using regression trees and related approaches, treating the response as a quantitative variable. We first split the data in test and training set. We already provide you with this code in order to align our starting data set.

library(ISLR2)
set.seed(1)
train <- sample(1:nrow(Carseats), nrow(Carseats) / 2)
Carseats.train <- Carseats[train, ]
Carseats.test <- Carseats[-train, ]

Questions

  1. Fit a regression tree to the training set. Use a seed value of 2. Plot the tree, and interpret the results. Store the test error in mse.regrtree.

  2. Use the bagging approach in order to analyze this data. Use 500 trees and a seed value of 3. Store the test error in mse.bag. Use the importance() function to determine which variables are most important.

  3. Use random forests to analyze the data. Use a seed value of 4. Use 500 trees and use the typical \(m = \sqrt{p}\) (rounded to the nearest integer). Store the test error rate in mse.rf. Use the importance() function to determine which variables are most important.




Assume that: