2024-10-20

Slide 1: Title Slide

Simple Linear Regression Using mtcars Data
Exploring Relationships Between Variables. I found a negative relationship between mpg and wt. As the weight of the car increases, fuel efficiency decreases. Linear regression models can help predict fuel consumption based on car characteristics.

## Slide 2: Introduction to Simple Linear Regression

Simple Linear Regression is a method used to model the relationship between a dependent variable \(Y\) and an independent variable \(X\).

\[ Y = \beta_0 + \beta_1 X + \epsilon \]

  • \(Y\): Dependent variable (response)
  • \(X\): Independent variable (predictor)
  • \(\beta_0\): Intercept
  • \(\beta_1\): Slope
  • \(\epsilon\): Error term

Slide 3:2D Scatter Plot with ggplot (mpg vs wt)

ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "blue") +
  labs(title = "Relationship between MPG and Weight", 
       x = "Weight (1000 lbs)", y = "Miles per Gallon")

Slide 3(2):2D Scatter Plot with ggplot (mpg vs wt)

## `geom_smooth()` using formula = 'y ~ x'

##Slide 4: 3D Scatter Plot with Plotly (mpg, wt, hp)

##Slide 5: Visualization of the Regression Line

## `geom_smooth()` using formula = 'y ~ x'

##slide 7

Linear regression can also be written in matrix form:

\[ \mathbf{Y} = \mathbf{X} \boldsymbol{\beta} + \boldsymbol{\epsilon} \]

Where: - \(\mathbf{Y}\) is the vector of observed values. - \(\mathbf{X}\) is the matrix of predictor variables. - \(\boldsymbol{\beta}\) is the vector of coefficients. - \(\boldsymbol{\epsilon}\) is the vector of errors.

This matrix form is often used for multiple linear regression where there are multiple predictors.