2024-03-20

Introduction to Simple Linear Regression

  • Simple Linear Regression is a statistical method that allows us to study the relationship between two continuous variables.

  • It seeks to model how changes in one variable (independent variable) affect another variable (dependent variable) through a linear relationship.

  • SLR is widely used in various fields such as economics, social sciences, engineering, and healthcare to analyze data and make predictions based on observed patterns.

The Linear Model

The model is given by:

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

Where: \(Y\) is the dependent variable. \(X\) is the independent variable. \(\beta_0\) and \(\beta_1\) are parameters. \(\epsilon\) is the error term.

Estimating the Coefficients

The coefficients \(\beta_0\) (intercept) and \(\beta_1\) (slope) in the equation \(Y = \beta_0 + \beta_1 X + \epsilon\) are estimated using the least squares criterion.

\[ \hat{\beta}_1 = \frac{\sum_{i=1}^{n} (X_i - \bar{X})(Y_i - \bar{Y})}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \] \[ \hat{\beta}_0 = \bar{Y} - \hat{\beta}_1 \bar{X} \]

Example of Linear Regression

Consider a dataset where Y represents a person’s weight and X represents their height.

Assumptions of Linear Regression

  1. Linear Relationship
  2. Independence
  3. Homoscedasticity
  4. Normality of Residuals

GG Plot 1

GG Plot 2

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

Plotly Plot R Code

# Generate sample data for 3D plot
set.seed(123)
x <- rnorm(100)
y <- rnorm(100)
z <- x + y + rnorm(100)

Plotly Plot