2024-01-29

Introduction to Simple Linear Regression

In this presentation, we will delve into the basics of Simple Linear Regression and apply it to the mtcars dataset, which features information about different car models. Through this analysis, we aim to understand the relationship between horsepower and miles per gallon (mpg).

Definition

Simple linear regression aims to find a linear relationship to describe the correlation between an independent and possibly dependent variable. The regression line can be used to predict or estimate missing values which is known as interpolation.

Formula: \(Y = \beta_0 + \beta_1X + \varepsilon\)

In context of our mtcars dataset,

  • Y: Dependent variable (e.g., milers per gallon)
  • \(\beta_0\): Intercept form
  • \(\beta_1\): Slope coefficient, indicating a change in Y for a unit-change in X
  • X: Independent Variable(e.g., horsepower)
  • \(\varepsilon\): Error term, representing unobserved factors affecting

Applications of Simple Linear Regression

  • In business and finance, Simple Linear Regression holds a pivotal role. Analysts frequently employ it to model and predict diverse scenarios, such as estimating how alterations in marketing expenses impact product sales or unraveling the relationship between interest rates and investment returns.

  • In health sciences, Simple Linear Regression aids researchers in making predictions about patient outcomes. For instance, it can be utilized to comprehend how changes in specific health indicators correlate with overall well-being or to assess the impact of age on blood pressure levels.

Regression Line

  • The regression line is a fundamental element of Simple Linear Regression, representing the best-fit line through the scatter plot. It encapsulates the overall trend in the relationship between the independent variable (horsepower) and the dependent variable (miles per gallon). It provides a clear visual and mathematical representation of the underlying patterns in the data.

  • Despite its value, it’s crucial to acknowledge the limitations of the regression line. The model assumes a linear relationship between variables, and deviations from linearity or violations of other assumptions can impact the accuracy of predictions

  • Visualization using ggplot with the regression line (next slide)

R Code

# R code to generate the scatter plot
library(ggplot2)

# Load the mtcars dataset
data(mtcars)

# Create a scatter plot
ggplot(mtcars, aes(x = hp, y = mpg)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "blue") +
  labs(title = "Scatter Plot of Horsepower and MPG",
       x = "Horsepower",
       y = "MPG")
## `geom_smooth()` using formula = 'y ~ x'

Scatter Plot

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

Residuals

  • Residuals, in the context of Simple Linear Regression, are the differences between the observed values of the dependent variable (miles per gallon) and the values predicted by the regression line.

  • The formula for the residuals is given by \(e_i = Y_i - \hat{Y_i}\) where \(Y_i\) is the observed value of the dependent variable, and \(\hat{Y_i}\) is the predicted value based on the regression line. The residuals represent the unexplained variation in the data.

  • Visual representation of residuals using ggplot (next slide)

Residual Plot

Plotly 3D Plot

  • A 3D Plotly plot illustrating the relationship between Horsepower, MPG, and residuals

Hypothesis Testing

  • Hypothesis testing is a statistical method that enables us to evaluate the significance of our Simple Linear Regression model and draw informed conclusions about the relationship between variables.

  • To assess these hypotheses, we frequently employ a t-test for the slope coefficient. This test assists in determining whether the observed relationship between horsepower and miles per gallon is statistically significant or could have occurred by random chance.

  • The outcomes of the hypothesis test are usually conveyed through a p-value. A small p-value, often below a selected significance level (e.g., 0.05), indicates that we can reject the null hypothesis, offering evidence in support of a significant linear relationship. Conversely, a large p-value suggests insufficient evidence to reject the null hypothesis.