Simple Linear Regression
Understand linear regression through relatable examples, clear math, and a visual demo.
Why Regression? A Story of Fair Comparison
Imagine a 5-year-old child and a 20-year-old adult both score the same on a vocabulary test.
Would you say they have the same language ability?
Probably not. You naturally consider age. A 5-year-old scoring that high is impressive. A 20-year-old? Maybe just average.
What you did intuitively is control for a background factor. You “regressed” their scores to account for age.
Regression, in statistics, formalizes this intuition. It lets us adjust for background variables when making predictions or comparisons.
What Is Simple Linear Regression?
Simple Linear Regression is the most basic kind of regression. It models the relationship between two variables:
- One explanatory variable — something we know (like age)
- One response variable — something we want to predict (like vocabulary score)
The relationship is assumed to be a straight line.
The regression equation is:
Where:
- : the intercept — where the line crosses the y-axis
- : the slope — how much changes when increases by 1
- : the error term — the part of not explained by
Finding the Best Line
Given data points , we want to find the line that fits them best.
How? By minimizing the sum of squared errors between the observed and the predicted :
We choose and to minimize:
This method is called Ordinary Least Squares (OLS).
Step-by-Step: Calculating the Slope and Intercept
To find the best-fitting line, use these formulas:
1. Compute the slope :
2. Then the intercept :
Where and are the means of the and data.
Visual Intuition: Scatterplot + Regression Line
Picture a scatterplot of your data points.
Now imagine a straight line drawn through them — one that balances the points as evenly as possible.
That’s the regression line. It “predicts” from , minimizing the overall squared error.
Interactive Demo
Try adjusting data points and watch the regression line update live. Notice how a single point can tilt the line, especially if it’s far from the rest.
Simple Linear Regression Interactive Demo
y = β₀ + β₁x
0.000
Where the line crosses the y-axis
0.000
How much y changes when x increases by 1
Interactive Demo
Try adjusting data points and watch the regression line update live. Notice how the slope and intercept change!
Summary
Regression is about fair comparisons and informed predictions. Simple linear regression does this with:
- A clear mathematical formula
- A meaningful slope and intercept
- A visual way to model relationships
And it all starts with a very human idea: “Let’s account for the background before we compare.”