Introduction

In this presentation, we explore Simple Linear Regression, a statistical method used to model the relationship between a dependent variable and a single independent variable.

What is Linear Regression?

Linear regression fits a straight line through a set of data points to describe the relationship between two variables.

\[ Y = \beta_0 + \beta_1 X + \varepsilon \]

Where: - \(Y\) is the response variable - \(X\) is the explanatory variable - \(\beta_0\) is the intercept - \(\beta_1\) is the slope - \(\varepsilon\) is the error term

Dataset: mtcars

We’ll use the built-in mtcars dataset in R. We will model Miles per Gallon (mpg) as a function of Horsepower (hp).

ggplot: Scatter Plot

R Code Example

model <- lm(mpg ~ hp, data = mtcars)
summary(model)
## 
## Call:
## lm(formula = mpg ~ hp, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.7121 -2.1122 -0.8854  1.5819  8.2360 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 30.09886    1.63392  18.421  < 2e-16 ***
## hp          -0.06823    0.01012  -6.742 1.79e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.863 on 30 degrees of freedom
## Multiple R-squared:  0.6024, Adjusted R-squared:  0.5892 
## F-statistic: 45.46 on 1 and 30 DF,  p-value: 1.788e-07

This code fits a simple linear regression model predicting mpg using hp.

ggplot: Residual Plot

Plotly: 3D Scatter with Regression Plane

Interpreting the Model

\[ \hat{Y} = \hat{\beta}_0 + \hat{\beta}_1 X \]

From the output: - \(\hat{\beta}_0 =\) (intercept from summary) - \(\hat{\beta}_1 =\) (slope from summary)

This equation gives the estimated MPG for a given horsepower.

Conclusion

Simple Linear Regression provides an easy-to-use method for analyzing relationships between variables. It’s widely used across industries from economics to engineering and forms the foundation for many advanced statistical methods.