Multiple Linear Regression › Mathematical Foundation

Michael BrenndoerferApril 16, 20253 min read
Machine Learning from ScratchAll chapters
Part 4 of 9Regression Models
Chapter 31Multiple Linear Regression › Mathematical Foundation
Reading section 2 of 11 · Mathematical Foundation · 3 minSection 2 of 11 · 3 min

Book contents

Section 2 of 11 · 3 min read

Multiple Linear Regression › Mathematical FoundationOne section · Sections in this chapter2 / 11 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Multiple linear regression extends the simple linear regression model to incorporate multiple predictor variables. The mathematical foundation builds upon the principles of ordinary least squares (OLS) estimation, which is covered in detail in the dedicated OLS chapter.

Model Specification

The multiple linear regression model can be written as:

yi=β0+β1xi1+β2xi2+⋯+βpxip+ϵiy_i = \beta_0 + \beta_1 x_{i1} + \beta_2 x_{i2} + \cdots + \beta_p x_{ip} + \epsilon_i

where:

  • yiy_i: observed value of the target variable for the ii-th observation
  • β0\beta_0: intercept (bias term) - the predicted value of yy when all features equal zero
  • β1,β2,…,βp\beta_1, \beta_2, \ldots, \beta_p: coefficients (slopes) for each feature, representing the partial effect of each feature
  • xi1,xi2,…,xipx_{i1}, x_{i2}, \ldots, x_{ip}: values of the pp features for the ii-th observation
  • ϵi\epsilon_i: error term (residual) - the difference between the actual and predicted values

The key insight is that each coefficient βj\beta_j represents the partial effect of feature jj on the target variable, holding all other features constant. This is the fundamental difference from simple linear regression, where we only consider one feature at a time.

Matrix Notation

When working with nn observations and pp features, the model can be written compactly using matrix notation:

y=Xβ+ϵ\mathbf{y} = \mathbf{X} \boldsymbol{\beta} + \boldsymbol{\epsilon}

where:

  • y\mathbf{y}: n×1n \times 1 vector containing all observed target values
  • X\mathbf{X}: n×(p+1)n \times (p+1) design matrix containing all feature values with a column of ones for the intercept
  • β\boldsymbol{\beta}: (p+1)×1(p+1) \times 1 vector of coefficients (including intercept)
  • ϵ\boldsymbol{\epsilon}: n×1n \times 1 vector of error terms (residuals)

The design matrix X\mathbf{X} has the structure:

X=[1x11x12⋯x1p1x21x22⋯x2p⋮⋮⋮⋱⋮1xn1xn2⋯xnp]\mathbf{X} = \begin{bmatrix} 1 & x_{11} & x_{12} & \cdots & x_{1p} \\ 1 & x_{21} & x_{22} & \cdots & x_{2p} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 1 & x_{n1} & x_{n2} & \cdots & x_{np} \end{bmatrix}

The first column of ones enables estimation of the intercept term, while subsequent columns contain the feature values for each observation.

Coefficient Estimation

The coefficients in multiple linear regression are estimated using the Ordinary Least Squares (OLS) method, which finds the values of β0,β1,…,βp\beta_0, \beta_1, \ldots, \beta_p that minimize the sum of squared differences between observed and predicted values.

The OLS solution is given by the closed-form formula:

β^=(X⊤X)−1X⊤y\hat{\boldsymbol{\beta}} = (\mathbf{X}^\top \mathbf{X})^{-1} \mathbf{X}^\top \mathbf{y}

where:

  • β^\hat{\boldsymbol{\beta}}: estimated coefficient vector (including intercept)
  • X⊤X\mathbf{X}^\top \mathbf{X}: (p+1)×(p+1)(p+1) \times (p+1) matrix of feature cross-products
  • (X⊤X)−1(\mathbf{X}^\top \mathbf{X})^{-1}: inverse of the cross-product matrix
  • X⊤y\mathbf{X}^\top \mathbf{y}: (p+1)×1(p+1) \times 1 vector of feature-target covariances

For a detailed mathematical derivation of this formula, including the normal equations and computational considerations, see the dedicated OLS chapter.

Key Properties

The OLS solution has several important properties:

  • Unbiased: The estimates are unbiased under standard regression assumptions
  • Efficient: Among all unbiased linear estimators, OLS has the smallest variance
  • Consistent: As sample size increases, the estimates converge to the true values
Computational Considerations

While the closed-form solution is mathematically elegant, computing (X⊤X)−1(\mathbf{X}^\top \mathbf{X})^{-1} can be problematic when:

  • The matrix is nearly singular (ill-conditioned) due to multicollinearity
  • You have more features than observations (p>np > n)
  • The dataset is very large

In these cases, numerical methods like QR decomposition, SVD, or gradient descent are preferred for stability and efficiency.