2026-10-17

What is Simple Linear Regression?

Simple linear regression studies the relationship between two variables using a straight line.

  • The predictor variable (x) is used to predict another variable.
  • The response variable (y) is what we want to predict.

Regression Equation

The fitted regression line has the equation:

\[ \hat{y} = a + bx \]

  • \(\hat{y}\) is the predicted response.
  • \(a\) is the y-intercept.
  • \(b\) is the slope.
  • \(x\) is the predictor.

Example: Iris Flowers

We will use the built in ‘iris’ dataset.

We want to see whether petal length can help predict petal width.

  • Predictor (x): ‘Petal.Length’
  • Response (y): ‘Petal.Width’

Scatterplot of Petal Length and Width

The colors represent the three iris species.

Finding the Regression Line

We use ‘lm()’ to predict petal width from petal length.

mod = lm(Petal.Width ~ Petal.Length, data = iris)
mod
## 
## Call:
## lm(formula = Petal.Width ~ Petal.Length, data = iris)
## 
## Coefficients:
##  (Intercept)  Petal.Length  
##      -0.3631        0.4158

Interpreting the Regression Equation

The fitted regression equation is:

\[ \hat{y} = -0.3631 + 0.4158x \]

Here, \(x\) is petal length and \(\hat{y}\) is predicted petal width.

For each 1 cm increase in petal length, predicted petal width increases by approximately 0.4158 cm.

The positive slope indicates a positive relationship between petal length and petal width.

Scatterplot with Regression Line

Petal width generally increases as petal length increases.

Interactive Plot

Conclusion

  • Petal length and petal width have a positive relationship.
  • Simple linear regression can help predict petal width from petal length.