2026-02-07

Simple Linear Regression

Simple linear regression is a statistical method that models the linear relationship between a single, continuous, independent predictor variable \(X\) and a dependent, numerical outcome variable \(Y\)

It is widely used for prediction, understanding relationships, quantifying effects.

The Linear Regression Model

The simple linear regression model is defined as:

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

where: - \(\beta_0\) is the intercept
- \(\beta_1\) is the slope
- \(\varepsilon \sim N(0, \sigma^2\)

Dataset

For explaining linear Regression models I used the built in ‘mtcars’ dataset.

The dataset contains information on 32 cars and 11 variables

##                    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

Scatter Plot of MPG VS Weight

Linear Regression Fit

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

Least Squares Estimation

The regression coefficients are estimated by minimizing the sum of squared errors:

\[ \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 \]

where the fitted values are given by:

\[ \hat{y}_i = \hat{\beta}_0 + \hat{\beta}_1 x_i \]

Code for Plotly

plot_ly(
  mtcars,
  x = ~wt,
  y = ~hp,
  z = ~mpg,
  type = "scatter3d",
  mode = "markers"
)

3D Visualization with Plotly