Class 6 · Generalized Linear Models
STAT 517: Advanced Statistical Models · Fall 2026
This interactive companion follows the Class 6 notes (Chapter 5). We see why a conditional mean may need a link, identify the three GLM components and basic assumptions, and fit four short examples: Bernoulli, Poisson, Gamma, and Gaussian. We then compare predictions on the link scale and the response scale.
Each WebR code box runs R directly in your browser. Press Run Code, inspect the result, change something, and run it again. Run the cells in order because later cells use objects created earlier.
The page preloads the faraway package for the wafer data and includes data/crabs.txt and data/student_awards.csv, the same public data used in the class code companion.
Setup and data
Keep every plot small, and keep multi-panel plots inside a single cell, because the layout set by par() does not carry over from one cell to the next.
The wafer data contain resistivity measurements from 16 wafers and four experimental factors. Each factor has levels - and +, with - as the reference.
5.1 Why generalize the linear model?
When the identity link gives invalid means
The normal linear model sets the conditional mean equal to the linear predictor, \(\mu_i = \eta_i = \mathbf{x}_i^\mathsf{T}\boldsymbol\beta\). A probability lives in \((0, 1)\) and a count mean is positive, but a line does not know that.
You can ask glm() to use the identity link with a binomial or Poisson family. With its default starting values, fitting fails for these two examples:
This failure does not mean that no valid coefficients exist. An identity-link model must keep the fitted means valid over the intended predictor range, and extrapolation can leave that range. The logit and log links make valid means automatic for every real linear predictor.
Garnet lines are unconstrained least-squares mean lines from lm(). Teal curves are the GLM fits, which stay inside the allowable range for every value on the horizontal axis, not only inside the data.
The three components and common links
A GLM has a random component, the conditional distribution of \(Y_i\mid\mathbf{x}_i\); a systematic component, the linear predictor \(\eta_i=\beta_0+\sum_j\beta_jx_{ij}\); and a link \(g\) satisfying \(g(\mu_i)=\eta_i\). The link must be one-to-one so that the inverse returns a unique conditional mean, \(\mu_i=g^{-1}(\eta_i)\).
| Response | Distribution | Link | \(g(\mu)=\eta\) | Inverse \(g^{-1}(\eta)=\mu\) |
|---|---|---|---|---|
| Continuous | Gaussian | Identity | \(\mu\) | \(\eta\) |
| Binary | Bernoulli/binomial | Logit | \(\log\{p/(1-p)\}\) | \(\dfrac{e^\eta}{1+e^\eta}\) |
| Count | Poisson | Log | \(\log(\mu)\) | \(e^\eta\) |
| Positive, right-skewed | Gamma | Log | \(\log(\mu)\) | \(e^\eta\) |
For these links, every real \(\eta\) maps to an allowable conditional mean. The mean need not be a possible individual outcome: a Poisson mean can be 2.7 even though the response is an integer.
In R, qlogis() is the logit and plogis() is the inverse-logit function, \(\operatorname{expit}(\eta)=e^\eta/(1+e^\eta)\).
A link transforms the conditional mean, not the observed response. In particular, \(\log E(Y\mid\mathbf{x})\) generally differs from \(E\{\log(Y)\mid\mathbf{x}\}\).
Under conditional independence, the GLM likelihood is a product of the chosen conditional mass functions or densities. The coefficients are usually estimated by numerical maximum likelihood, as introduced in Chapter 4.
5.2 Basic GLM assumptions
A standard independent-response GLM rests on three basic assumptions:
- Random component. The chosen family describes the response conditional on the predictors. Its conditional variance is \(p_i(1-p_i)\) for Bernoulli responses and \(\mu_i\) for Poisson responses.
- Link and systematic component. The conditional mean satisfies \(g(\mu_i)=\eta_i=\beta_0+\sum_j\beta_jx_{ij}\) for the terms included. “Linear predictor” means linear in the coefficients.
- Conditional independence. Responses from distinct units are independent given the modeled predictors. Repeated measurements on the same person generally require a model that accounts for their dependence.
Normality and constant conditional variance are features of a Gaussian identity-link GLM, not requirements for every GLM. No distributional assumption is imposed on the predictors themselves. Interpretation also depends on data quality and the study design.
5.3 Fitting GLMs in R
These four examples illustrate fitting syntax and coefficient output. We will develop interpretation, inference, and model checks in later chapters. The estimates are rounded to four decimal places, as in the handout.
Bernoulli response: logit link
Poisson response: log link
prog is a factor with General as the reference level, so R creates coefficients for Academic and Vocational.
Gamma response: log link
This model uses the original positive resistivity. The coefficient names x1+ through x4+ compare the + level with the - reference level.
Gaussian response: identity link
Here the response is log(resist). A Gaussian GLM gives the same coefficient estimates as lm() for this transformed response.
The Bernoulli, Poisson, and Gaussian fits use their families’ default links. The Gamma fit specifies the log link explicitly.
What does type = "link" return?
predict(fit, type = "link") returns the fitted linear predictor: \[
\widehat\eta_i
=\widehat\beta_0+\sum_j\widehat\beta_jx_{ij}
=g(\widehat\mu_i).
\] type = "response" applies the inverse link and returns the fitted conditional mean, \(\widehat\mu_i=g^{-1}(\widehat\eta_i)\).
| Model | type = "link" |
type = "response" |
|---|---|---|
| Bernoulli with logit link | Fitted log-odds \(\log\{\widehat p/(1-\widehat p)\}\) | Fitted probability \(\widehat p\) |
| Poisson or Gamma with log link | Log of the fitted mean \(\log(\widehat\mu)\) | Fitted mean \(\widehat\mu\) |
| Gaussian with identity link | Fitted mean \(\widehat\mu\) | The same fitted mean \(\widehat\mu\) |
For the Gaussian wafer fit, the modeled response is log-resistivity, so type = "response" returns a fitted mean of log(resist); it does not undo the log transformation in the formula.
For a crab with carapace width 26 cm:
The output is a fitted log-odds of 0.5772 and a fitted probability of 0.6404. The headings label the scales; the type argument remains "link" or "response".
5.4 Takeaways
- A GLM combines a conditional response distribution, a linear predictor, and a link function.
- The link transforms the conditional mean; its inverse returns a mean on the scale of the modeled response.
- An appropriate conditional family and mean/link relationship, together with conditional independence, are the three basic assumptions.
glm()uses the same fitting interface for all four examples.type = "link"returns the fitted linear predictor;type = "response"returns its inverse-link mean.
Next, the Bernoulli GLM with the logit link becomes logistic regression. One predictor comes first, followed by several predictors and conditional interpretation.