GLMs Beyond Logistic
In Lesson 7, Priya stopped predicting a number and predicted a yes or no: would a given customer buy a pastry? A straight line cannot honour a yes/no, so you swapped lm() for glm(family = binomial) and let the logit link bend the prediction into a probability between 0 and 1.
That swap was your first step out of ordinary regression, and it hid a much bigger idea. Logistic regression is just one member of a whole family of models, the generalized linear models (GLMs). Change one setting and the same machinery models a count, or a skewed dollar amount, or a proportion. This lesson opens up the rest of that family.
The picture below is Priya's new problem: how many pastries she sells on a morning, plotted against how many people walk past the cart. Those dots are counts, whole numbers that never go negative, and, as you will see, a plain straight line through them is not just imperfect, it is impossible.
By the end of this lesson you will be able to:
- Name the three parts of any GLM and see
lm()and logistic regression as two members of the same family - Fit a Poisson regression for a count and read its coefficients as multiplicative rate ratios
- Spot overdispersion and repair it, knowing which part of the model it corrupts (and which it leaves alone)
- Fit a Gamma regression for a positive, right-skewed amount, and match any response to the right family and link
Prerequisites: Lessons 1 to 7 (you can fit lm(), read a coefficient table, and, from Lesson 7, fit glm() and interpret a coefficient after transforming it with exp()). You know that exp() and log() undo each other. Every new term is defined as it appears.
One family behind them all
Here is the key idea. Ordinary regression and logistic regression are not two unrelated tools; they are the same machine with a different setting turned. Every generalized linear model is built from exactly three parts.
- A random component: the probability distribution you assume for the response. This is the "family". A symmetric spread of numbers is
Normal; a yes/no isBinomial; a count isPoisson; a positive skewed amount isGamma. - A linear predictor: the familiar weighted sum of your predictors, written \( \eta = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \cdots \). The symbol \( \eta \) (the Greek letter "eta") is just a name for that sum; it can be any number, positive or negative.
- A link function \( g \): the bridge that ties the mean of the response, written \( \mu \) (the Greek "mu"), to that linear predictor:
\[ g(\mu) = \eta = \beta_0 + \beta_1 x_1 + \cdots \]
The link is the clever part. The linear predictor \( \eta \) roams freely from minus infinity to plus infinity, but a probability must sit in \([0,1]\) and a count must be positive. The link \( g \) does the translating so the two sides can meet.
You have already met two links without knowing the name. Ordinary regression uses the identity link, \( g(\mu) = \mu \): the mean is the linear predictor, nothing bent. Lesson 7's logistic regression used the logit link, \( g(\mu) = \log\!\frac{\mu}{1-\mu} \), which squeezes the line into a probability. Choosing a GLM is really just choosing these three parts, and the flow below is the whole decision.