4.9.23Probability Theory & Statistics

Multiple regression

1,890 words9 min readdifficulty · medium1 backlinks

WHAT is it?

WHY "partial"? In simple regression a slope mixes the direct effect of xx and whatever else xx correlates with. With several predictors in the model, βj\beta_j measures xjx_j's effect after the others have already explained what they can — its unique contribution.


Matrix form — WHY we switch notation

Writing nn equations one by one is painful. Stack them.

The column of 1's is HOW the intercept gets folded into the matrix algebra (it multiplies β0\beta_0 in every row).


DERIVATION from scratch — the normal equations

Goal: choose β\boldsymbol\beta to minimise the sum of squared residuals (vertical gaps): S(β)=i=1nεi2=yXβ2=(yXβ)(yXβ).S(\boldsymbol\beta)=\sum_{i=1}^n \varepsilon_i^2 = \|\mathbf{y}-\mathbf{X}\boldsymbol\beta\|^2 = (\mathbf{y}-\mathbf{X}\boldsymbol\beta)^\top(\mathbf{y}-\mathbf{X}\boldsymbol\beta).

Why squares? They are smooth (differentiable), penalise big misses harder, and give a unique closed-form answer.

Step 1 — expand. S=yy2βXy+βXXβ.S = \mathbf{y}^\top\mathbf{y} - 2\boldsymbol\beta^\top\mathbf{X}^\top\mathbf{y} + \boldsymbol\beta^\top\mathbf{X}^\top\mathbf{X}\boldsymbol\beta. Why this step? The two cross terms yXβ\mathbf y^\top \mathbf X\boldsymbol\beta and βXy\boldsymbol\beta^\top\mathbf X^\top\mathbf y are equal scalars (transpose of each other), so they combine into the 2-2 term.

Step 2 — differentiate w.r.t. the vector β\boldsymbol\beta and set to zero. Using β(aβ)=a\dfrac{\partial}{\partial\boldsymbol\beta}(\mathbf a^\top\boldsymbol\beta)=\mathbf a and β(βAβ)=2Aβ\dfrac{\partial}{\partial\boldsymbol\beta}(\boldsymbol\beta^\top A\boldsymbol\beta)=2A\boldsymbol\beta (for symmetric A=XXA=\mathbf X^\top\mathbf X): Sβ=2Xy+2XXβ=0.\frac{\partial S}{\partial\boldsymbol\beta} = -2\mathbf X^\top\mathbf y + 2\mathbf X^\top\mathbf X\boldsymbol\beta = \mathbf 0. Why set to zero? At a minimum the gradient vanishes; SS is convex (a quadratic with PSD Hessian 2XX2\mathbf X^\top\mathbf X), so this stationary point is the global minimum.

Step 3 — the normal equations.   XXβ^=Xy  \boxed{\;\mathbf X^\top\mathbf X\,\hat{\boldsymbol\beta} = \mathbf X^\top\mathbf y\;}

Step 4 — solve (if XX\mathbf X^\top\mathbf X is invertible, i.e. predictors not perfectly collinear):   β^=(XX)1Xy  \boxed{\;\hat{\boldsymbol\beta} = (\mathbf X^\top\mathbf X)^{-1}\mathbf X^\top\mathbf y\;}

Figure — Multiple regression

Measuring fit: R2R^2 and adjusted R2R^2

Problem: adding any predictor (even a random one) never decreases R2R^2. So we penalise complexity:


Worked Example 1 — tiny 2-predictor fit by hand-logic

Data: predict exam score yy from hours studied x1x_1 and hours slept x2x_2.

ii x1x_1 x2x_2 yy
1 1 6 50
2 2 7 65
3 3 5 70
4 4 8 85

We build X\mathbf X with a leading 1-column, form XX\mathbf X^\top\mathbf X (a 3×33\times3 matrix) and Xy\mathbf X^\top\mathbf y, then solve β^=(XX)1Xy\hat{\boldsymbol\beta}=(\mathbf X^\top\mathbf X)^{-1}\mathbf X^\top\mathbf y.

  • Why include the 1-column? Without it we force the surface through the origin — usually wrong.
  • Why solve the linear system rather than eyeball? With 2+ predictors there's no simple ratio; the predictors share information, so all slopes must be solved jointly.

(The VERIFY block below solves this exact system symbolically.)


Worked Example 2 — interpreting a partial slope

Suppose a fit gives y^=5+8x1+3x2\hat y = 5 + 8x_1 + 3x_2 where x1x_1=hours studied, x2x_2=hours slept.

  • β^1=8\hat\beta_1=8: one extra hour of study adds 8 points, holding sleep constant. Why "holding constant" matters: if studious students also sleep more, a simple regression of yy on x1x_1 alone would mistakenly credit study with sleep's benefit too.
  • Predict for x1=3,x2=7x_1=3,x_2=7: y^=5+24+21=50\hat y = 5 + 24 + 21 = 50. Why: just plug in; the model is linear so it's a weighted sum.

Common mistakes (Steel-man + fix)


