Hello! Welcome to the fifth lesson in our intensive review for your midterm.
In our last lesson, we introduced the theory behind parameter estimation in GLMs. We saw that because the likelihood equations are too complex to solve directly, we use an iterative algorithm called Fisher Scoring, which is equivalent to a procedure known as Iteratively Reweighted Least Squares (IRWLS).
Today, we're moving from theory to practice. Your goal for this lesson is to execute one full iteration of the IRWLS algorithm. Given a simple dataset and initial parameter estimates, you will calculate all the necessary components—the linear predictor, mean response, working response, and weights—to compute the updated parameter estimates. This is a core mechanical skill that statistical software performs under the hood and is a perfect example of an application-based exam question.
A Quick Recap: The IRWLS Loop
As a brief reminder, the IRWLS algorithm solves for the GLM parameters by repeatedly solving a weighted least squares (WLS) problem. The update step for the parameters at iteration is given by:
This looks just like the formula for ordinary least squares, but with two key differences:
- We use a working response vector instead of the actual data .
- We use a weight matrix to give more influence to observations with lower variance.
Since and depend on the current parameter estimates , we must recalculate them at each step, hence the name "Iteratively Reweighted."
For a deeper dive into the mathematical framework, the following resources provide a solid foundation.
GLM - 10 - Numerical Solution (Newton-Raphson, Fisher Scoring, IRLS)
This video from Meerkat Statistics provides an excellent explanation of how the Fisher Scoring algorithm is transformed into the IRWLS framework. It visually and mathematically connects the concepts we discussed previously.
Watch the section from 12:32 to 15:48. This part details the algebraic manipulation that turns the Fisher Scoring update rule into the familiar weighted least squares format. Focus on how the 'working response' (which the video calls z) is constructed.
[PDF] Fitting Generalized Linear Models
This document from a course at the University of Colorado Boulder clearly shows how the Fisher scoring update step is rearranged to resemble a weighted least squares problem.
Review the section titled 'Iteratively reweighted least squares' on pages 9-10. Notice how the update formula β(t+1) = ... is rewritten into the form β(t+1) = (X^T W X)^-1 X^T W z. Pay special attention to the definitions of the 'working variate' z and the weight matrix W.
Worked Example: One Iteration of IRWLS for Poisson Regression
Now, let's get our hands dirty. Your task is to perform one complete update of the coefficients for a Poisson regression model.
Problem Setup:
Suppose we are modeling the number of software bugs (y) found in a code module based on its complexity score (x). We have the following data from four modules:
| Module (i) | Complexity (x_i) | Bugs (y_i) |
|---|---|---|
| 1 | 10 | 2 |
| 2 | 12 | 3 |
| 3 | 15 | 4 |
| 4 | 18 | 6 |
We propose a Poisson regression model:
- Random Component:
- Systematic Component (Linear Predictor):
- Link Function: (Canonical link)
For a Poisson model, we know:
- Variance function:
- Derivative of the link function:
Our initial guess for the parameters is .
Let's execute the first iteration () to find .
Step 1: Calculate the Linear Predictor () and Mean Response ()
First, we use our initial to calculate the linear predictor and the expected number of bugs for each module.
| i | x_i | y_i | ||
|---|---|---|---|---|
| 1 | 10 | 2 | 1.1 | 3.004 |
| 2 | 12 | 3 | 1.3 | 3.669 |
| 3 | 15 | 4 | 1.6 | 4.953 |
| 4 | 18 | 6 | 1.9 | 6.686 |
Step 2: Calculate the Working Response () and Weights ()
Now we compute the two key components for our WLS update.
The general formula for the working response is:
For our Poisson model with , this becomes:
The general formula for the weights is:
For our Poisson model with and , this simplifies beautifully:
Let's calculate these values.
| i | y_i | |||||
|---|---|---|---|---|---|---|
| 1 | 1.100 | 3.004 | 2 | -1.004 | = 0.766 | 3.004 |
| 2 | 1.300 | 3.669 | 3 | -0.669 | = 1.118 | 3.669 |
| 3 | 1.600 | 4.953 | 4 | -0.953 | = 1.408 | 4.953 |
| 4 | 1.900 | 6.686 | 6 | -0.686 | = 1.797 | 6.686 |
You can see these calculation steps outlined for a general Poisson model in the resource below.
[PDF] Generalized linear models
These lecture slides from MSU provide a clear, step-by-step example for applying IRWLS to a Poisson model. It's a great reference to confirm the formulas we're using.
Review slides 14 and 15, titled 'Example: Poisson regression model'. Notice how g'(µ) and Wi are derived, and then see the resulting formulas for the 'adjusted dependent response' (Z) and weights (W) used in the algorithm steps.
Step 3: Perform the Weighted Least Squares Regression
We now have all the pieces to solve for using the WLS formula: .
Let's define our matrices:
- Calculate :
- Calculate the inverse :
For a 2x2 matrix , the inverse is . - Calculate :
- Finally, calculate :
So, after one iteration, our updated parameter estimates are and .
Statistical software would now take these new values and repeat the entire process—calculating new , , , and —until the change in between iterations is negligible.
Conclusion
In this lesson, you walked through the core computational engine for fitting Generalized Linear Models. You have now executed a full iteration of the IRWLS algorithm, translating abstract formulas into concrete calculations.
Key Takeaways:
- The IRWLS algorithm consists of a loop with three main steps per iteration:
- Calculate the linear predictor and mean response from the current .
- Use these to compute the working response and weights .
- Solve the weighted least squares equation to get the updated parameters.
- The specific formulas for the weights and working response depend on the GLM's distribution (variance function) and link function.
You've now seen how a GLM is fit. But how do we know if the fit is any good? In our next lesson, we will address this by learning how to compute the deviance of a fitted GLM and interpret it as a measure of model fit.