Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 30

MLE vs. OLS for Linear Models with Gaussian Noise

Recommended resources

Introduction

Welcome to the next lesson in our exploration of statistical inference. In our previous lesson, we derived the Generalized Least Squares (GLS) estimator, which we proved is the Best Linear Unbiased Estimator (BLUE) when the errors have a general, known covariance matrix . That derivation was powerful because it made no assumptions about the distribution of the errors, only about their first and second moments (mean and covariance).

Today, we will add a crucial layer to our linear model: a specific distributional assumption. We will assume the errors are not just uncorrelated with constant variance, but are also drawn from a Gaussian (Normal) distribution. This assumption allows us to connect two major estimation frameworks: Ordinary Least Squares (OLS) and Maximum Likelihood Estimation (MLE).

Our primary goal is to compare the properties of the MLE and OLS estimators for the linear model with Gaussian noise. You will discover that under this specific condition, these two seemingly different approaches lead to identical conclusions for the regression coefficients, a result that highlights a deep and elegant unity in statistical theory. We will also uncover a subtle but important difference in how they estimate the model's error variance.


1. The Linear Model with Gaussian Noise

Let's begin by formally stating the model. We start with the standard linear model:

where is the vector of observations, is the design matrix, is the vector of unknown parameters, and is the vector of errors.

Now, we add the crucial assumption: the errors are independent and identically distributed (i.i.d.) according to a Gaussian distribution with mean 0 and variance .

This implies that the vector of errors follows a multivariate normal distribution: .

From the properties of the Gaussian distribution, a linear transformation of a Gaussian random variable is also Gaussian. Thus, the conditional distribution of given is:

The probability density function (PDF) for a single observation is therefore:

This PDF is the fundamental building block for constructing the Maximum Likelihood Estimator.


2. Deriving the MLE: Equivalence with OLS

Our goal is to find the parameters that maximize the likelihood of observing our data . The first step is to write down the likelihood function.

The video below provides a clear, step-by-step derivation showing how maximizing the likelihood under the Gaussian noise assumption leads directly to the least squares solution.

Least Squares as a Maximum Likelihood estimator

This video, 'Least Squares as a Maximum Likelihood estimator' from Ben Lambert's channel, formally derives the MLE for the coefficients of a linear model. It clearly demonstrates that the objective function for MLE becomes equivalent to the objective function for OLS when we assume Gaussian errors.

Watch the entire video (0:00 - 7:37). Pay close attention to these key steps: How the likelihood for a single observation is constructed from the Gaussian PDF. How the joint likelihood for the whole dataset is formed as a product. How taking the logarithm simplifies the problem. The final step where differentiating the log-likelihood with respect to the parameter beta yields a condition identical to the one found in OLS.

Let's formalize the derivation from the video using matrix notation, which you are comfortable with.

  1. Likelihood Function: Since the observations are independent, the joint likelihood is the product of the individual PDFs:

    In vector form, this is:

  2. Log-Likelihood Function: Taking the natural logarithm simplifies the expression significantly:

  3. Maximizing with respect to : To find the MLE for , we need to maximize this function. Notice that the first term, , does not depend on . Therefore, maximizing the log-likelihood with respect to is equivalent to minimizing the term:

    This is precisely the Sum of Squared Errors objective function from Ordinary Least Squares!

Since the optimization problem is identical, the solution must be identical.

This is a profound result. It shows that the OLS method, which seems to be a simple heuristic based on minimizing squared distances, is in fact the "most likely" estimator under the common and natural assumption of Gaussian noise.

To solidify this concept, the following slides offer a concise summary of this derivation and the geometric interpretation.

Linear Regression and the Bias Variance Tradeoff

These slides from a Berkeley lecture on Linear Regression provide a condensed, matrix-based derivation of the equivalence between MLE and OLS. They also connect it to the geometric view of OLS as a projection.

Please review the slides from 'Rewriting with Matrix Notation' through 'Geometric Interpretation' (slides 9-13). Focus on how the log-likelihood is simplified to show that maximizing it is the same as minimizing the squared error. The final derivation of the 'Normal Equations' should be very familiar.


3. Comparing Estimator Properties

Now that we have established the equivalence of the estimators for , let's perform a detailed comparison of their properties. This is where a key difference emerges.