Recall Feynman: explain to a 12-year-old

Imagine guessing how tall a plant will grow from how much water and how much sunlight it gets. You collect many plants and draw the best flat "ramp" through the dots so the up-and-down distances to the ramp are tiniest. The ramp's steepness in the water direction tells you how much taller a plant gets per cup of water — pretending sunlight stays the same — and the steepness in the sunlight direction does the same for light. Multiple regression is just the math for finding that best ramp.


Flashcards

What does the partial slope βj\beta_j measure in multiple regression?
The change in yy per unit change in xjx_j while holding all other predictors fixed (its unique contribution).
Write the least-squares estimator in matrix form.
β^=(XX)1Xy\hat{\boldsymbol\beta}=(\mathbf X^\top\mathbf X)^{-1}\mathbf X^\top\mathbf y.
State the normal equations.
XXβ^=Xy\mathbf X^\top\mathbf X\,\hat{\boldsymbol\beta}=\mathbf X^\top\mathbf y.
Why is the column of ones added to X\mathbf X?
To estimate the intercept β0\beta_0; without it the hyperplane is forced through the origin.
What objective does multiple regression minimise?
The sum of squared residuals yXβ2\|\mathbf y-\mathbf X\boldsymbol\beta\|^2.
Geometrically, what is y^\hat{\mathbf y}?
The orthogonal projection of y\mathbf y onto the column space of X\mathbf X; the residual is perpendicular to it.
Why use adjusted R2R^2 over R2R^2?
R2R^2 never decreases when predictors are added; adjusted R2R^2 penalises extra parameters via degrees of freedom.
What goes wrong under multicollinearity?
XX\mathbf X^\top\mathbf X is near-singular, so its inverse and the coefficient variances explode → unstable estimates.
Define R2R^2 via sums of squares.
R2=1SSE/SST=SSR/SSTR^2 = 1 - SSE/SST = SSR/SST.
Why squared (not absolute) residuals in OLS?
Smooth/differentiable, convex, gives a unique closed-form solution and the orthogonal-projection geometry.

Connections

  • Simple Linear Regression — the p=1p=1 special case.
  • Ordinary Least Squares — the estimation principle used here.
  • Orthogonal Projection — geometric meaning of the fitted values.
  • Multicollinearity & VIF — when XX\mathbf X^\top\mathbf X misbehaves.
  • Gauss–Markov Theorem — why OLS is BLUE under the assumptions.
  • Coefficient of DeterminationR2R^2 and adjusted R2R^2.
  • Matrix Inverse / Positive Semidefinite Matrices — solvability of the normal equations.

Concept Map

generalises to

models

contains

measures

stacked into

column of 1s gives

fit by minimising

differentiate and set to zero

solved gives

requires

assumes errors

Simple regression line

Multiple regression hyperplane

y equals linear combo of predictors

Partial slope beta_j

Unique effect holding others fixed

Matrix form y equals X beta plus eps

Intercept beta_0

Sum of squared residuals

Normal equations

Estimated beta hat

X transpose X invertible

Zero mean constant variance independent

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Multiple regression ka idea simple hai: tum ek output yy ko predict karna chahte ho lekin ek nahi, kai predictors (x1,x2,x_1, x_2, \dots) se. Jaise exam score ko study hours aur sleep hours dono se predict karna. Simple regression me ek line fit hoti thi; yahan ek flat plane (hyperplane) fit hota hai us data-cloud ke beech me, taaki har point se plane tak ka vertical gap (residual) sabse chhota ho. Isi ko hum "least squares" kehte hain — squares isliye ki woh smooth hote hain aur ek hi unique answer dete hain.

Formula yaad rakhna: β^=(XX)1Xy\hat{\boldsymbol\beta}=(\mathbf X^\top\mathbf X)^{-1}\mathbf X^\top\mathbf y. Ye derive hota hai sum of squared errors ko minimise karke — gradient ko zero set karo, normal equations XXβ^=Xy\mathbf X^\top\mathbf X\hat{\boldsymbol\beta}=\mathbf X^\top\mathbf y milte hain, phir invert karke beta solve karo. Geometry me yeh bas projection hai: tum y\mathbf y ko X\mathbf X ke column space pe perpendicular drop kar rahe ho.

Sabse important concept hai partial slope. β1\beta_1 ka matlab hai "x1x_1 ek unit badha to yy kitna badhega, baaki sab predictors constant rakhte hue". Isliye yeh simple regression se zyada honest hai — kyunki agar do predictors aapas me related hain, simple regression unka effect mix kar deta hai.

Do bade traps: (1) R2R^2 hamesha badhta hai jab tum naya predictor add karte ho, isliye adjusted R2R^2 dekho. (2) Agar predictors aapas me bahut correlated hain (multicollinearity), to XX\mathbf X^\top\mathbf X almost non-invertible ho jaata hai aur coefficients pagal ho jaate hain. Aur yaad rakho — regression sirf association batata hai, causation nahi.

Go deeper — visual, from zero

Test yourself — Probability Theory & Statistics

Connections