Install and load necessary packages

install.packages(“ISLR”) library(ISLR) # Load ISLR package

Load the Auto dataset

data(Auto)

Check structure of the dataset

str(Auto)

Check variable types

sapply(Auto, class)

Qualitative predictors (categorical)

qualitative_vars <- c(“name”) # Only ‘name’ is qualitative

Quantitative predictors (numerical)

quantitative_vars <- setdiff(names(Auto), qualitative_vars)

cat(“Quantitative Variables:”, quantitative_vars, “”) cat(“Qualitative Variables:”, qualitative_vars, “”)

Compute range for each quantitative variable

sapply(Auto[, quantitative_vars, drop=FALSE], range)

Compute mean

means <- sapply(Auto[, quantitative_vars, drop=FALSE], mean) print(“Means of Quantitative Variables:”) print(means)

Compute standard deviation

std_devs <- sapply(Auto[, quantitative_vars, drop=FALSE], sd) print(“Standard Deviations of Quantitative Variables:”) print(std_devs)

Remove observations from 10 to 85

Auto_subset <- Auto[-(10:85), ]

Compute new range, mean, and standard deviation

new_range <- sapply(Auto_subset[, quantitative_vars, drop=FALSE], range) new_means <- sapply(Auto_subset[, quantitative_vars, drop=FALSE], mean) new_std_devs <- sapply(Auto_subset[, quantitative_vars, drop=FALSE], sd)

print(“Range after removing observations 10-85:”) print(new_range)

print(“Means after removing observations 10-85:”) print(new_means)

print(“Standard Deviations after removing observations 10-85:”) print(new_std_devs)

Load ggplot2 for visualization

install.packages(“ggplot2”) # Install if needed library(ggplot2)

Scatterplots for relationships between quantitative variables

pairs(Auto[, quantitative_vars], main=“Scatterplot Matrix of Quantitative Variables”)

Alternative: Use ggplot to plot individual relationships

ggplot(Auto, aes(x=horsepower, y=mpg)) + geom_point() + ggtitle(“Horsepower vs MPG”) + theme_minimal()

Compute correlation of mpg with other numerical variables

correlation_matrix <- cor(Auto[, quantitative_vars]) print(“Correlation of mpg with other variables:”) print(correlation_matrix[“mpg”, ])

Fit a linear model predicting mpg

model <- lm(mpg ~ . -name, data=Auto) # Excluding ‘name’ as it’s qualitative summary(model) # Show regression results

Visualizing the relationship of mpg with horsepower

ggplot(Auto, aes(x=horsepower, y=mpg)) + geom_point() + geom_smooth(method=“lm”, col=“red”) + ggtitle(“Linear Relationship Between Horsepower and MPG”) + theme_minimal()