2024-02-01

Introduction to Simple Linear Regression

Simple Linear Regression is a foundational statistical method for understanding the relationship between two continuous variables.

  • The goal is to model the relationship by fitting a linear equation to observed data.
  • Simple linear regression has wide applications in various scientific and business fields.

The Regression Equation

Simple linear regression models the relationship between two variables by fitting a linear equation to observed data. The equation is given by:

\[ 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 of the line. - \(\epsilon\) is the error term.

Interpreting the Coefficients

In the regression equation \(y = \beta_0 + \beta_1x + \epsilon\), the coefficients have specific interpretations:

  • \(\beta_0\) (Intercept): The expected value of \(y\) when \(x\) is 0.
  • \(\beta_1\) (Slope): The expected change in \(y\) for a one-unit change in \(x\).

For instance, if \(\beta_1 = 3\), it means that for every one unit increase in \(x\), \(y\) increases by 3 units.

Assumptions of Linear Regression

Simple Linear Regression relies on several key assumptions:

  1. Linearity: The relationship between the predictor and the response is linear.
  2. Independence: Observations are independent of each other.
  3. Homoscedasticity: Constant variance of errors.
  4. Normality: The errors are normally distributed.

Sample Data Used in the Plots

##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1

ggplot2 Plot: Scatterplot

ggplot2 Plot: Regression Line

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

Plotly Plot: 3D Scatter Plot

R Code used for the above plots

ggplot2 Plot: Regression Line

ggplot(mtcars, aes(x=wt, y=mpg)) +
  geom_point() +
  geom_smooth(method="lm", color="blue", se=FALSE) +
  ggtitle("Linear Regression Line: MPG vs. Car Weight") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

Plotly Plot: 3D Scatter Plot

library(plotly)
plot_ly(data=mtcars,x=~mpg,y=~wt,z=~qsec,type='scatter3d',mode='markers')

Summary

  • Simple Linear Regression is a statistical technique used to model the relationship between a dependent variable and one independent variable.
  • The regression line is represented by the equation \(y = \beta_0 + \beta_1x\), where \(y\) is the predicted score, \(\beta_0\) is the intercept, \(\beta_1\) is the slope, and \(x\) is the score on the independent variable.
  • Key assumptions of the model include linearity, independence, homoscedasticity, and normality of residuals.
  • Interpretation of the regression coefficients involves understanding the slope (\(\beta_1\)) as the average change in the dependent variable for each one unit change in the independent variable.
  • Regression analysis is crucial in many fields for prediction and understanding the strength of relationships between variables.