3.1 Properties of the Coefficient Estimator

Property OLS Estimator () MLE Estimator () Comparison
Formula Identical.
Bias Unbiased. Proven via Gauss-Markov theorem: . Unbiased, because it is identical to the OLS estimator. Identical (both are unbiased).
Variance Identical.
Optimality BLUE (Best Linear Unbiased Estimator). This holds even without the Gaussian assumption. MVUE (Minimum Variance Unbiased Estimator). It achieves the Cramér-Rao Lower Bound. The MLE's optimality claim is stronger. MVUE means it has the lowest variance among all unbiased estimators, not just linear ones. This stronger claim is possible because we made a distributional (Gaussian) assumption.

3.2 Properties of the Error Variance Estimator

Here is where the two methods diverge. Let's find the MLE for . We return to the log-likelihood function:

First, we plug in our MLE for , . Then we take the derivative with respect to and set it to zero:

Solving for gives the MLE for the variance:

Now, let's compare this to the standard unbiased estimator for used in the context of OLS.

Property OLS-associated Estimator () MLE Estimator () Comparison
Formula Different. The denominators are vs. , where is the number of parameters in .
Bias Unbiased. It is specifically constructed to be so: . Biased. Its expectation is , which is slightly less than the true . The OLS variance estimator is unbiased by design. The MLE variance estimator is biased, though it becomes asymptotically unbiased as . The term is a degrees of freedom correction. We "lose" degrees of freedom by estimating the parameters in .

The following video provides an excellent visual summary of this entire comparison, including the difference in the variance estimators.

MLE vs OLS | Maximum likelihood vs least squares in linear regression

This video, 'MLE vs OLS', provides a fantastic conceptual and visual comparison. It demonstrates how changing the regression line parameters affects both the Sum of Squared Residuals (OLS) and the joint likelihood (MLE), showing they are optimized at the same point. It also explicitly discusses the difference in the variance estimators.

Watch the entire video. Focus on: The visual connection between minimizing the distance to the line (OLS) and maximizing the height on the normal distribution curves (MLE). The demonstration at (8:21) showing that both methods find the same optimal parameters. The crucial explanation at the end (12:31) about the difference in the denominators for the variance estimate (n vs n-2 in the video's simple regression example).

The image below, taken from the video, perfectly encapsulates the main idea. Minimizing the sum of squared residuals (the terms) is equivalent to finding the line that maximizes the product of the heights of the Gaussian distributions centered on that line.

OLS vs MLE with Gaussian Noise Visualization
A visual representation comparing OLS and MLE. OLS minimizes the sum of squared vertical distances (residuals). MLE, under Gaussian noise, places a normal distribution at each predicted point on the line and seeks to maximize the joint probability of the observed data, which corresponds to maximizing the product of the probability densities (heights of the curves at the data points).

Conclusion

In this lesson, we established a critical link between two foundational estimation techniques by adding the assumption of i.i.d. Gaussian noise to the linear model.

Key Takeaways:

  • Equivalence for : For a linear model with Gaussian noise, the Maximum Likelihood Estimator for the regression coefficients is identical to the Ordinary Least Squares estimator.
  • Stronger Optimality: This equivalence means that under Gaussian noise, the OLS estimator is not just the Best Linear Unbiased Estimator (BLUE), but the Minimum Variance Unbiased Estimator (MVUE)—the best of all unbiased estimators.
  • Difference for : The MLE for the error variance is and is biased. The standard unbiased estimator used with OLS is , which corrects for the degrees of freedom used to estimate .
  • The Power of Assumptions: This lesson highlights how adding distributional assumptions (like Gaussian noise) can provide deeper insights and stronger theoretical guarantees (like MVUE) for our estimators.

You have now seen how frequentist estimation can be approached from both a geometric/algebraic perspective (OLS) and a probabilistic one (MLE), and how they beautifully converge under the right conditions.


Preview of the Next Lesson:

We are now ready to transition into the third major paradigm of statistical inference: Bayesian Inference. In the upcoming module, we will start treating parameters not as fixed constants but as random variables themselves. You will learn how to formally combine prior knowledge about a parameter with the likelihood from observed data to form an updated posterior belief. This will lead us to powerful new estimators like the MMSE and MAP estimators and provide a completely new way of thinking about uncertainty and inference.