Lesson 3.4 · 12 min read · about 1 h 5 min to master at a very slow pace
Calculating Regression Coefficients by Hand
The slope and intercept formulas for simple regression, a full worked example with a table of deviations, and why a predictor with little variation gives an unreliable slope.
The formulas
Simple regression
- The numerator measures how and move together: positive when above-average goes with above-average .
- The denominator measures how spread out is.
- The fitted line always passes through the point of means .
Worked example: dataset B
and . So , , .
| 1 | 2 | −2 | −2 | 4 | 4 |
| 2 | 4 | −1 | 0 | 0 | 1 |
| 3 | 5 | 0 | 1 | 0 | 0 |
| 4 | 4 | 1 | 0 | 0 | 1 |
| 5 | 5 | 2 | 1 | 2 | 4 |
| Sum | |||||
and . The fitted line is .
Fitted values: . Residuals: . They sum to zero, which always happens when the model has an intercept.
RSS . We'll reuse this in 3.7 and 3.8.
Now build the same table yourself, one column at a time:
Why low variance in X is a problem
Look at the denominator . If the values barely vary, is tiny, and small changes in a few values swing the slope a lot. If is constant, and the slope can't be computed at all.
Design lesson
To estimate how changes with , you need to observe over a decent range. This is limited information about the slope, and it shows up later as a large standard error (3.8).
Stuck? Common doubts
Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.
First passDo I need to do the full manual calculation (means, deviations, products, squares)?
For a closed-book exam with "calculate by hand" questions, yes: practise the table above until you can do it in a few minutes, because it earns method marks even if the arithmetic slips. Conceptually, what matters is: the slope is "how and co-vary" divided by "how much varies", and the line passes through . If you're short on time, understand that first and return to the drill before the exam.
First passWhy does low variance in the predictor make the slope unreliable?
The slope's denominator is . When the values are clustered, is small, so tiny changes in the values (noise) produce big changes in . Intuitively, if you only see houses between 99 and 101 m², you have almost no information about how price changes with size. In 3.8 this appears as getting large.
Cheatsheet
Simple regression by hand
Slope by hand
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.