2025-10-23

Introduction to Linear Regression

Linear regression is a statistical method for modeling the relationship between:

  • a dependent variable \(Y\)
  • one or more independent variables \(X\)

It can be applied to various fields across math, engineering, and computer science! For example, we can use it to predictive machine learning models to predict various values, like housing prices.

Linear Regression Model

Linear Regression models have a linear relationship where:

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

Each variable in the Y:

  • \(\beta_0\): intercept
  • \(\beta_1\): slope
  • \(\epsilon\): random error

Women dataset

The dataset that will be used is the “women” dataset to model our simple linear regression. We will look at the relationship between height and weight in this dataset.

summary(women)
     height         weight     
 Min.   :58.0   Min.   :115.0  
 1st Qu.:61.5   1st Qu.:124.5  
 Median :65.0   Median :135.0  
 Mean   :65.0   Mean   :136.7  
 3rd Qu.:68.5   3rd Qu.:148.0  
 Max.   :72.0   Max.   :164.0  
View(women)

Women dataset prediction

Using this dataset, the goal is to predict the weight of the women based on the height using a simple linear regression model defined earlier, where:

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

Each variable in the Y:

  • Y : weight
  • \(\beta_0\): intercept
  • \(\beta_1\): height
  • \(\epsilon\): random error

Women Dataset Line Plot

In this dataset, we can see that this is a linear relationship between weight and height, which could be used to fit a linear regression model!

Linear Regression Model

The linear regression is the line of best fit of the data.

Making Predictions Using Linear Regression Model

The predicted weight at a height of 64 inches is 132 pounds.

<ggplot2::labels> List of 3
 $ x    : chr "Height (inches)"
 $ y    : chr "Weight (pounds)"
 $ title: chr "Weight vs Height"

Fitting the linear model

We can also get a quick overview and summarization of the data outside of the plots as well, using the following R code below.

Call:
lm(formula = weight ~ height, data = women)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.7333 -1.1333 -0.3833  0.7417  3.1167 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) -87.51667    5.93694  -14.74 1.71e-09 ***
height        3.45000    0.09114   37.85 1.09e-14 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.525 on 13 degrees of freedom
Multiple R-squared:  0.991, Adjusted R-squared:  0.9903 
F-statistic:  1433 on 1 and 13 DF,  p-value: 1.091e-14