Lesson 22: Linear Regression
November 30, 2026
Review:
- Course Evaluations are open until 18 Dec
- Scatterplots
- Sum of Squares
Presentation:
- Linear regression (simple, bivariate)
- Calculate equation of the regression line
- y-hat = b1*x + bo
- b1 = “slope” of the line
- b0 = “y-intercept”
- Calculate Sum of Squares: SSxx, SSyy, SSxy
- b1 = SSxy/SSxx
- b0 = (∑y/n) – b1*(∑x/n)
- y-hat = b1*x + bo
- Calculate equation of the regression line
- Pearson Correlation Coefficient
- r = SSxy/√(SSxx*SSyy)
- -1 < r < 1
- R-Squared
- Calculate r and then square the result, i.e., =r^2
- 0 < r^2 < 1
- Example 1: Rideshare Fare Estimation
- Use distance to predict fare
- Sample data (x=miles, y=fare $)
- Ride 1: 2, 7
- Ride 2: 3, 11
- Ride 3: 5, 15
- Ride 4: 7, 16
- Ride 5: 8, 21
- Scatterplot
- Table setup
- columns: x, y, x^2, y^2, xy
- sums: ∑x, ∑y, ∑x^2, ∑y^2, ∑xy
- Sum of Squares calculations
- SSxx = ∑x² – (∑x)²/n
- SSyy = ∑y² – (∑y)²/n
- SSxy = ∑xy – (∑x*∑y)/n
- Linear equation
- b1 = SSxy/SSxx
- b0 = (∑y/n) – b1*(∑x/n)
- Pearson Correlation Coefficient
- r = SSxy/√(SSxx*SSyy)
- R-Squared
- Calculate r and then square the result, i.e., =r^2
- 0 < r^2 < 1
- Example 2: Used car price by vehicle age
- Use temperature to predict sales
- Sample data (x=age in yrs, y=$1000s)
- Car 1: 1, 28
- Car 2: 2, 23
- Car 3: 4, 17
- Car 4: 5, 16
- Car 5: 8, 6
- Scatter Plot
- Table setup
- columns: x, y, x^2, y^2, xy
- sums: ∑x, ∑y, ∑x^2, ∑y^2, ∑xy
- Sum of Squares calculations
- SSxx = ∑x² – (∑x)²/n
- SSyy = ∑y² – (∑y)²/n
- SSxy = ∑xy – (∑x*∑y)/n
- Linear equation
- b1 = SSxy/SSxx
- b0 = (∑y/n) – b1*(∑x/n)
- Pearson Correlation Coefficient
- r = SSxy/√(SSxx*SSyy)
- R-Squared
- Calculate r and then square the result, i.e., =r^2
- 0 < r^2 < 1
- Video: Fitting Lines to Data
Activity:
For each problem (all the same as last week) below, calculate the linear equation, the Pearson Correlation Coefficient (r) and R-Squared
Problem 1 – Advertising and Sales (n = 6)
A retail chain studied weekly advertising spend and sales (both in $1,000s).
| Week | Advertising (x) | Sales (y) |
|---|---|---|
| 1 | 1 | 35 |
| 2 | 2 | 37 |
| 3 | 3 | 47 |
| 4 | 5 | 58 |
| 5 | 6 | 61 |
| 6 | 7 | 62 |
Problem 2 – Training Hours and Productivity (n = 6)
An HR analyst examined whether more training hours lead to higher productivity (daily packages processed per worker).
| Dept | Training Hours (x) | Productivity (y) |
|---|---|---|
| A | 2 | 42 |
| B | 4 | 39 |
| C | 6 | 49 |
| D | 8 | 51 |
| E | 10 | 55 |
| F | 12 | 46 |
Problem 3 – Price and Units Sold (n = 6)
A manufacturer tested different price points ($) to estimate demand.
| Trial | Price (x) | Units Sold (y) |
|---|---|---|
| 1 | 4 | 72 |
| 2 | 5 | 57 |
| 3 | 6 | 52 |
| 4 | 8 | 32 |
| 5 | 9 | 27 |
| 6 | 10 | 24 |
Problem 4 – Experience and Salary (n = 6)
An HR department compared employees’ years of experience with their annual salary (in $1,000s).
| Employee | Experience (x) | Salary (y) |
|---|---|---|
| 1 | 1 | 46 |
| 2 | 2 | 53 |
| 3 | 4 | 59 |
| 4 | 6 | 60 |
| 5 | 8 | 70 |
| 6 | 9 | 72 |
Problem 5 – Wait Time and Customer Satisfaction (n = 6)
A bank recorded customers’ average wait time (minutes) and their satisfaction score (0–100).
| Branch | Wait Time (x) | Satisfaction (y) |
|---|---|---|
| A | 2 | 84 |
| B | 4 | 70 |
| C | 5 | 76 |
| D | 7 | 58 |
| E | 8 | 53 |
| F | 10 | 55 |
Problem 6 – CEO Tenure and Stock Return (n = 6)
An investor wondered whether companies with longer-serving CEOs earn higher annual stock returns (%).
| Company | CEO Tenure, years (x) | Stock Return % (y) |
|---|---|---|
| 1 | 2 | 12 |
| 2 | 3 | 6 |
| 3 | 5 | 10 |
| 4 | 6 | 4 |
| 5 | 8 | 14 |
| 6 | 12 | 8 |