What is Simple Linear Regression?

Simple Linear Regression is a statistical method used to study the relationship between two numerical variables.

  • One variable is the predictor, or explanatory variable
  • The other variable is the response, or outcome variable
  • The goal is to find a straight line that best describes their relationship

Why Use Linear Regression?

Linear regression can help us:

  • Understand whether two variables are related
  • Measure the direction and strength of a relationship
  • Summarize a relationship with a simple mathematical model

The Regression Equation

The equation for a simple linear regression model is:

\[ \hat{y} = b_0 + b_1x \]

Where:

  • \(\hat{y}\) = predicted value of the response variable
  • \(b_0\) = y-intercept
  • \(b_1\) = slope of the regression line
  • \(x\) = value of the predictor variable

Example: Car Weight and Fuel Efficiency

To demonstrate simple linear regression, we will use the mtcars dataset in R.

We will investigate the relationship between:

  • Weight (wt) - the predictor variable
  • Miles per gallon (mpg) - the response variable

Our question is:

Can a car’s weight help predict its fuel efficiency?

Visualizing the Relationship

A scatterplot allows us to see the relationship between car weight and fuel efficiency

Fitting the Regression Model

We can fit a simple linear regression model in R using the lm() function.

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

model
## 
## Call:
## lm(formula = mpg ~ wt, data = mtcars)
## 
## Coefficients:
## (Intercept)           wt  
##      37.285       -5.344

The fitted regression equation is:

\[ \widehat{MPG} = 37.285 - 5.344(Weight) \]

Interactive Plotly Visualization

Plotly allows us to explore the relationship between car weight and fuel efficiency interactively.

Evaluating the Model

Residuals are the differences between the actual MPG values and the values predicted by the regression model.

A residual plot can help us evaluate how well the linear model fits the data.

Interpreting the Results

Our fitted regression equation is:

\[ \widehat{MPG} = 37.285 - 5.344(Weight) \]

  • The slope is -5.344
  • For every additional 1,000 pounds of car weight, predicted fuel efficiency decreases by about 5.34 MPG
  • The negative slope shows that heavier cars tend to have lower fuel efficiency
  • This relationship shows an association, but does not prove that weight alone causes changes in MPG

Key Takeaways

  • Simple linear regression models the relationship between one predictor and one response variable
  • In the mtcars dataset, car weight and fuel efficiency have a negative relationship
  • As car weight increases, predicted MPG tends to decrease
  • R can fit a regression model using lm() function
  • Scatterplots, regression lines, and residual plots help us understand and evaluate the model