← Back to the study guide, §8Study guide contents

DS 5030 · Understanding Uncertainty · Go deeper · §8

Inference for regression coefficients

Where every column of a regression table comes from, on a line you can drag.

Everything on five points

A regression table is a Wald test and a normal (or t) interval for each coefficient. On five points every number can be produced by hand. Data: \(x = 1, 2, 3, 4, 5\), \(y = 1, 3, 2, 5, 4\).

Work it by hand · coefficients

\(\bar x = \bar y = 3\). \(\sum(x - \bar x)(y - \bar y) = 4 + 0 + 0 + 2 + 2 = 8\); \(\sum(x - \bar x)^2 = 10\). Slope \(\hat\beta_1 = 0.8\); intercept \(\hat\beta_0 = 3 - 0.8 \times 3 = 0.6\).

Work it by hand · residuals and σ̂

Fitted \(1.4, 2.2, 3.0, 3.8, 4.6\); residuals \(-0.4, 0.8, -1.0, 1.2, -0.6\) (sum 0). RSS \(= 3.6\). \(\hat\sigma^2 = 3.6/(n - 2) = 1.2\), \(\hat\sigma = 1.095\). Two degrees of freedom were spent estimating two coefficients.

Work it by hand · the table row for the slope
coefstd errtP>|t| (t₃)[0.0250.975]
x0.8\(1.095/\sqrt{10} = 0.346\)2.310.10\(0.8 - 3.182 \times 0.346 = -0.30\)1.90
const0.6\(0.346\sqrt{55/5} = 1.15\)0.520.64−3.064.26

With \(z\) instead of \(t_3\), the slope's \(t = 2.31 > 1.96\) would "reject." With three residual degrees of freedom, the honest critical value is 3.18.

Work it by hand · the bow-tie and a prediction

SE of the fitted line at \(x\): \(\hat\sigma\sqrt{1/5 + (x - 3)^2/10}\) = 0.49 at \(x = 3\), 0.85 at \(x = 5\), 1.15 at \(x = 6\). Predicting a new \(y\) at \(x = 6\): \(\hat y = 5.4\), SE \(= \sqrt{1.15^2 + 1.2} = 1.59\), 95% prediction interval \(5.4 \pm 3.18 \times 1.59 = (0.35, 10.45)\).

Widget: drag the data, watch the table

A live regression table

Drag any point. The red line is the least-squares fit; the dark band is the 95% confidence band for the mean of \(y\) (the bow-tie); the light band is the 95% prediction band for a new point. The table updates with classical and robust (HC1) standard errors.

Things to try: drag one end point far up and watch the slope's SE and the bands change; load the fan-shaped data and compare the classical and robust SEs.

The matrix version by hand

Work it by hand · \((X^\top X)^{-1}X^\top y\) $$X^\top X = \begin{pmatrix}5 & 15\\15 & 55\end{pmatrix},\ (X^\top X)^{-1} = \frac{1}{50}\begin{pmatrix}55 & -15\\-15 & 5\end{pmatrix},\ X^\top y = \begin{pmatrix}15\\53\end{pmatrix},\ \hat\beta = \frac{1}{50}\begin{pmatrix}30\\40\end{pmatrix} = \begin{pmatrix}0.6\\0.8\end{pmatrix}.$$

\(\hat\sigma^2(X^\top X)^{-1} = 1.2 \times \frac{1}{50}\begin{pmatrix}55 & -15\\-15 & 5\end{pmatrix} = \begin{pmatrix}1.32 & -0.36\\-0.36 & 0.12\end{pmatrix}\). SEs \(\sqrt{1.32} = 1.15\) and \(\sqrt{0.12} = 0.346\). The correlation between \(\hat\beta_0\) and \(\hat\beta_1\) is \(-0.36/\sqrt{1.32 \times 0.12} = -0.905\): if the slope came out too steep, the intercept probably came out too low. That's the pivot of the bow-tie.

Work it by hand · the robust (sandwich) SE for the slope

\(\widehat{\text{se}}^2_{HC0} = \sum(x_i - \bar x)^2\hat\epsilon_i^2/\big(\sum(x_i - \bar x)^2\big)^2 = \frac{4(0.16) + 1(0.64) + 0 + 1(1.44) + 4(0.36)}{100} = 0.0416\), so 0.204; HC1 multiplies by \(\sqrt{n/(n-2)} = \sqrt{5/3}\): 0.263. Smaller than the classical 0.346 here, because the biggest residuals sit at low-leverage points near \(\bar x\).

Reading a real table

Worked example · Ames, Iowa (course)

2,930 house sales, 11 coefficients, df 2,919. Row: area 113.32 2.009 56.40 0.000 109.38 117.26.

Widget: when the SE formula is wrong

Classical vs. robust SEs under a fan-shaped error

2,000 simulated datasets: \(x\) uniform on 0–10, \(y = 1 + 0.5x + \epsilon\). The error SD depends on \(x\) in one of two shapes. The readouts compare the slope's true sampling SD with the average classical and robust SEs, and each method's coverage of the true slope.

The classical formula fails worst when the noisiest points are also the high-leverage ones (far from \(\bar x\)): "both ends" drops classical coverage to about 84%, while the robust SE stays near 94%. A fan that grows steadily with \(x\) does less damage when \(x\) is spread evenly.

Questions

Think about itIn the drag widget, move the point at \(x = 3\) far up. Why does the slope barely change, while moving the point at \(x = 5\) changes it a lot?

Leverage. The slope is \(\sum(x_i - \bar x)(y_i - \bar y)/\sum(x_i - \bar x)^2\), so a point's pull is proportional to \(x_i - \bar x\), which is 0 at \(x = 3\). Moving the middle point raises the intercept and inflates \(\hat\sigma\) (so every SE grows), but leaves the slope where it was.

Think about itWith strength \(\gamma = 0\) in the error-shape widget, which SE is better?

Both are about right on average (set strength to 0), but the classical one is slightly less noisy and its coverage is closer to 95% at small \(n\): when its assumption holds, it uses it. The robust SE costs a little efficiency in exchange for not depending on the assumption.

Check your understandingWhy is the prediction band so much wider than the confidence band?

The confidence band covers the average \(y\) at each \(x\), whose uncertainty shrinks like \(1/\sqrt n\). The prediction band covers a single new \(y\), which adds that point's own noise \(\hat\sigma^2\). With infinite data the confidence band collapses onto the line; the prediction band stays at roughly \(\pm 1.96\sigma\).

← §07 Many tests at once§09 When the machinery breaks →