# Load necessary package if (!require("MASS")) install.packages("MASS", dependencies = TRUE) library(MASS) # Load the mtcars dataset data(mtcars) # Automated stepwise model selection based on AIC full_model <- lm(mpg ~ ., data = mtcars) # Full model with all predictors null_model <- lm(mpg ~ 1, data = mtcars) # Null model with intercept only selected_model <- step(null_model, scope = list(lower = null_model, upper = full_model), direction = "both") # Default uses AIC for selection # Summary of the selected model print("Summary of the Selected Model:") summary(selected_model)