Linear models, link functions, and the GLM family
Read this before doing the lab to set up the conceptual scaffolding.
The big idea
Plain-language summary
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).
Key idea
The biology hook: a log link encodes the assumption that effects are multiplicative. A logit link encodes the assumption that effects are multiplicative on the odds. Both match how biology actually works far better than the additive assumption baked into a plain Normal regression. See the log/logit intuition guide for many worked examples.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.
Common mistakes
Watch out
Fitting a Normal to count data. Predicts negative counts; variance assumption usually wrong. Use a Poisson or NB instead.Watch out
Forgetting to back-transform. A log-link coefficient of 0.5 is not "a 0.5 increase in response per unit x" — it's "a $\times e^{0.5} = \times 1.65$ multiplicative effect." Always exponentiate.Watch out
Trusting Poisson SEs when overdispersed. Overdispersion makes Poisson SEs too small. Switch to NB (or quasipoisson if you only need point estimates).Watch out
Treating interactions as one-size-fits-all. An interaction that looks important on the log scale might disappear on the natural scale, and vice versa. Always state which scale you're talking about.