2026-06-06

2. Dataset

Dataset:

Built-in mtcars dataset.

Variables:

Dependent variable is Miles Per Gallon (mpg).

Independent variable is Car Weight (wt).

3. Model Equation(In Latex)

The model for simple linear regression:

\[y_i = \beta_0 + \beta_1 x_i + \epsilon_i\]

Where \(y_i\) is mpg and \(x_i\) is weight(‘wt’).

4. Residual Formula(In Latex)

Difference between the observed values and the predicted values:

\[e_i = y_i - \hat{y}_i\]

5. R Code Example

R code used to create the scatter plot shown on slide 6:

ggplot(mtcars, aes(x=wt, y=mpg)) +
  
  geom_point(color="blue", size=3) +
  
  geom_smooth(method="lm", formula=y~x, color="red") +
  
  theme_minimal()

6. Regression Plot (ggplot)

Shows the relationship between car weight and miles per gallon.

7. Residuals by Car (ggplot)

Displays the residual error values for each specific car model.

8. Weight/MPG Relationship (plotly)

Visualizes the relationship between weight and MPG.