Introduction

  • We will be going over Simple Linear Regression
  • It is a technique used to model between two variables
  • We will use mtcars dataset and visualizations to understand how it works

What is Simple Linear Regression?

  • A method to model the relationship between a dependent variable \(y\) and one independent variable \(x\)

\[ y = \beta_0 + \beta_1x + \epsilon \]

Where:

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

Properties of Least Squares Estimators

\[ \hat{\beta}_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}, \quad \hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x} \]

  • These formulas give us the slope and intercept of the best fitting line using the least squares method
  • Least squares estimators minimize the total squared vertical distance between the observed points and the regression line
  • They are the basis for drawing the regression line shown in the next slide and interpreting the model

Scatter Plot with Regression Line

  • This scatter plot shows the relationship between car weight and miles per gallon (MPG)
  • The downward-sloping regression line indicates that as car weight increases, MPG tends to decrease

Residual Plot

  • Residuals are the differences between observed and predicted values
  • This plot helps check if the residuals are randomly scattered, indicating a good linear fit

Setting up our 3D Plot

  • This code will set up the 3D Plot to showcase Simple Linear Regression.
fig = plot_ly(data = mtcars, x =~ wt, y =~ mpg, z =~ hp,
               type = 'scatter3d', mode = 'markers',
               marker = list(size = 5, color =~ hp, 
                             colorscale = 'Viridis'))
fig
  • This 3D plot visualizes the relationship between weight, MPG, and horsepower
  • It helps us see how a third variable like horsepower may influence the relationship between weight and MPG

Relationship Between Weight, MPG, and Horsepower

Conclusion

  • Simple linear regression is a powerful tool in statistics
  • It helps us understand and predict relationships between two variables
  • Make sure to always check assumptions and use diagnostic plots to validate your model