Introduction

  • Simple Linear Regression (SLR) models the relationship between one predictor (x) and a response (y).
  • Equation:
    \[ y = \beta_0 + \beta_1 x + \epsilon \]

Example Dataset

We’ll use the mtcars dataset in R.
- Predictor: wt (car weight)
- Response: mpg (miles per gallon)

Scatterplot of Data

Fitting the Model

The fitted regression line is:
\[ \hat{y} = \hat{\beta}_0 + \hat{\beta}_1 x \]

## (Intercept)          wt 
##   37.285126   -5.344472

Scatterplot with Regression Line

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

R Code Example

# Fit linear regression
fit <- lm(mpg ~ wt, data=mtcars)

# Summary of results
summary(fit)

# Plot regression line
ggplot(mtcars, aes(x=wt, y=mpg)) +
  geom_point() +
  geom_smooth(method="lm")

Interactive 3D Plot (Plotly)

Statistical Inference

We test the null hypothesis:
\[ H_0 : \beta_1 = 0 \quad \text{vs} \quad H_a : \beta_1 \neq 0 \]
- If p-value < 0.05 → reject \(H_0\).
- Conclude there is a significant linear relationship.

Conclusion

  • SLR models the linear relationship between X and Y.
  • Example with mtcars shows weight strongly affects mpg.
  • Tools used: ggplot, plotly, R code, LaTeX math.