Matrix Approach to Linear Regression Model & Derivation of OLS Estimator in Matrix Form
The K-Variable Linear Regression Model
Consider the following K-variable linear regression model:
![]()
Where εᵢ is the error term, it is distributed as normal with mean 0 (E(εᵢ) = 0) and variance σ² (Var(εᵢ) = σ², constant variance).
β₀, β₁, β₂, …, βK and σ² are true, unknown population parameters — β₀ is the intercept and β₁, …, βK are the partial slope coefficients on X₁, …, XK — estimated from sample data using an appropriate parameter-estimation method such as OLS or ML.
![]()
Expanding the Model Across N Observations
Replacing the generic index i by 1, 2, 3, …, N produces N individual equations, one for each observation:
![]()
![]()
![]()
![]()
or, for a representative observation i:
![]()
or, more compactly, in summation form:
![]()
The Model in Matrix Notation
We can now write the entire system of N equations compactly in matrix notation as:
![]()

Equivalently, indicating the dimension (order) of every component:
![]()
which is written as:
![]()
Definitions and Dimensions of Each Component
- Y = N × 1 column vector of values of the dependent variable.
- X = N × (K + 1) matrix: a column of 1’s (for the intercept) plus K columns of explanatory variables X₁, X₂, …, X_K, across N observations.
- β = (K + 1) × 1 column vector of (K + 1) unknown parameters (β₀ is the intercept; β₁, …, β_K are the slope coefficients).
- ε = N × 1 column vector of N error terms.
Derivation of the OLS Estimator in Matrix Form
Overview
Building on the K-variable model introduced above, this lecture derives the Ordinary Least Squares (OLS) estimator
entirely in matrix notation — starting from the Population Regression Function (PRF), through minimization of the Sum of Squared Residuals (SSR), to the final closed-form solution. Every algebraic step—including two independent proofs of the matrix differentiation rules used—is shown explicitly.
The Population Regression Function (PRF) in Matrix Form
The Population Regression Function, written compactly in matrix form, is:
![]()
where the components are defined as follows:
- Y is an N × 1 column vector of observations on the dependent variable.
- X is an N × (K + 1) matrix — a column of 1’s for the intercept plus K explanatory variables X₁, …, XK — with N observations.
- β is a (K + 1) × 1 column vector of (K + 1) unknown parameters (β₀ the intercept, and β₁,…,βK the slope coefficients).
- ε is an N × 1 column vector of stochastic error terms, distributed as ε ~ N(0, σ²), with constant variance σ² (homoscedasticity).

The Estimated (Sample) Regression Function
Because E(ε) = 0, the fitted (estimated) model is written as:
![]()
Objective: Minimizing the Sum of Squared Residuals (SSR)
The OLS estimator
is obtained by minimizing the Sum of Squared Residuals:
![]()
Since Y is an N × 1 column vector, Ŷ must also be an N × 1 column vector, and their difference — the residual vector — is likewise N × 1:
![]()
Expressing SSR in Matrix Notation
To obtain the sum of squared residuals, the residual vector (order N × 1) must be multiplied by its own transpose (order 1 × N). This product yields a scalar of order 1 × 1.

Thus, the minimization problem becomes:
![]()
Expanding e′e
![]()
![]()
Applying the transpose rule (AB)′ = B′A′ to the first bracket:
![]()
Distributing the second bracket across both terms:
![]()
Multiplying out fully gives the expanded quadratic form:
![]()
Proving that Y′Xβ̂ is a Scalar
Checking the conformability and resulting dimension of the middle term:
![]()
Since
reduces to a 1 × 1 matrix, it is a scalar.
Simplifying via Transpose Property
The transpose of a scalar is the scalar itself. For example, if A = [5], then A′ = [5].
Taking the transpose of the scalar
and applying the rule (ABC)′ = C′B′A′:
![]()
Since a scalar equals its own transpose,
. Substituting
in place of
in equation (1) allows the two middle terms to be combined:
![]()
First-Order Conditions: Differentiating e′e with respect to ![]()
To minimize e′e, we differentiate equation (2) with respect to
and set the first derivative equal to the zero vector:
![]()
The first term,
is zero since Y′Y does not depend on
. The remaining two derivatives are derived below with proof.
Derivative of the Linear Term ![]()
Proof 1 — Element-wise expansion
Writing out the inner product explicitly (over all K + 1 parameters β̂₀, β̂₁, …, β̂K):

![]()
Taking partial derivatives with respect to each
and stacking them into a vector:

Proof 2—Matrix differentiation rule
Rule:
, where c is a constant vector.
![]()
Letting c = X′Y (a constant (K + 1) × 1 vector, since it does not depend on
:
![]()
Derivative of the Quadratic Term ![]()
The result of this derivative is:
![]()
Proof (using the matrix differentiation rule):
Rule:![]()
![]()
![]()
![]()
![]()
Combining the Derivatives
Substituting both results back into the first-order condition:
![]()
![]()
![]()
The Normal Equations
Solving the first-order condition for the stationary point:
![]()
This is the matrix form of the Normal Equations.
Solving for the OLS Estimator ![]()
Pre-multiplying both sides of the normal equations by the inverse (X′X)⁻¹:
![]()
![]()
![]()
![]()
which gives the OLS estimator in closed matrix form:
![]()
Condition for Existence of 
![]()
If (X′X) is a non-singular (invertible) matrix,
can be uniquely determined. This inverse exists if and only if X has full column rank—that is, no explanatory variable (nor the intercept column) is an exact linear combination of the others (no perfect multicollinearity).
Summary: Key Steps
- PRF:

- Minimize SSR:

- Expand:

- Differentiate and set to zero:

- Normal equations:

- Final Answer:






MinhajMetricsHub