What is Simple Linear Regression?

Simple linear regression studies the relationship between:

  • one explanatory variable \(x\)
  • one response variable \(y\)

In this example:

  • \(x\) = car weight (wt)
  • \(y\) = miles per gallon (mpg)

The Model

\[ Y = \beta_0 + \beta_1 x + \varepsilon \]

  • \(\beta_0\): intercept
  • \(\beta_1\): slope

Hypothesis Test

\[ H_0: \beta_1 = 0 \]

\[ H_a: \beta_1 \neq 0 \]

If the p-value is small, we reject \(H_0\).

Example Data

##                    mpg    wt
## Mazda RX4         21.0 2.620
## Mazda RX4 Wag     21.0 2.875
## Datsun 710        22.8 2.320
## Hornet 4 Drive    21.4 3.215
## Hornet Sportabout 18.7 3.440
## Valiant           18.1 3.460

This dataset includes:

  • miles per gallon
  • weight of cars

GGPlot Scatterplot

GGPlot Distribution of MPG

Plotly Interactive Plot

R Code Example

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  geom_smooth(method = "lm") +
  labs(
    title = "MPG vs Weight",
    x = "Weight (1000 lbs)",
    y = "Miles per Gallon"
  )

Conclusion

  • Linear regression shows relationship between two variables
  • Heavier cars tend to have lower MPG
  • The p-value is very small, so weight is a significant predictor of MPG
  • ggplot and plotly were used to visualize the data