Accessible version · How to use this site with a screen reader · Course home
Day 2 · Plain-language summary

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

$\mu_i = \beta_0 + \beta_1 x_{i1} + \beta_2 x_{i2} + \dots$

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

  1. The linear predictor: $\eta_i = \beta_0 + \beta_1 x_{i1} + \dots$ — same as before.
  2. The link function: $g(\mu_i) = \eta_i$. Transforms the mean onto an unbounded scale so a line makes sense.
  3. The distribution: $y_i \sim D(\mu_i, \theta)$. Says how observations vary.

R syntax: glm(y ~ x, family = D(link = "link_function")).

When to switch distributions

A simple checklist:

  1. Is the response a count? Start with Poisson. If residual deviance / df >> 1, switch to Negative Binomial.
  2. Is the response binary or proportion-of-fixed-n? Binomial/logistic. Always.
  3. Is the response strictly positive and continuous? Try Gamma with log link, or a Normal on log(y).
  4. Is the response a proportion not built from a count? Beta regression (betareg package).
  5. 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.