4.9.22 · D4Probability Theory & Statistics

Exercises — Linear regression — least squares, inference on coefficients

2,165 words10 min readBack to topic

Before we start, we agree on the toolbox (nothing used before it is named):

A shared dataset (call it Set A) is used by several problems so you build fluency on one table:

The figure shows Set A with its least-squares line (cyan), its centroid (amber cross), and the residuals as amber vertical segments. Keep it open while you work L2 and L3 — the line is what you fit, the segments are what you square to get SSE.

Figure — Linear regression — least squares, inference on coefficients

Level 1 — Recognition

L1.1 — Read the pieces off a line

The fitted line from some data is . (a) What is the estimated slope ? (b) What is the estimated intercept ? (c) What does the slope mean in words?

Recall Solution

(a) The slope is the number multiplying : . (b) The intercept is the standalone number (value when ): . (c) "Each time goes up by , the fitted goes up by on average." The slope is a rate, not a total.

L1.2 — Which number is which?

For Set A you are told . Compute .

Recall Solution

. The mean is just add-them-up-and-divide; here.


Level 2 — Application

L2.1 — Fit the line to Set A by hand

Using , , compute , then and .

Recall Solution

Means first (everything centres on them): , .

Centred deviations : .

Centred deviations : . Multiply pairwise and add: (Term by term: .)

Slope = co-movement over -spread: . Intercept (forces the line through ): . Fitted line: .

L2.2 — Predict and check the centroid

Using the L2.1 line, predict at , and verify the line passes through .

Recall Solution

At : . At : ✓. The least-squares line always passes through the centre of mass — a free sanity check.


Level 3 — Analysis

L3.1 — Standard error and the -statistic

For Set A () the residuals are and the residual sum of squares is (you may take this). Compute , , , and the -statistic for testing . (These inference steps assume the error conditions stated in the toolbox above.)

Recall Solution

Residual variance (divide by because two coefficients were estimated): Standard error of the slope (defined in the toolbox — precision improves with more -spread): -statistic (how many SEs the slope sits from zero):

L3.2 — Decide significance

Critical value . At the 5% level, do we reject ? Build the 95% CI.

Recall Solution

, so we reject : the slope is significant. 95% CI: . The interval excludes — consistent with rejection. Notice it's the same decision from two angles (Hypothesis Testing via , or via the CI using the t-distribution with df).


Level 4 — Synthesis

L4.1 — from the decomposition

For Set A, and . Compute two ways (via SSE and via SSR) and confirm , where is the Correlation coefficient.

Recall Solution

Total up–down variation: . Residual (unexplained): . Explained: .

R^2=\frac{\text{SSR}}{\text{SST}}=\frac{24.0190}{31.3333}=0.7666.\ \checkmark$$ **Correlation check (exact):** $r^2 = \dfrac{S_{xy}^2}{S_{xx}S_{yy}}=\dfrac{20.5^2}{17.5\cdot31.3333}=\dfrac{420.25}{548.33}=0.7664.$ The tiny gap from $0.7666$ is only rounding in the "given" SSE; with exact arithmetic $R^2=r^2$ identically. The line explains about **77\%** of the variance in $y$.

L4.2 — Forecast-then-verify the lever effect

Without recomputing from data: suppose you could triple the spread of the 's (so becomes larger) while stays the same. Predict what happens to , then confirm with the formula. What does this say physically?

Recall Solution

Predict: . If , then , so the SE should shrink to one-third. Verify numerically: old SE ; new SE , and ✓. Physical meaning: wide-spread -values give the line a long lever arm, so the same vertical wobble pins the slope down far more precisely — echoing the Gauss–Markov Theorem idea that spread-out design points make the least-squares estimator sharp.


Level 5 — Mastery

L5.1 — Rebuild the slope's variance from scratch

Starting from with weights , and using with independent errors, prove that . Show why the collapse so neatly.

Recall Solution

What we do: treat as a fixed weighted sum of random . For independent terms, variance of a sum is the sum of (weight variance): Why: independence kills all the cross-covariance terms — only the diagonal survives. Now the collapse:

=\frac{S_{xx}}{S_{xx}^2}=\frac{1}{S_{xx}}.$$ Therefore $\text{Var}(\hat\beta_1)=\dfrac{\sigma^2}{S_{xx}}$. The numerator sum-of-squares *is* $S_{xx}$, so one power cancels. This is exactly the "long lever" fact made rigorous, and replacing $\sigma^2$ by $s^2$ gives the $\text{SE}(\hat\beta_1)=s/\sqrt{S_{xx}}$ we assumed in L3. (Under Gaussian errors this variance, plugged into a $t$-ratio, is what [[Maximum Likelihood Estimation]] would also hand you.)

L5.2 — Full pipeline on new data

New dataset Set B: , . Do the whole job: , , , , the -statistic for , and the significance decision at 5% ().

Recall Solution

Means: , . -deviations: . -deviations: . . Slope: . Intercept: . Line .

Fitted values: . Residuals : . , . . on df. Since , we reject at 5%: the slope is significant even with only 5 points, because the fit is tight and the 's are spread.


Recall One-line self-test

Slope of least squares ::: Why divide SSE by ::: two constraints (, ) remove 2 df, making unbiased What makes small ::: large (spread-out ) and small (little noise) in one phrase ::: fraction of 's variance explained by the line, equals here