Linear models, link functions, and the GLM family
Read this before doing the lab to set up the conceptual scaffolding.
The big idea
Yesterday you learned that data come from a distribution. Today you learn how to connect a distribution to a predictor. That's all a regression is: a recipe that says "if the predictor is $x$, the expected response is $\mu(x)$, and observations vary around $\mu$ according to some distribution."
The traditional linear regression you've seen ($y = a + bx + \text{noise}$) assumes the response is Normal and unbounded. But ecological responses are usually counts, proportions, or strictly positive — none of which are Normal. So we generalize.
Continuous distributions: the morning's cast
- Normal — symmetric, unbounded. Workhorse for measurements that can fall on either side of a mean, like temperatures and model residuals. Because it puts probability on negative values, it is a poor default for strictly positive quantities such as lengths and masses — those belong with the Lognormal or Gamma below.
- Lognormal — log(Y) is Normal. Always positive, right-skewed. Use for abundances, concentrations, body sizes.
- Gamma — flexible positive continuous. Use when variance grows with the mean (common in biology).
- Beta — for proportions strictly between 0 and 1 (not derived from a count).
- Exponential — time between events in a Poisson process. Use for survival times, time-to-first-detection.
What a linear model actually does
A linear model is the recipe
plus an assumption that observations $y_i$ are independently drawn from a distribution centered at $\mu_i$.
"Linear" refers to the coefficients, not the predictors. y ~ x + I(x^2) is still a linear model. y ~ sin(beta * x) is not.
Generalized linear models — three ingredients
- The linear predictor: $\eta_i = \beta_0 + \beta_1 x_{i1} + \dots$ — same as before.
- The link function: $g(\mu_i) = \eta_i$. Transforms the mean onto an unbounded scale so a line makes sense.
- The distribution: $y_i \sim D(\mu_i, \theta)$. Says how observations vary.
R syntax: glm(y ~ x, family = D(link = "link_function")).
How to pick the right link function
The link should match the range of the mean:
| If the mean lives on… | Use link… | Example |
|---|---|---|
| All real numbers | identity | Normal regression |
| Positive numbers only | log | Poisson, NB, Gamma regression |
| Between 0 and 1 | logit | Logistic regression |
The choice isn't arbitrary — it's about making sure the model doesn't predict impossible values (negative counts, probabilities > 1).
When to switch distributions
A simple checklist:
- Is the response a count? Start with Poisson. If residual deviance / df >> 1, switch to Negative Binomial.
- Is the response binary or proportion-of-fixed-n? Binomial/logistic. Always.
- Is the response strictly positive and continuous? Try Gamma with log link, or a Normal on log(y).
- Is the response a proportion not built from a count? Beta regression (
betaregpackage). - None of the above? Plot the residuals from a Normal fit. If they look symmetric and homoscedastic, the Normal might be fine.