What Is Simple Linear Regression?
The word "simple" distinguishes this from multiple linear regression, which uses two or more predictors. "Linear" means the relationship between x and y is modeled as a straight line — not curved, not stepped.
The equation ŷ = b₀ + b₁x has two parts. The slope b₁ tells you how much y changes, on average, for each one-unit increase in x. The intercept b₀ is the predicted value of y when x equals zero. Together they define the regression line — also called the line of best fit.
The method dates to Francis Galton, who coined the term "regression" in 1886 when studying the heights of parents and their children. Karl Pearson later formalized the mathematics. Today, simple linear regression is the entry point for predictive modeling in statistics, economics, machine learning, and data science. A full treatment of the underlying theory is available at Statistics Fundamentals.
- Equation: ŷ = b₀ + b₁x (b₀ = intercept, b₁ = slope)
- Slope (b₁): Change in ŷ for every 1-unit increase in x — the most important number in the output
- Intercept (b₀): Predicted ŷ when x = 0 (may not be meaningful if x = 0 is outside the data range)
- Residual (e): Actual y minus predicted ŷ — measures how far each point falls from the line
- R² (R-squared): Proportion of variance in y explained by x; ranges 0–1
- Pearson r: Strength and direction of the linear relationship; r² = R²
- OLS: Ordinary Least Squares — the method that computes b₁ and b₀ by minimizing Σ(y − ŷ)²
The Regression Formula and How to Calculate It
The slope and intercept are calculated from your data using ordinary least squares (OLS). These two formulas are all you need when working by hand:
n = number of data points
Σxy = sum of each x times y
Σx = sum of all x values
Σy = sum of all y values
Σx² = sum of each x squared
ȳ = mean of y values
x̄ = mean of x values
b₁ = slope (calculated first)
Once you have b₀ and b₁, write the equation, then use it to predict y for any x value. The coefficient of determination R² is calculated as:
Σ(y−ŷ)² = sum of squared residuals (SSR)
Σ(y−ȳ)² = total sum of squares (SST)
R² ranges from 0 to 1
R² = 0.80 does not mean regression is "80% accurate." It means the x variable accounts for 80% of the observed variation in y. The remaining 20% comes from other factors not in the model. See the full R-squared guide for details.
Four Assumptions of Simple Linear Regression
The OLS estimates b₀ and b₁ have desirable properties only when these four conditions are met. Checking them — ideally with a residual plot — is part of responsible regression analysis.
Linearity
The relationship between x and y must be linear — a straight line, not a curve. Check by plotting the data in a scatter plot. If the pattern curves upward or downward, a transformation of x or y (such as log x) may be needed before fitting a regression.
Independence of Residuals
Each observation's residual must be independent of the others. This is most often violated in time-series data, where residuals from one period are correlated with the next. A Durbin-Watson test or residual time plot can reveal autocorrelation.
Homoscedasticity (Constant Variance)
The spread of residuals should be roughly constant across all values of x. When residuals fan out as x increases (heteroscedasticity), standard errors are biased. A residual-versus-fitted plot is the standard diagnostic. See the regression assumptions guide for correction methods.
Normality of Residuals
For inference (p-values, confidence intervals) to be valid, residuals should be approximately normally distributed. A Q-Q plot or Shapiro-Wilk test can check this. With large samples (n > 30), the Central Limit Theorem makes regression inference fairly robust to minor departures from normality.
Simple Linear Regression Examples — 8 Fully Solved
Each example below uses a small, realistic dataset so every arithmetic step is visible. All formulas follow the notation standard used by the NIST Engineering Statistics Handbook.
Example 1 — Study Hours vs. Exam Score (Education)
A professor records study hours and exam scores for 6 students. Is there a linear relationship, and how well can study time predict exam performance?
| Student | Study Hours (x) | Exam Score (y) | xy | x² |
|---|---|---|---|---|
| 1 | 1 | 52 | 52 | 1 |
| 2 | 2 | 58 | 116 | 4 |
| 3 | 3 | 65 | 195 | 9 |
| 4 | 5 | 78 | 390 | 25 |
| 5 | 6 | 84 | 504 | 36 |
| 6 | 7 | 91 | 637 | 49 |
| Σ | 24 | 428 | 1,894 | 124 |
Calculate the means:
x̄ = 24 / 6 = 4.00 | ȳ = 428 / 6 = 71.33
Calculate the slope:
b₁ = [6(1894) − (24)(428)] / [6(124) − (24)²]
= [11364 − 10272] / [744 − 576]
= 1092 / 168 = 6.50
Calculate the intercept:
b₀ = ȳ − b₁·x̄ = 71.33 − 6.50(4.00) = 71.33 − 26.00 = 45.33
Write the regression equation:
ŷ = 45.33 + 6.50x
Make a prediction:
If a student studies 4.5 hours: ŷ = 45.33 + 6.50(4.5) = 45.33 + 29.25 = 74.58 ≈ 75
Scatter Plot: Study Hours vs. Exam Score
✅ Equation: ŷ = 45.33 + 6.50x — Each additional study hour adds 6.50 points. A student who studies 4.5 hours is predicted to score about 75. The slope and intercept can be verified with the regression calculator.
R² for this example:
Example 2 — Advertising Spend vs. Sales Revenue (Business)
A retailer tracks weekly advertising spend (in $000s) and weekly sales (in $000s) over 5 weeks. What does a $1,000 increase in ad spend predict for sales?
| Week | Ad Spend x ($k) | Sales y ($k) | xy | x² |
|---|---|---|---|---|
| 1 | 2 | 14 | 28 | 4 |
| 2 | 3 | 19 | 57 | 9 |
| 3 | 4 | 23 | 92 | 16 |
| 4 | 5 | 27 | 135 | 25 |
| 5 | 6 | 31 | 186 | 36 |
| Σ | 20 | 114 | 498 | 90 |
Means: x̄ = 20/5 = 4.00 | ȳ = 114/5 = 22.80
Slope:
b₁ = [5(498) − (20)(114)] / [5(90) − (20)²]
= [2490 − 2280] / [450 − 400]
= 210 / 50 = 4.20
Intercept: b₀ = 22.80 − 4.20(4.00) = 22.80 − 16.80 = 6.00
Regression equation: ŷ = 6.00 + 4.20x
Prediction at x = 7 ($7,000 ad spend): ŷ = 6.00 + 4.20(7) = 6.00 + 29.40 = $35,400 in sales
✅ Equation: ŷ = 6.00 + 4.20x — Each extra $1,000 spent on advertising adds $4,200 in sales. At $7,000 spend, predicted sales = $35,400. R² for this dataset is approximately 0.998 — a near-perfect linear fit.
Example 3 — House Size vs. Sale Price (Real Estate)
A property analyst records house sizes (sq ft) and sale prices ($000s) for 6 homes. What price would a 1,800 sq ft house command?
| Home | Size x (sq ft) | Price y ($k) | xy | x² |
|---|---|---|---|---|
| 1 | 900 | 145 | 130,500 | 810,000 |
| 2 | 1,100 | 175 | 192,500 | 1,210,000 |
| 3 | 1,300 | 198 | 257,400 | 1,690,000 |
| 4 | 1,500 | 220 | 330,000 | 2,250,000 |
| 5 | 1,800 | 265 | 477,000 | 3,240,000 |
| 6 | 2,100 | 305 | 640,500 | 4,410,000 |
| Σ | 8,700 | 1,308 | 2,027,900 | 13,610,000 |
Means: x̄ = 8,700/6 = 1,450 | ȳ = 1,308/6 = 218.00
Slope:
b₁ = [6(2,027,900) − (8,700)(1,308)] / [6(13,610,000) − (8,700)²]
= [12,167,400 − 11,379,600] / [81,660,000 − 75,690,000]
= 787,800 / 5,970,000 = 0.132
Intercept: b₀ = 218.00 − 0.132(1,450) = 218.00 − 191.40 = 26.60
Equation: ŷ = 26.60 + 0.132x
Prediction at x = 1,800 sq ft: ŷ = 26.60 + 0.132(1,800) = 26.60 + 237.60 = $264,200
✅ Equation: ŷ = 26.60 + 0.132x — Each additional square foot adds approximately $132 to the predicted price. A 1,800 sq ft home is predicted to sell for $264,200. R² ≈ 0.997.
Example 4 — Work Experience vs. Salary (Economics)
An HR analyst records years of experience and annual salary ($000s) for 5 employees. What salary would an 8-year employee typically earn?
| Employee | Experience x (yrs) | Salary y ($k) | xy | x² |
|---|---|---|---|---|
| 1 | 1 | 38 | 38 | 1 |
| 2 | 3 | 45 | 135 | 9 |
| 3 | 5 | 54 | 270 | 25 |
| 4 | 7 | 63 | 441 | 49 |
| 5 | 9 | 72 | 648 | 81 |
| Σ | 25 | 272 | 1,532 | 165 |
Means: x̄ = 25/5 = 5.00 | ȳ = 272/5 = 54.40
Slope:
b₁ = [5(1532) − (25)(272)] / [5(165) − (25)²]
= [7660 − 6800] / [825 − 625]
= 860 / 200 = 4.30
Intercept: b₀ = 54.40 − 4.30(5.00) = 54.40 − 21.50 = 32.90
Equation: ŷ = 32.90 + 4.30x
Prediction at x = 8 years: ŷ = 32.90 + 4.30(8) = 32.90 + 34.40 = $67,300
✅ Equation: ŷ = 32.90 + 4.30x — Each year of experience adds approximately $4,300 to predicted salary. An employee with 8 years of experience would earn an estimated $67,300. R² ≈ 0.995.
Example 5 — Temperature vs. Electricity Usage (Environment)
A utility company records daily high temperature (°F) and household electricity usage (kWh) on 6 summer days. How much electricity is predicted when the high is 95°F?
| Day | Temperature x (°F) | Usage y (kWh) | xy | x² |
|---|---|---|---|---|
| 1 | 72 | 28 | 2,016 | 5,184 |
| 2 | 76 | 33 | 2,508 | 5,776 |
| 3 | 82 | 39 | 3,198 | 6,724 |
| 4 | 86 | 44 | 3,784 | 7,396 |
| 5 | 90 | 50 | 4,500 | 8,100 |
| 6 | 96 | 56 | 5,376 | 9,216 |
| Σ | 502 | 250 | 21,382 | 42,396 |
Means: x̄ = 502/6 = 83.67 | ȳ = 250/6 = 41.67
Slope:
b₁ = [6(21382) − (502)(250)] / [6(42396) − (502)²]
= [128292 − 125500] / [254376 − 252004]
= 2792 / 2372 = 1.177
Intercept: b₀ = 41.67 − 1.177(83.67) = 41.67 − 98.48 = −56.81
Equation: ŷ = −56.81 + 1.177x (negative intercept is expected — 0°F would produce no meaningful usage)
Prediction at 95°F: ŷ = −56.81 + 1.177(95) = −56.81 + 111.82 = 55.0 kWh
✅ Equation: ŷ = −56.81 + 1.177x — Each 1°F rise in temperature adds approximately 1.18 kWh to predicted electricity use. At 95°F, usage is estimated at 55 kWh. R² ≈ 0.993.
Example 6 — Exercise vs. Weight Loss (Healthcare)
A nutritionist records weekly exercise hours and monthly weight loss (lbs) for 5 participants. What weight loss does 6 hours of weekly exercise predict?
| Participant | Exercise x (hrs/wk) | Weight Loss y (lbs) | xy | x² |
|---|---|---|---|---|
| 1 | 1 | 0.8 | 0.8 | 1 |
| 2 | 2 | 1.5 | 3.0 | 4 |
| 3 | 3 | 2.2 | 6.6 | 9 |
| 4 | 5 | 3.6 | 18.0 | 25 |
| 5 | 7 | 4.9 | 34.3 | 49 |
| Σ | 18 | 13.0 | 62.7 | 88 |
Means: x̄ = 18/5 = 3.60 | ȳ = 13.0/5 = 2.60
Slope:
b₁ = [5(62.7) − (18)(13.0)] / [5(88) − (18)²]
= [313.5 − 234.0] / [440 − 324]
= 79.5 / 116 = 0.686
Intercept: b₀ = 2.60 − 0.686(3.60) = 2.60 − 2.47 = 0.13
Equation: ŷ = 0.13 + 0.686x
Prediction at 6 hrs/week: ŷ = 0.13 + 0.686(6) = 0.13 + 4.12 = 4.25 lbs/month
✅ Equation: ŷ = 0.13 + 0.686x — Each additional hour of weekly exercise predicts 0.686 lbs of extra weight loss per month. At 6 hours per week, predicted monthly weight loss is 4.25 lbs. R² ≈ 0.996.
Example 7 — Website Traffic vs. Conversions (Marketing)
A digital analyst records weekly website visitors (000s) and purchases made for 5 weeks. How many conversions does 12,000 visitors predict?
| Week | Visitors x (k) | Purchases y | xy | x² |
|---|---|---|---|---|
| 1 | 3 | 42 | 126 | 9 |
| 2 | 5 | 68 | 340 | 25 |
| 3 | 7 | 95 | 665 | 49 |
| 4 | 9 | 121 | 1,089 | 81 |
| 5 | 11 | 148 | 1,628 | 121 |
| Σ | 35 | 474 | 3,848 | 285 |
Means: x̄ = 35/5 = 7.00 | ȳ = 474/5 = 94.80
Slope:
b₁ = [5(3848) − (35)(474)] / [5(285) − (35)²]
= [19240 − 16590] / [1425 − 1225]
= 2650 / 200 = 13.25
Intercept: b₀ = 94.80 − 13.25(7.00) = 94.80 − 92.75 = 2.05
Equation: ŷ = 2.05 + 13.25x
Prediction at x = 12 (12,000 visitors): ŷ = 2.05 + 13.25(12) = 2.05 + 159.00 = 161 purchases
✅ Equation: ŷ = 2.05 + 13.25x — Each 1,000 additional visitors predicts approximately 13 more purchases. At 12,000 weekly visitors, the model predicts 161 conversions. R² ≈ 0.9997.
Example 8 — Rainfall vs. Crop Yield (Agriculture)
An agronomist records seasonal rainfall (mm) and wheat yield (tons/acre) for 6 growing seasons. What yield does 450mm of rainfall predict?
| Season | Rainfall x (mm) | Yield y (t/acre) | xy | x² |
|---|---|---|---|---|
| 1 | 250 | 2.1 | 525.0 | 62,500 |
| 2 | 310 | 2.6 | 806.0 | 96,100 |
| 3 | 370 | 3.0 | 1,110.0 | 136,900 |
| 4 | 420 | 3.4 | 1,428.0 | 176,400 |
| 5 | 480 | 3.8 | 1,824.0 | 230,400 |
| 6 | 530 | 4.2 | 2,226.0 | 280,900 |
| Σ | 2,360 | 19.1 | 7,919.0 | 983,200 |
Means: x̄ = 2360/6 = 393.33 | ȳ = 19.1/6 = 3.183
Slope:
b₁ = [6(7919) − (2360)(19.1)] / [6(983200) − (2360)²]
= [47514 − 45076] / [5899200 − 5569600]
= 2438 / 329600 = 0.0074
Intercept: b₀ = 3.183 − 0.0074(393.33) = 3.183 − 2.911 = 0.272
Equation: ŷ = 0.272 + 0.0074x
Prediction at 450mm: ŷ = 0.272 + 0.0074(450) = 0.272 + 3.330 = 3.60 tons/acre
✅ Equation: ŷ = 0.272 + 0.0074x — Each additional millimeter of rainfall predicts 0.0074 more tons per acre. At 450mm seasonal rainfall, predicted yield is 3.60 tons/acre. R² ≈ 0.996.
How to Interpret the Regression Output
Running a regression produces several numbers. Here is what each one actually means, using Example 1 (study hours vs. exam score) as the reference point.
| Output Value | From Example 1 | Plain-English Meaning |
|---|---|---|
| Slope (b₁) | 6.50 | Each extra hour of study adds 6.50 points to the predicted score, on average |
| Intercept (b₀) | 45.33 | A student who studies zero hours is predicted to score 45.33 (caution: extrapolation) |
| R² | 0.97 | 97% of the variation in exam scores is explained by study hours |
| Residual (e) | e = y − ŷ | How far the actual score was from the predicted score for each student |
| Pearson r | ≈ 0.985 | Strong positive linear relationship (r² = R² = 0.97) |
| Predicted ŷ | 75 (at x=4.5) | Expected exam score for a student studying exactly 4.5 hours |
Predicting ŷ for x values far outside the range of your data is unreliable. In Example 3 (house size), the model should not be used for a 10,000 sq ft mansion — the linear relationship observed in the 900–2,100 sq ft range may not extend that far.
Regression vs. Correlation: Key Differences
| Feature | Pearson Correlation (r) | Simple Linear Regression |
|---|---|---|
| Purpose | Measure strength and direction of a linear relationship | Predict y from x with a specific equation |
| Output | A single number between −1 and +1 | An equation: ŷ = b₀ + b₁x |
| Symmetric? | Yes — corr(x,y) = corr(y,x) | No — x predicts y, not the reverse |
| Prediction | Cannot produce predictions | Directly predicts ŷ for any x |
| Connection | r² = R² (coefficient of determination) | R² = r² from Pearson correlation |
| When to use | You want to describe association only | You have a predictor–outcome relationship |
For a full treatment of the correlation side, see the Pearson correlation guide. The scatter plot patterns that indicate strong vs. weak correlation are covered in scatter plots and correlation.
Simple vs. Multiple Linear Regression
| Feature | Simple Linear Regression | Multiple Linear Regression |
|---|---|---|
| Predictors | One (x) | Two or more (x₁, x₂, …) |
| Equation | ŷ = b₀ + b₁x | ŷ = b₀ + b₁x₁ + b₂x₂ + … |
| Visualization | 2D scatter plot with line | Requires 3D or partial regression plots |
| Interpretation | Slope = change in y per unit of x | Each slope = change in y, holding other variables constant |
| Best for | One clear predictor, learning regression fundamentals | Real-world data where multiple factors matter |
When one predictor is not enough — for example, predicting salary from both experience and education — the logical next step is multiple linear regression.
When to Use Simple Linear Regression
Should You Use Simple Linear Regression?
Real-Life Applications of Simple Linear Regression
Education
Predicting exam performance from study time. Schools use regression to identify students who need extra support before exams.
Real Estate
Estimating property values from square footage. Automated valuation models start with a linear regression between size and price.
Marketing
Forecasting sales from advertising spend. Helps marketers set budgets and estimate return on ad investment for a single channel.
Healthcare
Predicting blood pressure reduction from medication dose, or weight loss from exercise hours. Supports clinical decision-making.
Economics / HR
Estimating salary from years of experience. Used in wage analysis, compensation benchmarking, and labor market research.
Energy
Forecasting electricity demand from temperature. Utility companies use regression to plan daily grid capacity in hot or cold weather.
Agriculture
Predicting crop yields from rainfall. Governments and farmers use regression-based forecasts to plan food supply chains.
Web Analytics
Estimating purchases from website traffic. E-commerce teams use regression to set traffic acquisition targets linked to revenue goals.
Common Regression Mistakes and How to Avoid Them
| Mistake | Wrong Interpretation | Correct Interpretation |
|---|---|---|
| Treating R² as accuracy | "R² = 0.80, so the model is 80% accurate" | "80% of the variation in y is explained by x" |
| Ignoring the intercept context | "b₀ = 26.60 means a house with no size costs $26,600" | "b₀ is mathematically necessary but may be meaningless if x = 0 is outside the data range" |
| Confusing correlation with regression | "A high correlation means the regression is good at predicting" | "High r means a strong linear relationship, but regression quality also depends on data spread and residual patterns" |
| Extrapolating beyond data | Using a salary regression to predict income at 50 years experience when data only goes to 10 years | "The model is only reliable within the observed range of x values" |
| Confusing causation with prediction | "The regression shows that advertising causes sales" | "The regression shows that ad spend predicts sales — causation requires controlled experimental design" |
| Not checking residuals | Trusting output without looking at a residual plot | Always inspect the residual plot to confirm assumptions before reporting results |
Entity and Term Glossary
| Term / Symbol | Definition |
|---|---|
| Simple Linear Regression | Statistical method modeling the linear relationship between one predictor (x) and one outcome (y) |
| ŷ (y-hat) | Predicted value of the dependent variable from the regression equation |
| b₀ (Intercept) | Predicted value of y when x equals zero; where the regression line crosses the y-axis |
| b₁ (Slope) | Change in ŷ for each one-unit increase in x — the most informative regression coefficient |
| x (Independent Variable) | The predictor — the variable used to predict y; also called the explanatory or input variable |
| y (Dependent Variable) | The outcome — the variable being predicted; also called the response or output variable |
| Residual (e) | The difference between the actual y and the predicted ŷ: e = y − ŷ |
| OLS | Ordinary Least Squares — the method of fitting b₀ and b₁ by minimizing the sum of squared residuals |
| R² (Coefficient of Determination) | Proportion of variance in y explained by x; ranges 0–1; equals r² from Pearson correlation |
| Pearson r | Correlation coefficient measuring strength and direction of the linear relationship between x and y |
| Line of Best Fit | The regression line ŷ = b₀ + b₁x; minimizes the vertical distance from all data points to the line |
| Scatter Plot | A graph of paired (x, y) data points used to visually inspect the linear relationship before regression |
| Homoscedasticity | The assumption that residual variance is constant across all levels of x |
| Regression to the Mean | Term coined by Francis Galton: extreme observations tend to be followed by less extreme ones |
| Confidence Interval | Range within which the true population slope or mean ŷ likely falls at a given confidence level |
| Prediction Interval | A wider interval giving the range for an individual y observation at a given x — always wider than a CI |
| Mean Squared Error (MSE) | Average of squared residuals: Σ(y−ŷ)² / (n−2); lower is better |
| Francis Galton | 19th-century statistician who coined the term "regression" and discovered regression to the mean |
| Karl Pearson | Formalized the Pearson correlation coefficient (r) and developed much of the mathematics behind regression |
| scikit-learn | Python library with LinearRegression() class for fitting simple and multiple regression models |
Interactive Simple Linear Regression Calculator
Enter your x and y values below — one pair per line, separated by a comma. The calculator computes the slope, intercept, regression equation, R², and predicted ŷ for your chosen x value. Results match the manual formula exactly.
Simple Linear Regression Calculator
Frequently Asked Questions
References and Further Reading
- James, G., Witten, D., Hastie, T., & Tibshirani, R. (2021) — An Introduction to Statistical Learning with Applications in R, 2nd ed. Springer. Free PDF at statlearning.com — Chapter 3 covers simple linear regression comprehensively.
- NIST Engineering Statistics Handbook — "Simple Linear Regression." National Institute of Standards and Technology. itl.nist.gov — Authoritative reference for OLS formulas and regression diagnostics.
- Penn State STAT 462 — "Applied Regression Analysis." Pennsylvania State University. online.stat.psu.edu/stat462 — Free course notes covering interpretation, diagnostics, and inference.
- OpenStax Statistics — "Linear Equations." OpenStax College. openstax.org — Free textbook chapter on regression for introductory statistics courses.
- scikit-learn Documentation — "LinearRegression." scikit-learn.org — Python implementation reference for machine learning applications.
- Galton, F. (1886) — "Regression towards Mediocrity in Hereditary Stature." Journal of the Anthropological Institute of Great Britain and Ireland, 15, 246–263. — The paper that introduced the term "regression" to statistics.