Example variables

We will use the built-in mtcars dataset.

  • wt: car weight (in 1000 lbs)
  • mpg: miles per gallon

Goal: understand how weight affects fuel efficiency.

What is simple linear regression?

Simple linear regression describes the relationship between one predictor variable and one response variable.

  • Predictor: car weight
  • Response: miles per gallon

The model

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

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

Scatter plot with regression line

Fitting the regression line

Estimated coefficients:

  • Intercept: 37.29
  • Slope: -5.34

Estimated model:

\[ \hat{y} = b_0 + b_1 x \]

  • Intercept: baseline mpg
  • Slope: change in mpg per unit increase in weight

Interpretation:

For every increase of 1 (1000 lbs) in weight, mpg decreases by about 5.34.

Hypothesis test for the slope

\[ H_0 : \beta_1 = 0 \]

\[ H_a : \beta_1 \ne 0 \]

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

Why regression matters

  • Understand relationships
  • Make predictions
  • Widely used in many fields

Residual plot

Interactive plotly plot

Explore how weight, mpg, and horsepower relate in 3D.

R code used for the main plot

ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point(size = 3, color = "#8C1D40") +
  geom_smooth(method = "lm", se = TRUE, color = "black") +
  labs(
    title = "MPG vs Weight",
    x = "Weight (1000 lbs)",
    y = "Miles per Gallon"
  ) +
  theme_minimal(base_size = 18)

Key takeaways

  • Regression models relationships
  • The slope shows direction and strength
  • Residuals check model quality
  • Statistical tests confirm significance

Regression is a powerful tool.