4.9.23 · D4Probability Theory & Statistics

Exercises — Multiple regression

2,607 words12 min readBack to topic

Throughout, , the least-squares estimator is , and = number of observations, = number of predictors (so has columns including the leading 1-column).


Level 1 — Recognition

Can you name the parts and read off the model?

Exercise 1.1

Given the fitted model , state (a) the intercept, (b) the partial slope of , (c) the predicted when .

Recall Solution 1.1

(a) The intercept is the constant term: (predicted when both predictors are ). (b) The partial slope of is its multiplier: . It means drops by 4 for each 1-unit rise in , holding fixed. (c) Plug in — the model is a weighted sum:

Exercise 1.2

For a dataset with observations and predictors, what are the dimensions (rows columns) of , of , and of ?

Recall Solution 1.2
  • has one row per observation and columns (the 1-column + + ): .
  • is (square, one row/col per coefficient).
  • is (a column, matching ).

Why square? Being square is a necessary condition to even talk about an inverse — but it is not sufficient. is also invertible only when its determinant is nonzero, which happens exactly when has full column rank (linearly independent columns, proved in Ex 5.1). A square-but-rank-deficient matrix has and no inverse (Matrix Inverse).


Level 2 — Application

Plug into the machinery and turn a handle.

Exercise 2.1

Solve the tiny system by hand. Fit (simple case, one predictor) to:

1 0 1
2 1 3
3 2 4

Build , form and , and solve .

Recall Solution 2.1

Step 1 — build (leading 1-column then the column): Step 2 — form . Row-of-ones itself ; ones ; : Step 3 — form . ; : Step 4 — invert the . Why this formula works: for a matrix , the inverse is . The scalar measures the (signed) area the matrix's columns span; dividing by it undoes the scaling. The rearranged matrix (swap the diagonal, negate the off-diagonal) is the adjugate — you can check by direct multiplication, which is why dividing by then gives . Here (so the inverse exists): Step 5 — solve: So and . (This is exactly Ordinary Least Squares on one predictor — same machinery, matrix-shaped.)

Exercise 2.2

A fit gives . Study hours was measured in hours. You now re-measure it in minutes but keep and unchanged, and refit. What is the new coefficient on the minutes-variable? Explain.

Recall Solution 2.2

One hour minutes, so the minutes value is the hours value: . To keep every prediction identical, the coefficient must shrink by the same factor: New coefficient . The fit is unchanged — only the number relabelling the same slope changed.


Level 3 — Analysis

Explain the "why" behind a number.

Exercise 3.1

A model on observations with predictors has and . Compute and adjusted . Then add one useless (random) predictor that reduces only to ; recompute adjusted (now ). What happened, and why?

Recall Solution 3.1

Original (): After adding the junk predictor (, ): What happened: plain rose () even though the predictor is garbage — can never fall when you add a column. But adjusted fell () because the denominator shrank from to , penalising the wasted degree of freedom. Adjusted correctly flags the junk.

Exercise 3.2

Two predictors are highly correlated. Explain, using , why their estimated coefficients become wildly unstable. Refer to Figure s01.

Figure — Multiple regression
Figure s01 — What to see: Left panel: two arrows from the origin, the blue "column " and orange "column ", drawn at almost the same angle — the red note "tiny angle ⇒ det ≈ 0" marks how nearly parallel they are. Right panel: a green line/band in space along which every pair of slopes fits the data almost equally well; the three red dots are wildly different slope pairs all landing on that band — i.e. the data cannot choose between them.

Recall Solution 3.2

When and are nearly parallel (left panel of the figure), the columns of almost lie on one line, so is near-singular: its determinant is close to . The inverse is computed as , where is the adjugate (the matrix of cofactors, transposed). The cofactor entries stay of ordinary size, but they are all divided by a determinant that is heading to — so the entries of the inverse blow up. It is not a clean scalar proportionality; the point is that the shared factor magnifies every entry. Hence tiny changes in the data produce huge swings in . Geometrically (right panel), tilting the fitted plane steeply "up" along and equally steeply "down" along barely moves the surface where the data sit, so the data can't pin the two slopes down: many wildly different fit almost equally well.

