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.

Not startedJump to quiz

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 , , .

12−2−244
24−1001
350100
441001
552124
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.

Spread-out x: six resampled datasets give six similar slopes.
Clustered x (4.5–5.5): same truth, same noise, wildly different slopes.

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

1) Means . 2) Deviations. 3) Products & squares. 4) Sum → , . 5) Divide; then intercept. 6) Check residuals sum to 0.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1calculateFor the points , what are and ?
Q2calculateFor the points , what is the slope ?
Q3conceptWhy does the slope formula fail when every has the same value?
Q4conceptIn a model with an intercept, the OLS residuals always...
Q5interpretThe fitted line for and is . Which point must it pass through?