4.9.23 · D3Probability Theory & Statistics

Worked examples — Multiple regression

2,823 words13 min readBack to topic

This page is one long practice hall. We walk through every kind of situation a multiple-regression problem can hand you — clean data, degenerate data, collinear data, a real-world story, and an exam trick — and solve each one from the ground up. If a symbol appears here that you have not met, we build it first.

Before we start, one reminder from the parent note: the whole game is solving where is the table of predictors (with a leading column of 's), is the outcome column, and is the list of numbers we want: the intercept and the slopes.

We will also need three "sum of squares" quantities to judge fit. Build them now so they are never a surprise later:


The scenario matrix

Every problem below lands in one of these cells. The point is that after this page you have seen each cell at least once, so nothing on an exam is truly new.

Cell What makes it special Example
A. Clean full-rank fit predictors independent, invertible Ex 1
B. Single predictor sanity multiple-regression machinery must reduce to simple regression Ex 2
C. Negative slope a predictor that lowers Ex 3
D. Prediction + interpretation plug a new point into a fitted plane, read a partial slope Ex 4
E. Degenerate: perfect collinearity singular, inverse does not exist Ex 5
F. Near-collinearity (VIF blow-up) inverse exists but coefficients explode Ex 6
G. Fit quality: and adjusted including the "useless extra predictor" limiting case Ex 7
H. Real-world word problem translate a story into Ex 8
I. Exam twist centring / rescaling changes coefficients but not fit Ex 9

Ex 1 — Cell A: a clean full-rank fit

Forecast: guess — is the slope positive, and is it bigger or smaller than ? (The dots go generally up.)

  1. Build . Leading column of 's, then the column: Why this step? The -column is how the intercept enters the algebra — it multiplies in every row.

  2. Form and — and see where every entry comes from. Here (four rows), , and . So and . Why this step? Multiplying (a matrix whose first row is all 's and second row is the 's) by a column literally adds things up: a row of 's times a column is a plain sum; the -row times a column weights each entry by . Those are exactly the sums simple regression uses.

  3. Solve the system. For a matrix the inverse is . Here . So .

Why flag the determinant? , so the inverse genuinely exists (Matrix Inverse) — the machinery is sound. The safe habit is always to survive a plug-back check (Ex 2).

Verify: the VERIFY block solves the exact system symbolically: the correct line is , giving with residuals summing to .

The figure below plots these four points, draws the fit line in yellow, and marks each residual (the pink vertical stick from a dot to the line). Look at the pink sticks: they are the vertical gaps least squares makes as small as possible, and their signed lengths add to zero.

Figure — Multiple regression

Ex 2 — Cell B: the machine must reduce to simple regression

Forecast: the honest slope should be less than 1 (the dots rise but not on a perfect line). Guess: around ?

  1. Centre the data. . Deviations , . Why this step? Centring removes the intercept from the slope calculation — it isolates the "tilt". The simple-regression slope formula is the single-predictor special case of , so if the two disagree we have made an arithmetic slip.

  2. Numerator (covariation) .

  3. Denominator (spread of ) .

  4. Slope , and intercept .

Why this matches Ex 1: two independent routes — the matrix inverse in Ex 1 and the centred slope formula here — both land on . That agreement is the strongest sanity check we have.

Verify: with , predictions are , residuals which sum to . ✓


Ex 3 — Cell C: a genuinely negative slope

Forecast: more maintenance → fewer defects, so the slope should be negative. Guess its size.

  1. Sums. . Why this step? These four sums are all and need — exactly the pattern and we built in Ex 1 Step 2.

  2. Normal equations.

  3. Determinant , so So .

Why negative works fine: least squares never demands positive slopes; the sign just follows the data's tilt.

Verify: exactly matches — the points are perfectly collinear, so all residuals are and . Units: defects per (maintenance hour) , meaning 2 fewer defects per extra hour. ✓


Ex 4 — Cell D: two predictors, predict and interpret

Forecast: plugging in is a weighted sum; the sleep effect per hour is just .

  1. (a) Substitute. . Why this step? The model is linear, so prediction is literally the dot product of the coefficient vector with .

  2. (b) Partial slope. Change by , hold fixed: . Why "hold fixed": is the partial slope — sleep's unique contribution after study is accounted for (Orthogonal Projection is why this "after" is clean).

Verify: recompute (a) with a small nudge: at , , which is — consistent with per study hour. Units check: points, and points-per-hour. ✓


Ex 5 — Cell E: perfect collinearity, the inverse dies

Forecast: two columns carrying the same information — the machine should choke.

  1. Look at the columns. The column is exactly the column. One is a copy of the other (scaled). Why this matters: the column space of is "flat" in the plane — the predictors do not span a genuine 2D direction.

  2. Compute the determinant explicitly. Take a tiny two-row example with just the two length columns (drop the intercept for a clean to make the algebra visible): , Now the determinant, entry by entry: So exactly — the two products cancel because the second column is the first, which forces and patterns that make and equal.

  3. No inverse. Since the determinant is , the formula divides by zero: does not exist. Infinitely many minimise equally — the plane can tilt freely in the redundant direction at zero cost. Why: dividing by a "flat" matrix is like dividing by zero — see Multicollinearity & VIF and Positive Semidefinite Matrices ( is only semidefinite here, not positive definite).

Verify: the VERIFY block confirms for the full three-column version too. Fix: drop one of the two length columns; the remaining fit is unique. ✓

The figure below draws the two predictor columns as arrows from the origin. Because , the pink arrow lies exactly on top of the blue one's direction (only its length differs). Two arrows pointing the same way cannot frame a 2-D patch of area — and zero area is a zero determinant.

Figure — Multiple regression

Ex 6 — Cell F: near-collinearity, coefficients explode

Forecast: the inverse exists (determinant tiny but nonzero) yet the answer is unstable.

  1. Why unstable: divides by a near-zero determinant, magnifying tiny data changes into huge coefficient swings. Why this step? This is the practical face of Multicollinearity & VIF.

  2. Concrete blow-up. Solve the least-squares fit for once, then change the last outcome from to and solve again. Both slopes shift substantially from a mere -unit data nudge — the exact rational before/after values, and the size of the swing, are computed in the VERIFY block. Why this happens: and differ only in the last entry, so the fit must lean heavily on that one distinguishing coordinate; a tiny wobble there whipsaws both slopes.

  3. The VIF summary. Regress on ; the near-perfect fit gives close to , so the variance inflation factor is huge. At this equals ; standard errors scale with . High VIF is the early-warning gauge for exactly the whipsaw in Step 2.

Verify: VERIFY confirms (i) is small-but-positive here (inverse exists, unlike Ex 5); (ii) the two coefficient vectors differ noticeably after the -unit nudge; and (iii) . ✓


Ex 7 — Cell G: , adjusted , and the useless predictor limit

Forecast: always rises when you add a variable; adjusted should fall for junk.

  1. (a) . . Why this step? is the fraction of variance explained: the leftover error as a share of the total wobble , subtracted from .

  2. Adjusted with : Why this step? Dividing by degrees of freedom penalises each extra predictor.

  3. (b) Add junk. Now , , so (rose slightly, as always). But Adjusted fell from to .

Why: the useless predictor cost a degree of freedom ( dropped ) but barely reduced error — a bad trade.

Verify: VERIFY recomputes all four numbers () and confirms the adjusted value dropped. ✓


Ex 8 — Cell H: a real-world word problem

Forecast: warmer days sell more (positive ), weekends sell more (positive ).

  1. Set up three equations. Why this step? With exactly as many points as unknowns and independent rows, the plane passes through all three — no least-squares averaging needed.

  2. Subtract eqn 1 from eqn 2: ($4 revenue per °C).

  3. Subtract eqn 1 from eqn 3: ($60 extra on a weekend).

  4. Back-substitute into eqn 1: .

Verify: plug : ✓; plug : ✓. Units: dollars, dollars-per-degree, dollars-per-weekend. Interpretation of : the weekend bump holding temperature fixed — a clean partial effect. ✓


Ex 9 — Cell I: the exam twist (centring changes coefficients, not fit)

Forecast: the slope should stay (steepness is unaffected by shifting the axis); the intercept must change so the line still passes through the same points.

  1. Slope is invariant to shifting . Replacing by leaves and the covariation unchanged, so . Why this step? Centring slides the vertical axis left/right; it does not tilt the line, and the slope formula depends only on deviations from the mean, which shifting cannot alter.

  2. New intercept = fitted value at , i.e. at : . So . Why: when we sit at the mean of ; a least-squares line always passes through the point , and . Hence the centred intercept equals .

  3. Fit unchanged. Predictions — algebraically identical to Ex 3. So , every residual, and every prediction are exactly the same; only the labels vs moved.

Verify: VERIFY confirms and that the centred predictions equal the original . Lesson: rescaling/centring predictors reshuffles coefficients but never the quality of fit — beware exam questions that hide this behind a scary-looking coefficient change.


Recall Which cell was hardest for you?

Perfect collinearity (Ex 5) fails ::: because is singular (), so does not exist and is not unique. Adjusted falls for a useless predictor ::: because shrinks (lost degree of freedom) while barely drops — a bad trade. Centring changes the intercept to ::: (the fitted value at the mean of ), while the slope and the fit are unchanged.