Skip to main content

Welcome to a Grasp lesson

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

Lesson 19

Log-Likelihood for GLMs

Recommended resources

Introduction

Welcome to the first lesson in our module on parameter estimation. In the previous module, you mastered a crucial decision-making process: how to select the right probability distribution (Normal, Poisson, Gamma, etc.) for your response variable based on its characteristics. Now, we take the next logical step. Once we've chosen a distribution, how do we actually fit a model to our data?

The core of model fitting in this context is a principle called Maximum Likelihood Estimation (MLE). The goal of MLE is to find the set of model parameters (the coefficients) that make our observed data "most likely." To do this, we need to construct a specific mathematical function—the log-likelihood function—which serves as the objective function we need to maximize.

In this lesson, you will learn how to formulate the log-likelihood function for a Generalized Linear Model (GLM) based on its specified distribution. This is the foundational step for all the estimation algorithms we will discuss next.


From Probability to Likelihood

The idea of likelihood is a subtle but powerful shift in perspective from probability.

  • Probability asks: Given a model with known parameters, what is the chance of seeing a particular outcome?
  • Likelihood asks: Given the data we have actually observed, how plausible is a particular set of model parameters?

For a set of independent observations , the total likelihood is the product of the individual probabilities. However, working with products is mathematically inconvenient. This is why we almost always work with the log-likelihood.

The following video provides an excellent introduction to Maximum Likelihood Estimation and explains why the log-likelihood is so useful.

Maximum Likelihood Estimation (MLE) with Examples

Let's watch this video from Steve Brunton's YouTube channel. It clearly explains the core idea of MLE and the practical reasons for using the logarithm of the likelihood function.

Please watch from the beginning until the timestamp 12:39. Pay close attention to: How the joint probability for independent data is constructed as a product (01:01 - 05:54). The definition of the likelihood function as a function of the parameters \theta, given the observed data (05:54 - 08:30). The critical switch from maximizing the likelihood to maximizing the log-likelihood, and why this turns products into sums (09:18 - 12:39).

As the video highlights, using the log-likelihood simplifies our problem immensely by converting a large product of probabilities into a more manageable sum. Maximizing is equivalent to maximizing because the logarithm is a monotonically increasing function.


The Log-Likelihood for the Exponential Family

Now, let's generalize this. In the previous module, you saw that any distribution in the exponential family can be written in a standard form. This standardization allows us to define a single, general formula for the log-likelihood of any GLM.

Let's use the general form we've seen before. The probability density/mass function (PDF/PMF) for a single observation from an exponential family distribution is:

Here, is the natural parameter and is the dispersion parameter.

To get the log-likelihood for this single observation, we simply take the natural logarithm.

[PDF] GLM (Generalized Linear Model) #1 (version 9)

The document 'GLM #1' provides a clear derivation of the log-likelihood for a single observation from the exponential family. Let's look at that specific part.

Please read section 5.1, 'Likelihood basics' (page 14). Focus on how equation (52) is derived by simply taking the log of the exponential family PDF.

As shown in the resource, taking the log of the exponential function simply gives us the exponent. The log-likelihood for a single observation is:

Since our observations are independent, the total log-likelihood for the entire dataset is the sum of these individual log-likelihoods:


From to : Making it a GLM

The expression above is a function of the natural parameters . However, in a regression context, our goal is to estimate the coefficients . We need to express the log-likelihood as a function of .

This connection is made through the components of the GLM you've already learned:

  1. The linear predictor defines as a linear combination of the predictors and coefficients: .
  2. The link function connects the mean to the linear predictor: .
  3. A property of the exponential family connects the mean to the natural parameter via the derivative of : .

Therefore, the parameters we want to find, , determine the log-likelihood through this chain:

The function we ultimately want to maximize is .


Worked Example: The Poisson GLM

Let's make this concrete by formulating the log-likelihood for a Poisson GLM.

  1. Start with the PMF: The probability of observing a count from a Poisson distribution with mean is:

  2. Take the Log: The log-likelihood for a single observation is:

  3. Sum over all observations: The total log-likelihood as a function of the means is:

  4. Introduce the GLM link function: For a Poisson GLM, the canonical link is the log link.

    This implies that .

  5. Substitute to get the final log-likelihood in terms of : We replace with and with .

This is the function that an optimization algorithm would maximize to find the MLEs for the coefficients in a Poisson regression.


Practice: Formulating the Logistic Regression Log-Likelihood

Now it's your turn. Logistic regression is a GLM for binary data, using a Binomial distribution with (also called a Bernoulli distribution) and a logit link. Follow the steps above to formulate its log-likelihood function.

Click here to see the steps and final solution.
  1. Start with the PMF: For a Bernoulli trial, is either 0 or 1. The PMF is , where is the probability of success ().

  2. Take the Log: The log-likelihood for a single observation is:

  3. Sum over all observations: The total log-likelihood is:

  4. Introduce the GLM link function: For logistic regression, the canonical link is the logit link.

    The inverse link gives us in terms of : . A useful identity derived from this is .

  5. Substitute to get the final log-likelihood: Substituting for and in terms of simplifies the expression significantly.

    The final log-likelihood function for logistic regression is:

This is another fundamental result in statistics and machine learning, forming the basis for training classification models.


Conclusion

In this lesson, you have learned the crucial process of building the objective function for parameter estimation in GLMs. This bridges the gap between choosing a distribution and actually fitting the model.

Key Takeaways:

  • Maximum Likelihood Estimation (MLE) seeks to find the parameters that make the observed data most probable.
  • We work with the log-likelihood because it turns products into sums, simplifying the mathematics of optimization.
  • The log-likelihood for a GLM starts from the general exponential family form.
  • The final log-likelihood function must be expressed in terms of the regression coefficients by substituting the model's link function.

You now know how to construct the function . The next natural question is: how do we find the that maximizes it? In the next lesson, you will learn how to take the first step in this optimization process by deriving the score equations, which are simply the derivatives of the log-likelihood function.