2026-03-08

Introduction

Simple linear regression is a way to study how two things are related. It looks at how one thing changes when something else changes. We use it to see if one variable goes up or down when another variable changes. Simple linear regression helps us understand the relationship, between two variables.

In this presentation, we look at how car weight affects fuel efficiency.

What is Linear Regression?

Linear regression is a way to find the straight line that shows how two variables are connected.

The line is really helpful because it shows how the dependent variable is affected when the linear regression variable changes. Linear regression is often used to find trends and make predictions, about what might happen with the linear regression dependent variable and linear regression independent variable.

Regression Equation

The formula for simple linear regression is:

\[ y = \beta_0 + \beta_1 x + \epsilon \]

Where:

  • \(y\) = dependent variable
  • \(x\) = independent variable
  • \(\beta_0\) = intercept
  • \(\beta_1\) = slope
  • \(\epsilon\) = error term

Example Explanation

In this example we examine the relationship between:

  • wt (car weight)
  • mpg (miles per gallon)

Heavier cars usually consume more fuel, so fuel efficiency may decrease as weight increases.

ggplot Scatter Plot

ggplot Regression Line

Interactive Plot (Plotly)

R Code Example

## 
## Call:
## lm(formula = mpg ~ wt, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.5432 -2.3647 -0.1252  1.4096  6.8727 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  37.2851     1.8776  19.858  < 2e-16 ***
## wt           -5.3445     0.5591  -9.559 1.29e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.046 on 30 degrees of freedom
## Multiple R-squared:  0.7528, Adjusted R-squared:  0.7446 
## F-statistic: 91.38 on 1 and 30 DF,  p-value: 1.294e-10

This code fits a regression model to see how car weight affects fuel efficiency.

Interpretation

The regression line shows that weight and fuel efficiency are related in a way. This means that when the weight of a car gets bigger the fuel efficiency usually gets worse.

For example a car that weighs more will probably get miles per gallon. Linear regression is a tool that helps us see this pattern in the data, about cars and their fuel efficiency. We can use regression to understand how the weight of a car affects its fuel efficiency.

Conclusion

Simple linear regression is a way to understand how things relate to each other. It shows us trends explains why things happen and helps us guess what might happen next.

  • I looked at an example. Found out that cars that are heavier usually do not go as far on a gallon of gas.

  • This tells us that the heavier a car is, the miles it can go on a gallon of gas.

  • This is an example of a negative relationship, between how heavy a car is and how many miles it can go on a gallon of gas.