This is multicollinearity. It is quantified by the VIF (variance inflation factor): for predictor , where is the obtained by regressing on all the other predictors. If and are nearly parallel, each explains the other almost perfectly, so and — the factor by which the variance of is inflated relative to the no-collinearity case. A common rule of thumb flags .


Level 4 — Synthesis

Combine several ideas into one argument.

Exercise 4.1

Prove that the residual vector is orthogonal to every column of , and hence that the residuals sum to zero whenever the model has an intercept. Connect this to Figure s02.

Figure — Multiple regression
Figure s02 — What to see: a translucent blue plane = the column space of (all vectors the fitted surface can produce). The orange arrow "y" points off the plane (the real data). The green arrow "y_hat = Xb" lies inside the plane — the closest point. The red arrow "e = y − y_hat" joins the tip of up to and meets the plane at a marked 90° angle: the residual is perpendicular to the whole space.

Recall Solution 4.1

Orthogonality. Start from the normal equations . Move everything to one side: literally says the dot product of each column of with is zero — i.e. is perpendicular to every predictor direction. That is orthogonal projection: is the shadow of on the column space, is the perpendicular drop (Figure s02, red arrow). Residuals sum to zero. With an intercept, 's first column is all ones, . Its row of reads So the positive and negative vertical gaps exactly cancel — a direct consequence of including the 1-column.

Exercise 4.2

Show that the SST = SSR + SSE decomposition (used in ) is really the Pythagorean theorem for the projection. Use centring. (Recall = sum of squares due to regression, defined at the top of the page.)

Recall Solution 4.2

Center everything by subtracting . Write:

  • total vector (length = ),
  • explained vector (length = ),
  • residual vector (length = ). These add: . Take squared length: The cross term vanishes: lives in the column space of (both and are combinations of 's columns), and that whole space by Ex 4.1. So , giving This is exactly for a right triangle whose right angle is at — the same right angle from Figure s02.

Level 5 — Mastery

Prove something general, or handle a degenerate case.

Exercise 5.1

Prove that is always positive semidefinite, and that it is positive definite (hence invertible) iff the columns of are linearly independent. Explain what "perfect multicollinearity" does to this.

Recall Solution 5.1

PSD. For any vector , A squared length is never negative, so is positive semidefinite. Always. Positive definite iff full column rank. forces .

  • If columns are linearly independent, the only with is . So for all → positive definite → invertible → unique .
  • If columns are dependent (perfect collinearity), some gives , so with → only semidefinite, , not invertible. The formula doesn't exist; infinitely many minimise .

Exercise 5.2

Using Ex 5.1, show that when is invertible the least-squares solution is not just a stationary point but the unique global minimum of .

Recall Solution 5.2

The objective is , a quadratic whose Hessian (matrix of second derivatives) is . By Ex 5.1 this is positive definite when columns are independent. A quadratic with a positive-definite Hessian is strictly convex: it curves upward in every direction, so it has exactly one lowest point and no other stationary points. That single point is where the gradient vanishes — i.e. the normal equations — giving the unique . This is exactly what the Gauss–Markov Theorem needs to even speak of "the" estimator. Compare with Simple Linear Regression, where the same convexity gives the one best line.


Recall Quick self-check

One-line answers before you leave. Ex 2.1 gives and equal to what? ::: and . In Ex 3.1, why does adjusted fall when plain rises? ::: The degrees-of-freedom penalty shrinks faster than drops for a useless predictor. What single equation proves residual every column of ? ::: (the normal equations rearranged). When is positive definite (not just PSD)? ::: Exactly when has linearly independent columns (full column rank).