2026-09-13

Introduction to Simple Linear Regression

  • Objective: Understanding the relationship between two variables.
  • Variables Defined:
    • X: Predictor Variable.
    • Y: Response Variable.
  • Core Concept: We use \(X\) to predict \(Y\) assuming that the relationship can be represented by a straight line.

Regression Equation (LaTeX)

The Simple Linear Regression model is:

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

  • \(Y\) = Response Variable
  • \(X\) = Predictor Variable
  • \(\beta_0\) = intercept
  • \(\beta_1\) = slope
  • \(\epsilon\) = random error

Data: Car Speed and Stopping Distance

  • X (Independent Variable): Speed of the car (mph)
  • Y (Dependent Variable): Stopping distance (ft)
  • Question: Does the stopping distance increase as the speed increases?
  • Goal: Use the speed to predict the stopping distance.

ggplot: Scatter plot

The scatterplot shows the relationship between:

X: speed(mph) Y: Stopping distance (ft)

Each point represents one observation.

The plot helps us to see whether there is a relationship between speed and stopping distance.

Plot Visualization:

ggplot: Scatter plot with Regression Line

The regression line shows the overall trend in the data:

  • The line represents the predicted stopping distance.
  • The line has an upward slope.
  • This suggests that the stopping distance tends to increase as speed increases.

Plot Visualization:

## `geom_smooth()` using formula = 'y ~ x'

Regression Equation + Results (LaTeX)

Final sample prediction line equation:

\[\hat{Y}_i = -17.579 + 3.932 X_i\] Where:

  • \(\hat{Y}_i\) is the estimated stopping distance (ft).
  • \(3.932\) is the calculated slope coefficient (\(\hat{\beta}_1\)).
  • \(-17.579\) is the intercept (\(\hat{\beta}_0\)).

Several Variables of Data

##   speed dist
## 1     4    2
## 2     4   10
## 3     7    4
## 4     7   22
## 5     8   16
## 6     9   10

Weight Vs Fuel Efficiency

p = plot_ly(mtcars, x=~wt, y=~mpg, type="scatter", mode="markers", 
        color = ~disp, width=600, height=350)
p

Conclusion

Takeaway:

  • Simple linear regression provides a very beneficial framework to model relationships.
  • Whether we are looking at the fuel efficiency or the car stopping distance, it is important in determining and understanding the relationship between two variables.
  • It is always important to check the trend lines and residuals using the graphic tools such as ggplot2.