install.packages("ISLR")Exercise 1
Exercise 1: Login to RStudio Pro
- Go to course website → Computing → Using the RStudio Server
- Follow login instructions
- Log in with your credentials
Check: You should see the RStudio interface with 4 panes.
Exercise 2: Create RStudio Project
- File → New Project → New Directory → New Project
- Name:
ex-1 - Click Create Project
Check: Project name appears in top-right corner.
Exercise 3: Create Quarto Document
- File → New File → Quarto Document
- Title: “My First Analysis”
- Save as
analysis.qmd
Check: New .qmd file is open and saved.
Exercise 4: Install ISLR Package and Load Data
Run this code in the console ONCE:
Then run this:
library(ISLR)
library(ggplot2)
# Test it works
data(Auto)
head(Auto) mpg cylinders displacement horsepower weight acceleration year origin
1 18 8 307 130 3504 12.0 70 1
2 15 8 350 165 3693 11.5 70 1
3 18 8 318 150 3436 11.0 70 1
4 16 8 304 150 3433 12.0 70 1
5 17 8 302 140 3449 10.5 70 1
6 15 8 429 198 4341 10.0 70 1
name
1 chevrolet chevelle malibu
2 buick skylark 320
3 plymouth satellite
4 amc rebel sst
5 ford torino
6 ford galaxie 500
Check: You see the Auto dataset.
Now run this in the console:
?AutoQuestion: What is in this dataset?
Action: Add the code below to your .qmd file along with a short description of the data.
library(ISLR)
library(ggplot2)
data(Auto)Exercise 5: Linear Model and Plot
Add the following code to your .qmd file. Try running it.
# Fit linear model
model1 <- lm(mpg ~ horsepower, data = Auto)
summary(model1)
Call:
lm(formula = mpg ~ horsepower, data = Auto)
Residuals:
Min 1Q Median 3Q Max
-13.5710 -3.2592 -0.3435 2.7630 16.9240
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 39.935861 0.717499 55.66 <2e-16 ***
horsepower -0.157845 0.006446 -24.49 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.906 on 390 degrees of freedom
Multiple R-squared: 0.6059, Adjusted R-squared: 0.6049
F-statistic: 599.7 on 1 and 390 DF, p-value: < 2.2e-16
# Create plot
ggplot(Auto, aes(x = horsepower, y = mpg)) +
geom_point() +
geom_smooth(method = "lm", formula = "y ~ x") +
labs(title = "Horsepower vs MPG",
x = "Horsepower",
y = "Miles per Gallon")
Check: You have model output and a scatter plot with trend line.
Finish
Click “Render” to create your HTML report. Upload your .html file in Canvas under Exercise 1