What is Simple Linear Regression?

Simple Linear Regression (SLR) is a statistical method used to describe the relationship between two numerical variables.

  • Predictor Variable (X)
  • Response Variable (Y)

Predict the value of Y using X.

Example: Can we predict a car’s fuel efficiency using its weight?

Why Is SLR Important?

Industries that use SLR:

  • Statistics
  • Data Science
  • Machine Learning
  • Economics
  • Engineering

Applications include:

  • Predicting sales
  • Forecasting prices
  • Understanding trends
  • Risk analysis

The Regression Equation

The mathematical model is:

\[ Y = \beta_0 + \beta_1X + \epsilon \]

Where:

  • \(Y\) = response variable
  • \(X\) = predictor variable
  • \(\beta_0\) = intercept
  • \(\beta_1\) = slope
  • \(\epsilon\) = random error

Least Squares Method

Regression chooses the line that minimizes: \[ \sum_{i=1}^{n}(y_i-\hat y_i)^2 \]

Residual: \[ e_i = y_i - \hat y_i \]

This method produces the “best fitting” line. The smaller the residuals, the better the line fits the data.

Example Dataset: mtcars

For this presentation we use the built-in dataset:

##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1

Variables:

  • mpg = miles per gallon
  • wt = vehicle weight

Does vehicle weight influence fuel efficiency?

Relationship Between Weight and MPG

Observation: As vehicle weight increases, fuel efficiency tends to decrease.

Regression Line

Observation: The downward slope of the Regression Line shows more clearly a negative relationship between weight and miles per gallon.

R Code Example

model <- lm(mpg ~ wt,
            data = mtcars)

summary(model)

This is the code that fits a simple linear regression model.

Interactive Plotly Visualization

Users can hover over points to view exact values.

Key Takeaways

  • Simple Linear Regression models relationships between variables.
    • It predicts a response variable using a predictor variable.
    • The least squares method finds the best-fitting line.
  • Linear regression serves as a foundation for more advanced machine learning models.