Chapter 3 of 5
The OLS Solution
Hand calculation, step by step
OLS finds the one line with the smallest total squared error. Let's calculate it by hand.
Step 1: Find the averages. x̄ (mean size) and ȳ (mean price).
x̄ (mean size) 0 sqft
ȳ (mean price) $0
Step 2: How far is each point from the average? These are deviations.
Step 3: Multiply the deviations together. Sum them up, then divide by n − 1 — that's the covariance.
| # | xi - x̄ | × | yi - ȳ | = | product |
|---|---|---|---|---|---|
| 1 | -246 | × | -77,183 | = | 18,961,323 |
| 2 | -226 | × | -142,551 | = | 32,169,039 |
| 3 | -217 | × | -56,882 | = | 12,324,462 |
| 4 | -144 | × | -68,300 | = | 9,812,452 |
| 5 | -122 | × | -47,959 | = | 5,835,028 |
| 6 | -88 | × | -8,850 | = | 775,862 |
| 7 | -84 | × | -14,406 | = | 1,205,313 |
| 8 | 35 | × | 46,272 | = | 1,634,939 |
| 9 | 52 | × | 5,486 | = | 287,094 |
| 10 | 110 | × | 19,034 | = | 2,100,070 |
| 11 | 113 | × | 64,752 | = | 7,338,545 |
| 12 | 154 | × | 15,569 | = | 2,402,795 |
| 13 | 199 | × | 91,526 | = | 18,244,156 |
| 14 | 222 | × | 115,675 | = | 25,718,379 |
| 15 | 237 | × | 57,819 | = | 13,722,344 |
| Sum / (n - 1) = | 10,895,128.7 | ||||
Cov(x, y) 0.0
Step 4: Square the x-deviations and average them. That's the variance of x.
| # | xi - x̄ | (xi - x̄)² |
|---|---|---|
| 1 | -246 | 60,352 |
| 2 | -226 | 50,925 |
| 3 | -217 | 46,944 |
| 4 | -144 | 20,640 |
| 5 | -122 | 14,803 |
| 6 | -88 | 7,685 |
| 7 | -84 | 7,000 |
| 8 | 35 | 1,248 |
| 9 | 52 | 2,739 |
| 10 | 110 | 12,173 |
| 11 | 113 | 12,844 |
| 12 | 154 | 23,819 |
| 13 | 199 | 39,734 |
| 14 | 222 | 49,432 |
| 15 | 237 | 56,327 |
| Sum / (n - 1) = | 29,047.7 | |
Var(x) 0.0
Step 5: Divide covariance by variance. That's β₁, the slope.
Cov(x,y) 10,895,128.7
/ Var(x) 29,047.7
= β₁ (slope) 0.00
For every additional square foot, the predicted price increases by $375.
Step 6: The intercept. β₀ = ȳ − β₁ · x̄
ȳ (mean price) 174,664 from Step 1
− β₁ (slope) 375.08 from Step 5
× x̄ (mean size) 348 from Step 1
= β₀ (intercept) $0
A hypothetical 0 sqft house would cost $44,262. (It's the baseline, not a real prediction.)